Java realizes the method of developing Unicom SMS based on SGIP protocol _java

Source: Internet
Author: User

This article describes the Java implementation based on SGIP protocol to develop the Unicom SMS method. Share to everyone for your reference. Specifically as follows:

Recently, due to the company's business needs, the development of Unicom SMS. This article is also written on the basis of some examples on the web. Less gossip, the following code: (When running this program need to import Huawei's development package, this package can be downloaded online)

Downlink:

public class Mt {private static String Spnumber = "**********";
 Access number private static String Chargenumber = "000000000000000000000";
 Billing number, white list private static String servicetype = "";
 Service type private static String host = "***.***.***.***";
 Host name, gateway IP private static INT port = * * *;
 Port number private static String Corpid = "* * *";
 Enterprise Code private static String login_name = "* *";
 Login name private static String Login_password = "* * *"; Login password public static void main (string[] args) throws unsupportedencodingexception {int srcnode = new BigInteger ("* *
  "). Intvalue (); SOURCE node number (Nodeid), this step is very important, Huawei package, the field type is int, and access protocol requirements in the Enterprise code before the addition of 30000, so that the value of the int's range, so need to use BigInteger turn can be Args argstr =
   New Args ()//Set connection parameter Argstr.set ("host", host);
   Argstr.set ("Port", port);
   Argstr.set ("Transaction-timeout", 10);
   Operation timeout (in seconds) argstr.set ("Read-timeout", 15);
   Physical connection read operation timeout (in seconds) argstr.set ("Source-addr", Srcnode); Sp... ID (maximum six-bit character) Argstr.set ("Login-namE ", login_name);
   Argstr.set ("Login-pass", Login_password);
   Argstr.set ("Debug", "false");
   Connection Landing Sgipsmproxy SGIPSMP = new Sgipsmproxy (ARGSTR);
    Here to connect to the SMS gateway try {//connect to SMG login, the login name and password are SMG to the SP assigned username and password, call this interface method, send the BIND command message to SMG.
    If a message timeout or communication exception is sent, an exception is thrown, requiring the caller to capture the processing.
    Boolean reslut = Sgipsmp.connect (login_name, Login_password);
    Login to get True and False if (Reslut) {System.out.println ("Connection succeeded ...");
     else {System.out.println ("Connection failed (user name or password error) ...");
    Return
    } catch (Exception ex) {System.out.println ("network exception .... ...");
    Ex.printstacktrace ();
   Return
   } string[] Usernumber = {"8618686619970", "8618686619977"};
   Receive SMS mobile phone number, the front should add a String content = "Unicom SMS sent Success";
    byte[] messagecontent = content.getbytes ("GB2312");
   SYSTEM.OUT.PRINTLN ("SMS content:" +content);  try {//Issued short interest sgipsubmitmessage sgipsubmit = new Sgipsubmitmessage (spnumber,//SP's access number Chargenumber,
     Pay Number String Usernumber,///receive the SMS phone number, up to 100 numbers string[] corpid,//Enterprise code, value range for 0~99999 string servicetype,//business code, defined by SP St
      irng 03,//billing type int "0",//The charge value of the short message stirng "0",///giving the user the bill of credit string 0,//Generation toll Mark 0: Receivable 1: Paid-in int
      0,//cause MT Message int 06,///priority 0~9 from low to high, default to 0 int null,//Short message lifetime expiration date NULL,//Short message timed time sent date 1,//status report tag int 0,//GSM protocol type int 0,//GSM protocol type int 15,///Short message encoding format int 0,//information type int Mes
    Sagecontent.length,//Short message content length int messagecontent,//Short message content btye[] "0"//reserved, extended with string);
    The received response message is converted to rep int status = Processsubmitrep (Sgipsmp.send (sgipsubmit));
    SYSTEM.OUT.PRINTLN (status);
    if (status = = 0) {System.out.println ("message sent successfully ...");
    else {System.out.println ("message send failed .... ...");   
   } catch (Exception ex) {ex.printstacktrace (); convert private static int processsubmitrep (Sgipmessage msg) {//Received response message to Repmsg SGIPSUBMITrepmessage repmsg = (sgipsubmitrepmessage) msg;
   System.out.println (Repmsg.getsrcnodeid ());
   System.out.println ("Status:::::;" + Repmsg.getresult ());
   if (repmsg!= null && repmsg.getresult () = = 0) {System.out.println (Sent successfully:::);
  return Repmsg.getresult ();

 }
}

Uplink:

public class Mo extends Sgipsmproxy {//SMG server information private static String Serhost = "***.***.***.***";
 private static int Serviceport = * * *;
 Native information private static String localhost = "***.***.***.***"; 
 private static int LocalPort = * * *;
  Public Mo (Args Args) {super (Args);
  System.out.println ("Enter Start monitor ...");
  StartService (localhost, localport);
  I would like to know if the host and port passed here are local or that of} public static void Main (string[] args) {args argstr = new Args ();
  Argstr.set ("Serhost", serhost);
  Argstr.set ("Serviceport", Serviceport);
  Argstr.set ("localhost", localhost);
  Argstr.set ("LocalPort", LocalPort);
  Argstr.set ("Transaction-timeout", 10);
  Operation timeout (in seconds) argstr.set ("Read-timeout", 15);
  Physical connection read operation timeout (in seconds)//How to solve the security authentication problem here?  
 Mo mymo=new mo (argstr);
  Public sgipmessage Ondeliver (sgipdelivermessage msg) {processrecvdelivermsg (msg);
  System.out.println ("Waiting to receive ...");
 return Super.ondeliver (msg); } public void Processrecvdelivermsg (Sgipmessage msg) {iF (msg instanceof Sgipsubmitrepmessage) {//Whether it is an instance of class System.out.println ("return the corresponding message sent by SMS"); } if (msg instanceof sgipdelivermessage) {//Receive SMS sent by User (uplink) sgipdelivermessage delivermsg = (sgipdelivermessage) m
   sg
   String Usernumber = Delivermsg.getusernumber ();
   Mobile number String msgcontent = delivermsg.tostring ();
   SMS content//byte[] msgId = Delivermsg.getmsgcontent ();
   System.out.println ("Usernumber:::::" + delivermsg.getusernumber ());
   System.out.println ("Msgcontent::::::" + delivermsg.tostring ());
   System.out.println ("Spnumber:::::::" + delivermsg.getspnumber ());
   Log.info ("received the message:" + delivermsg);
   System.out.println ("received the message:" +delivermsg);
   int commandid = Delivermsg.getcommandid ();
   Response type System.out.println ("CommandID:::::::," + CommandID);
    if (CommandID = = 0) {//upload SMS (receive) System.out.println ("DSTADDR:::::" + delivermsg.getspnumber ()); try {} catch (Exception e) {//TODO auto-generated catch block E.printstacktrace ();
    }
   }
  }
 }
}

 

I hope this article will help you with your Java programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.