📄 smppdemo.java
字号:
package demo.smppdemo ;
import java.io.IOException ;
import java.io.UnsupportedEncodingException ;
import com.huawei.smproxy.comm.smpp.message.* ;
import com.huawei.smproxy.util.Debug ;
import java.util.ArrayList;
import com.huawei.smproxy.util.CharSetUtil;
public class SMPPDemo
{
public static void main ( String[] args )
{
/**
* A list saved the msgid the SMSC message ID of the submitted message.
* It may be used at a later stage to query the status of a message, cancel or replace the message.
*/
ArrayList msgIdList = new ArrayList();
byte sourceAddrTon = (byte)0;
byte sourceAddrNpi = (byte)0;
String sourceAddr = "8888";
//Constructs the destination addresses.
System.out.print("create rcvMobiles start......");
String[] rcvMobile = new String[8];
int count = 0;
for (int i = 0; i<2; i++)
{
for (int j = 0; j<4; j++)
{
rcvMobile[count] = "139030000"+i+j;
count++;
}
}
System.out.println("Create rcvMobiles end.");
System.out.print("new SMPPMessage...");
SMPPUnbindMessage exitMsg = new SMPPUnbindMessage();
int sendcount = 2;
int sendinterval = 5000;
int dataCoding = 0;
SMSender sender = SMSender.getInstance();
String msgContent = "Message Content.";
int msgLength = 0;
try
{
msgLength = msgContent.getBytes(CharSetUtil.getCharset(dataCoding)).length;
}
catch (UnsupportedEncodingException ex)
{
Debug.dump("UnsupportedEncoding error or message length error !");
ex.printStackTrace();
}
for (int i = 0; i<sendcount; i++)
{
System.out.print("Send Message...");
SMPPSubmitMessage msg = new SMPPSubmitMessage(
"abc", //serviceType,
sourceAddrTon, //sourceAddrTon,
sourceAddrNpi, //sourceAddrNpi,
sourceAddr, //sourceAddr,
(byte)0, //destAddrTon,
(byte)0, //destAddrNpi,
rcvMobile[i], //rcvMobile[i], //destinationAddr,
(byte)0, //esmClass,
(byte)0, //protocolId,
(byte)1, //priorityFlag,
"060430201314032+", //scheduleDeliveryTime,
"060430151314032+", //validityPeriod,
(byte)0, //registeredDelivery,
(byte)0, //replaceIfPresentFlag,
(byte)dataCoding, //dataCoding,
(byte)0, //smDefaultMsgId,
msgLength, //smLength,
msgContent); //shortMessage
SMPPSubmitRespMessage respMsg = (SMPPSubmitRespMessage)sender.send(msg);
if (respMsg!=null)
{
msgIdList.add(i, respMsg.getMessageId());
System.out.println(" success! respMsg =="+respMsg.toString());
}
else
{
System.out.println("Fail");
}
try
{
Thread.sleep(sendinterval);
}
catch (InterruptedException ex)
{
Debug.dump("thread error!");
ex.printStackTrace();
}
}
//===========================================
if (msgIdList.size()>0)
{
//Constructs a SMPPQueryMessage.
for (int i = 0; i<sendcount; i++)
{
SMPPQueryMessage msgQuery = new SMPPQueryMessage(
(String)msgIdList.get(i), //Var max 6:C_Octet String
sourceAddrTon, // 1:Integer
sourceAddrNpi, // 1:Integer
sourceAddr //Var max 21:C_Octet String
);
SMPPQueryRespMessage respMsgQuery = null;
respMsgQuery = (SMPPQueryRespMessage)sender.send(msgQuery);
if (respMsgQuery!=null)
{
respMsgQuery.getMessageId();
System.out.println(" success! respMsg =="
+respMsgQuery.toString());
}
else
{
System.out.println("Fail");
}
try
{
Thread.sleep(sendinterval);
}
catch (InterruptedException ex)
{
Debug.dump("thread error!");
ex.printStackTrace();
}
}
//----------------------------
//Constructs a SMPP34ReplaceMessage.
msgContent = "Message Content.";
byte[] msgContentBytes = null;
msgLength = 0;
try
{
msgContentBytes = msgContent.getBytes(CharSetUtil.getCharset(
dataCoding));
msgLength = msgContentBytes.length;
}
catch (UnsupportedEncodingException ex)
{}
for (int i = 0; i<sendcount; i++)
{
SMPPReplaceMessage msgRepalce = new SMPPReplaceMessage(
(String)msgIdList.get(i),
sourceAddrTon,
sourceAddrNpi,
sourceAddr,
"060426221314032+",
"060427221314032+",
(byte)0,
(byte)0,
msgLength,
msgContentBytes
);
SMPPReplaceRespMessage respMsgReplace = null;
respMsgReplace = (SMPPReplaceRespMessage)sender.send(msgRepalce);
if (respMsgReplace!=null)
{
System.out.println(" success! respMsg =="
+respMsgReplace.toString());
}
else
{
System.out.println("Fail");
}
try
{
Thread.sleep(sendinterval);
}
catch (InterruptedException ex)
{
Debug.dump("thread error!");
ex.printStackTrace();
}
}
//--------------------------------
//Constructs a SMPPCancelMessage.
msgContent = "Message Contents.";
msgLength = 0;
try
{
msgLength = msgContent.getBytes(CharSetUtil.getCharset(dataCoding)).length;
}
catch (UnsupportedEncodingException ex)
{}
for (int i = 0; i<sendcount; i++)
{
SMPPCancelMessage msgCancel = new SMPPCancelMessage(
"abcde",
(String)msgIdList.get(i),
sourceAddrTon,
sourceAddrNpi,
sourceAddr,
sourceAddrTon,
sourceAddrNpi,
rcvMobile[i]
);
SMPPCancelRespMessage respMsgCancel = null;
respMsgCancel = (SMPPCancelRespMessage)sender.send(msgCancel);
if (respMsgCancel!=null)
{
System.out.println(" success! respMsg =="
+respMsgCancel.toString());
}
else
{
System.out.println("Fail");
}
try
{
Thread.sleep(sendinterval);
}
catch (InterruptedException ex)
{
Debug.dump("thread error!");
ex.printStackTrace();
}
}
}
//===========================================
try
{
Thread.sleep ( 30000 ) ;
}
catch ( InterruptedException ex )
{}
//send exitMessage
sender.send ( exitMsg ) ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -