SoFunction
Updated on 2025-03-08

Java implements the method of developing China Unicom SMS based on SGIP protocol

This article describes the method of developing China Unicom SMS based on SGIP protocol in Java. Share it for your reference. The details are as follows:

Recently, due to the company's business needs, China Unicom SMS has been developed. The writing of this article is also based on some examples on the Internet. Let's talk about it, let's take a look at the code below: (When running this program, you need to import Huawei's development package, which can be downloaded online)

Down:

public class Mt {
 private static String SPNumber = "**********";
 //Access number private static String ChargeNumber = "000000000000000000000";
 // Billing number, whitelist 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();
  //The source node number (nodeid), this step is very important. In Huawei package, the field type is int, and the access protocol requires 30,000 to be added before the enterprise code, which exceeds the value range of int, so you need to use BigInteger to turn it in.   Args argstr = new Args();//Set connection parameters   ("host", host);
   ("port", port);
   ("transaction-timeout", 10);
   // Operation timeout (unit: seconds)   ("read-timeout", 15);
   // Timeout time for physical connection read operation (unit: seconds)   ("source-addr", srcnode);
   // SP…ID (maximum is six characters)   ("login-name", login_Name);
   ("login-pass", login_PassWord);
   ("debug", "false");
   // Connect to log in   SGIPSMProxy sgipsmp = new SGIPSMProxy(argstr);
   // Here is a connection to the SMS gateway   try {
    //connect means login to SMG. The login name and password are the username and password assigned by SMG to SP, call this interface method and send Bind command message to SMG.    //If the sending message timeout or communication exception is abnormal, an exception is thrown, and the caller needs to capture and handle it.    boolean reslut = (login_Name, login_PassWord);
    // Log in to get true and false    if (reslut) {
     ("Connected successfully......");
    } else {
     ("Connection failed(Incorrect username or password)...........");
     return;
    }
   } catch (Exception ex) {
    ("Network exception......");
    ();
    return;
   }
   String[] UserNumber = { "8618686619970","8618686619977"};
   //The mobile phone number for receiving text messages must be added to 86 in front of it   String content = "Unicom SMS sent successfully";
   byte[] MessageContent = ("GB2312");
    ("SMS content: "+content);
   try {
    // Send a short message    SGIPSubmitMessage sgipsubmit = new SGIPSubmitMessage(
      SPNumber, // SP's access number      ChargeNumber, // Paid number string      UserNumber, // The mobile phone number that receives the short message, up to 100 numbers string[]      CorpId, // Enterprise code, value range is 0~99999 string      ServiceType, // Business code, defined by SP string      03, // Billing type int      "0", // The charge value of this short message string      "0", // Give users a fee string      0, // Charging sign 0: Receivable 1: Actual receipt int      0, // The reason for causing MT message int      06, // Priority 0~9 From low to high, default is 0 int      null, // End time of short message life date      null, // The time for sending short messages regularly date      1, // Status report mark int      0, // GSM protocol type int      0, // GSM protocol type int      15, // Short message encoding format int      0, // Information type int      , // Short message content length int      MessageContent, // The content of the short message btye[]      "0" // Keep, use string to expand    );
    // The received response message is converted into rep    int status = ProcessSubmitRep((sgipsubmit));
    (status);
    if (status == 0) {
     ("Message sent successfully...");
    } else {
     ("Message sending failed...");
    }
   } catch (Exception ex) {
    ();   
   }
  }
  private static int ProcessSubmitRep(SGIPMessage msg) {
   // The received response message is converted to repMsg   SGIPSubmitRepMessage repMsg = (SGIPSubmitRepMessage) msg;
   (());
   ("status:::::::" + ());
   if (repMsg != null && () == 0) {
    ("Send successfully::");
   }
   return ();
  }
}

Up:

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);
  ("Enter start listening...");
  startService(localhost, localport);
  //I want to know whether the host and port passed here are local or that }
 public static void main(String[] args)
 {
  Args argstr = new Args();
  ("serHost", serHost);
  ("serviceport", serviceport);
  ("localhost", localhost);
  ("localport", localport);
  ("transaction-timeout", 10);
  // Operation timeout (unit: seconds)  ("read-timeout", 15);
  // Timeout time for physical connection read operation (unit: seconds)  //How to solve the security authentication problem here?  Mo mymo=new Mo(argstr);  
 }
 public SGIPMessage onDeliver(SGIPDeliverMessage msg) {
  ProcessRecvDeliverMsg(msg);
  ("Awaiting for reception...");
  return (msg);
 }
 public void ProcessRecvDeliverMsg(SGIPMessage msg) {
  if (msg instanceof SGIPSubmitRepMessage) {
  //Is it an instance of the class   ("Return to the corresponding message for sending the text message");
  }
  if (msg instanceof SGIPDeliverMessage) {
   // Receive a text message sent by the user (uplink)   SGIPDeliverMessage deliverMsg = (SGIPDeliverMessage) msg;
   String userNumber = ();
   // phone number   String msgContent = ();
   // SMS content   // byte[] msgId = ();
   ("userNumber::::::" + ());
   ("msgcontent:::::::" + ());
   ("spNumber::::::::" + ());
   //("Message received:" + deliverMsg);   ("Received Message:"+deliverMsg);
   int commandId = ();
   // Response type   ("commandId:::::::::" + commandId);
   if (commandId == 0) { //Upload SMS (receive)    ("dstaddr::::::" + ());
    try {
    } catch (Exception e) {
     // TODO Auto-generated catch block
     ();
    }
   }
  }
 }
}

I hope this article will be helpful to everyone's Java programming.