The example of this article describes the method of developing Unicom SMS based on the SGIP protocol development. Share it for everyone for your reference. The specifics are as follows:
Recently, due to the company's business needs, China Unicom SMS has been developed. The writing of this article is also done according to some examples on the Internet. Less gossip, let ’s look at the code: (When running this program, you need to import Huawei's development when running this program. Bags, this package can be downloaded online))
L fors:
Public Class MT {Private Static String spnumber = "************"; // access number Private Static String CHARGENUMBER = "00000000000000000000000"; C String Serviceype = " "; // Service type Private Static String Host =" ***. ***. ***. *** "; // The host name, gateway IP Private Static Int port = ****; Private Static String Corpid = "******"; // Enterprise Code Private Static String login_name = "**"; // Login the name Private Static Login_password = "***"; // Login password pub LIC Static void Main (String [] args) Throws unsupportedEncodingException {int Srcnode = New Biginteger ("********"). Intvalue (); Section The type is int, and the access protocol is required to add 30,000 before the enterprise code, so as to exceed the value range of int, so you need to use Biginteger to turn Parameter argSet ("Host", Host); ArgStr.Set ("Port", Port); ArgStr.Set ("Transaction-Timeout", 10); // Operation timeout time (unit: second) argStr.Set ( "Read-Timeout", 15); // Physical connection reading operation timeout time (unit: second) argStr.set ("source-addr", srcnode); // sp ... ID (maximum six characters) argStr.sett ("Login-Name", Login_name); ARGSTR.SET ("Login-Pass", Login_password); Argstr.Set ("Debug", "False"); MProxy (argStr); / /Here is connected to the SMS Try {// Connect to indicate to the SMG. The login name and password are the username and password assigned by SMG to the SP, call this interface method, and send the Bind command message to the SMG. // If the message timeout or communication abnormality is sent, it is thrown out, and the caller needs to be captured. BOOLEAN Reslut = sgipsmp.connect (login_name, login_password); // Log in to get true and false if (resten) {system.out.println ("successful connection ...");} else { System.out.println ("Connection failure (user name or password error) ..........."); Return;}} catch (exception ex) {system.out.println ("network abnormal. ... "); ex.printstacktrace (); Return;} String [] usernumber = {" 86186866619970 "," 8618686619977 ""}; String Content = "Unicom SMS Sending Success"; byte [] MessageContent = Content.getBytes ("GB2312"); System.out.println ("SMS content:+Content); ESSAGE SGIPSUBMIT = New SGIPSUBMITMEMESSAGE (SPNUMBER, // SP's access number Chargenumber, // paid number string usernumber, // receiving the mobile phone number of the short message, up to 100 numbers string [] corpid, // corporate code, the value range is 0 0. ~ 99999 String Servicespe, // Business code, is defined by SP definition stirng 03, // billing type int "0", // The charging value of this short message is stirng "0", // / Overseas charging logo 0: Acceptance 1: Received int 0, // The reason for MT messages int 06, // priority 0-9 from low to high, default to 0 int null, // short message life terminal termination Time date null, // short message time delivery time Date 1, // status report tagging, // GSM protocol type INT 0, // GSM protocol type int 15, // short message encoding format 0, / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /ize / / / / / Information type int messageContent.Length, // Short message content length int messageContent, // The content of short message content BTYE [] 0 "// retain, expansion for string); // The response message received to repide into rept status = ProcessSUBMITREP (SGIPSMP.SEND (SGIPSUBMIT)); System.out.println (STATUS); if (status == 0) {system.out.println ("The message sends successfully ...") ;} Else {System.out.println ("Message Send fails ...");}} Catch (Exception EX) {ex.printstacktrace ();}} Private Static int (SGIPM ESSAGE MSG ) {// The response message received was converted into a repmsg sgipsubmitrePMESSAGE REPMSG = (sgipsubmitrepmessage) msg; System.out.println (rePMSG.Getsrcnodeid ()); System.ouou t.println ("Status ::::::: REPMSG.GetResult ()); if (REPMSG! = NULL && Repmsg.getResult () == 0) {system.out.println ("Sending success: ::");} RETURN repmsg.getResult ();}}}}}}}
Uplotting:
Public Class Mo Extends Sgipsmproxy {// SMG Server Information Private Static STRING Serhost = "***. ***. ***. ***"; rivate Static String LocalHost = "***. ***. ***. ***"; Private Static Int LocalPort = ****; PUBLIC MO (ARGS ARGS) {Super (ARGS); System.out.println ( "Enter the startup monitoring ..."); Startservice (localhost, localport); // I want to know whether the host and port here are local or that} Public Static void Main (string [] args) {Args ARGSTR = New ARGS (); ArgStr.Set ("Serhost", Serhost); ARGSTR.SET ("Serviceport", Serviceport); Argstr.Set ("LocalHost", ARGSTR.SE T ("Localport", Localport); ArgStr.Set ("Transaction-Timeout", 10); // Operation timeout time (unit: second) argStr.Set ("Read-timeout", 15); // Physical connection reading operation timeout time (unit: unit: unit: unit: unit: unit: unit: unit: unit: unit: unit: unit: unit: unit: unit: unit: unit: Second) How to solve the problem of security certification here? Mo mymo = New Mo (ARGSTR);} Public Sgipmessage ONDELIVER (SGIPDELIVEESAGE MSG) {ProcessRecvdermsg (MSG); System.out.prin. TLN ("Waiting for receiving ..... .. "); Return Super.ondeliver (msg);} Public Void ProcessRCVDELIVEERMSG (SGIPMESSAGE MSG) {if (MSG Instanceof SgipsubmitrePMessage) {// Whether it is an instance SY STEM.OUT.PRINTLN ("The corresponding message of sending a text message ");} if (MSG Instanceof sgipDeliverMessage) {// Receive the SMS message (uplink) SgIPDELIVELMESSAGERIVERMSG = (SGIPDELIVELMESSAGE) msg; string usernumber = sg.getUsernumber (); // mobile phone number string msgContent = deliverMsg.tring ( ); // SMS content // byte [] msgid = delivermsg.getmsgContent (); System.out.println ("usernumber :::: ("msgcontent :::: " + delivermsg.tostring ()); System.out.println (" spnumber :::::: Message: " + DeliverMSG); System.out.println (" Receive Message: " + DeliverMSG); int Commandid = Delivermsg.getCommandid (); // The response type system.out.println (" commit :::::: ::: :: " + Commandid); if (Commandid == 0) {// Upload System.out.println (" dstaddr :::: "" + deliverMSG.getSpnumber ()); try {} catch (Exception E) {// Todo Auto-Generatd Catch Block E.printstacktrace ();}}}}}}}}
It is hoped that this article is helpful to everyone's Java program design.