Java implementation of SGIP protocol based on the development of unicom SMS method
- 2020-04-01 04:01:41
- OfStack
The example of this paper describes the Java implementation of SGIP protocol based on the development of unicom SMS method. Share with you for your reference. The details are as follows:
Recently, due to the business needs of the company, China unicom short message has been developed. This article is also written according to some online examples.
The downside:
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 = ****;
//The port number
private static String CorpId = "*****";
//Enterprise code
private static String login_Name = "**";
//Login name
private static String login_PassWord = "***";
//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 the huawei package, the field type is int, and the access protocol requires the enterprise code before 30,000, which is beyond the int range, so you need to use BigInteger to turn it
Args argstr = new Args();//Set connection parameters
argstr.set("host", host);
argstr.set("port", port);
argstr.set("transaction-timeout", 10);
//Operation timeout time (in seconds)
argstr.set("read-timeout", 15);
//Physical connection read operation timeout time (in seconds)
argstr.set("source-addr", srcnode);
//SP... ID(up to six characters)
argstr.set("login-name", login_Name);
argstr.set("login-pass", login_PassWord);
argstr.set("debug", "false");
//Connection to land
SGIPSMProxy sgipsmp = new SGIPSMProxy(argstr);
//This is connected to the SMS gateway
try {
//Connect means to login to SMG, the login name and password are respectively the user name and password assigned by SMG to SP. Call this interface method and send the Bind command message to SMG.
//If a message timeout is sent or a communication exception is thrown, the caller needs to catch the handle.
boolean reslut = sgipsmp.connect(login_Name, login_PassWord);
//Log in and you get true and false
if (reslut) {
System.out.println(" The connection is successful ...........");
} else {
System.out.println(" The connection fails ( Wrong username or password )...........");
return;
}
} catch (Exception ex) {
System.out.println(" Network anomalies ...........");
ex.printStackTrace();
return;
}
String[] UserNumber = { "8618686619970","8618686619977"};
//The cell phone number to receive a text message is 86
String content = " China unicom message was sent successfully ";
byte[] MessageContent = content.getBytes("GB2312");
System.out.println(" Message content : "+content);
try {
//Issued by the short interest rates
SGIPSubmitMessage sgipsubmit = new SGIPSubmitMessage(
SPNumber, //SP access number
ChargeNumber, //Payment number string
UserNumber, //The mobile phone number to receive the short message, up to 100 Numbers string[]
CorpId, //Enterprise code, with values ranging from 0 to 99999 strings
ServiceType, //Business code, defined by SP stirng
03, //Billing type int
"0", //The charge value of this short message is stirng
"0", //Give the user a free call string
0, //Agent charge mark 0: receivable 1: paid int
0, //The cause of the MT message is int
06, //Priority 0 ~ 9 from low to high, default is 0 int
null, //End of short message life date
null, //The time date when short messages are timed to be sent
1, //Status report marks int
0, //GSM protocol type int
0, //GSM protocol type int
15, //The encoding format for short messages is int
0, //Information type int
MessageContent.length, //Short message content length int
MessageContent, //Content of short message btye[]
"0" //Keep, extend with string
);
//The response message received 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 delivery failed ..........");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static int ProcessSubmitRep(SGIPMessage msg) {
//The response message received is converted 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(" Send successfully... ");
}
return repMsg.getResult();
}
}
The upside:
public class Mo extends SGIPSMProxy {
//SMG server information
private static String serHost = "***.***.***.***";
private static int serviceport = ****;
//The machine 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 want to know if the host and port passed here are local or there
}
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 time (in seconds)
argstr.set("read-timeout", 15);
//Physical connection read operation timeout time (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 for reception .......");
return super.onDeliver(msg);
}
public void ProcessRecvDeliverMsg(SGIPMessage msg) {
if (msg instanceof SGIPSubmitRepMessage) {
//Is an instance of a class
System.out.println(" Returns the message that sent the message ");
}
if (msg instanceof SGIPDeliverMessage) {
//Received SMS from the user (uplink)
SGIPDeliverMessage deliverMsg = (SGIPDeliverMessage) msg;
String userNumber = deliverMsg.getUserNumber();
//Mobile phone number
String msgContent = deliverMsg.toString();
//Message 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 message :" + deliverMsg);
System.out.println(" Messages are received : "+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 has been helpful to your Java programming.