⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smpp34submitdemo.java

📁 pk_Total - 相同msg_Id消息总条数 pk_Number - 相同msg_Id的消息序号 registered_Delivery - 是否要求返回状态报告 msg_Level - 信
💻 JAVA
字号:
package demo.smpp34demo;

import com.huawei.smproxy.util.Debug;
import com.huawei.smproxy.comm.smpp34.*;
import com.huawei.smproxy.comm.smpp34.message.*;
import com.huawei.smproxy.util.CharSetUtil;
import java.util.ArrayList;
import java.io.IOException;
import java.io.UnsupportedEncodingException;


public class SMPP34SubmitDemo
{
	public SMPP34SubmitDemo ()
	{
	}

	public static void main (String[] args)
	{
		try
		{
			/**
			 * 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)1;
			String sourceAddr = "1860";
			byte destAddrTon = (byte)0;
			byte destAddrNpi = (byte)1;

			//Constructs the destination addresses.
			System.out.print("create rcvMobiles start......");
			String[] rcvMobile = new String[10];
			int count = 0;
			for (int i = 0; i<10; i++)
			{
				rcvMobile[i] = "1381230000"+i;
				count++;
			}
			System.out.print("Create rcvMobiles end.");

			System.out.print("Create new SMPPUnbindMessage bgegin.");
			SMPP34UnbindMessage exitMsg = new SMPP34UnbindMessage();

			int sendcount = 2;
			int sendinterval = 3;

			SMSender proxy = SMSender.getInstance();
			String msgContent = "Message Content.";
			int msgLength = 0;
			int dataCoding = 0;

			try
			{
				msgLength = msgContent.getBytes(CharSetUtil.getCharset(dataCoding)).length;
			}
			catch (UnsupportedEncodingException ex)
			{}

			//Constructs a list of option arguments.
			ConstructTLV tlvargs = new ConstructTLV();
		    tlvargs.adduser_message_reference();
		    tlvargs.addsource_port();
			tlvargs.addsource_addr_subunit();
			tlvargs.addpayload_type();
			tlvargs.addcallback_num_pres_ind();
			tlvargs.addcallback_num_atag();
			tlvargs.adddestination_port();

			//Constructs a SMPP34SubmitMessage.
			for (int i = 0; i<sendcount; i++)
			{
				SMPP34SubmitMessage msg = new SMPP34SubmitMessage(
										  "", //serviceType
										  sourceAddrTon, // sourceAddrTon
										  sourceAddrNpi, // sourceAddrNpi
										  sourceAddr, //sourceAddr
										  destAddrTon, // destAddrTon
										  destAddrNpi, //destAddrNpi
										  rcvMobile[i], // destinationAddr
										  (byte)1, // esmClass
										  (byte)2, //protocolId
										  (byte)3, // priorityFlag
										  "060426203000032+", // scheduleDeliveryTime
										  "060426233234032+", // validityPeriod
                                          (byte)1, // registeredDelivery
										  (byte)0, // replaceIfPresentFlag
										  (byte)dataCoding, // dataCoding
										  (byte)123, // smDefaultMsgId
										  msgLength, // smLength
										  msgContent, // shortMessage
										  tlvargs.getTLVList()
										  );
				SMPP34SubmitRespMessage respMsg = (SMPP34SubmitRespMessage)proxy.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();
				}
			}
			//---------------------------------------------------
			//Constructs a list of option arguments.
			tlvargs.clear();
			tlvargs.addsar_total_segments();
			tlvargs.addsource_port();

			//Constructs a SMPP34DataMessage.
			for (int i = 0; i<sendcount; i++)
			{
				SMPP34DataMessage msgData = new SMPP34DataMessage(
											"",
											sourceAddrTon,
											sourceAddrNpi,
											sourceAddr,
											destAddrTon,
											destAddrNpi,
											rcvMobile[i],
											(byte)0,
											(byte)0,
											(byte)dataCoding,
											tlvargs.getTLVList()
											);
				SMPP34DataRespMessage respMsgData = null;
				respMsgData = (SMPP34DataRespMessage)proxy.send(msgData);
				if (respMsgData!=null)
				{
					respMsgData.getMessageId();
					System.out.println(" success! respMsg =="
						+respMsgData.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 SMPP34QueryMessage.
			   tlvargs.clear();
			   for (int i = 0; i<sendcount; i++)
			   {
				   SMPP34QueryMessage msgQuery = new SMPP34QueryMessage(
												 (String)msgIdList.get(i),
												 sourceAddrTon,
												 sourceAddrNpi,
												 sourceAddr
												 );
				   SMPP34QueryRespMessage respMsgQuery = null;
				   respMsgQuery = (SMPP34QueryRespMessage)proxy.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("gb2312");
					msgLength = msgContentBytes.length;
				}
				catch (UnsupportedEncodingException ex)
				{}

				tlvargs.clear();
				for (int i = 0; i<sendcount; i++)
				{
					SMPP34ReplaceMessage msgRepalce = new SMPP34ReplaceMessage(
													  (String)msgIdList.get(i),
													  sourceAddrTon,
													  sourceAddrNpi,
                                                      sourceAddr,
													  "060525121314032+",
													  "000000000514000R",
													  (byte)1,
													  (byte)0,
													  msgLength,
													  msgContentBytes
													  );
					SMPP34ReplaceRespMessage respMsgReplace = null;
					respMsgReplace = (SMPP34ReplaceRespMessage)proxy.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 SMPP34CancelMessage.
				tlvargs.clear();
				for (int i = 0; i<sendcount; i++)
				{
					SMPP34CancelMessage msgCancel = new SMPP34CancelMessage(
													"",
													(String)msgIdList.get(i), //Var max 6:C_Octet String
													sourceAddrTon, // 1:Integer
													sourceAddrNpi, // 1:Integer
                                                    sourceAddr, //Var max 21:C_Octet String
													sourceAddrTon,
													sourceAddrNpi,
													rcvMobile[i]
													);
					SMPP34CancelRespMessage respMsgCancel = null;
					respMsgCancel = (SMPP34CancelRespMessage)proxy.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();
					}
				}
			}

			//--------------------------------------
			//Constucts a SMPP34SubmitMultiMessage.

			//Constructs the destination addresses.
			  int destNum = 3;
			  byte[] destFlag = new byte[destNum];
			  byte[] dest_addr_ton = new byte[destNum];
			  byte[] dest_addr_npi = new byte[destNum];
			  String[] destinationAddrOrDlName = new String[destNum];
			  for (int i = 0; i<destNum; i++)
			  {//for example: 2 for Distribution List; 1 for Destination Address
				  if (i%2==0)
				  { //Distribution List
					  destFlag[i] = 2;
					  destinationAddrOrDlName[i] = "AA";
				  }
				  else
				  {//Destination Address
					  destFlag[i] = 1;
					  dest_addr_ton[i] = 2;
					  dest_addr_npi[i] = 1;
					  destinationAddrOrDlName[i] = "9999";
				  }
			  }
			  //Constructs the message content.
			  String msgMultiContent = "Message content.";
			  int msgMultiLength = 0;
			  try
			  {
			       msgMultiLength = msgMultiContent.getBytes(CharSetUtil.getCharset(dataCoding)).length;
			  }
			  catch (UnsupportedEncodingException ex)
			  {}
			  tlvargs.clear();
			  tlvargs.adduser_message_reference();
			  for (int i = 0; i<sendcount; i++)
			  {
				  SMPP34SubmitMultiMessage msgMulti = new
													  SMPP34SubmitMultiMessage(
													  "",
													  sourceAddrTon,
													  sourceAddrNpi,
													  sourceAddr,
													  destNum,
													  destFlag,
													  dest_addr_ton,
													  dest_addr_npi,
													  destinationAddrOrDlName,
													  (byte)0,
													  (byte)0,
													  (byte)0,
													  "060426222536032+",
													  "060426232536032+",
													  (byte)0,
													  (byte)0,
													  (byte)dataCoding,
													  (byte)0,
													  msgMultiLength,
													  msgMultiContent,
													  tlvargs.getTLVList()
													  );
				  SMPP34SubmitMultiRespMessage respMultiMsg = (
					   SMPP34SubmitMultiRespMessage)(
					   proxy.send(msgMulti));

			if (respMultiMsg!=null)
			{
				respMultiMsg.getMessageId();
				System.out.println(" success! respMsg =="
					+respMultiMsg.toString());
			}
			else
			{
				System.out.println("Fail");
			}
			try
			{
				Thread.sleep(sendinterval);
			}
			catch (InterruptedException ex)
			{
				Debug.dump("thread error!");
				ex.printStackTrace();
			}
		}

		   //----------------------------
		   try
		   {
			   Thread.sleep(100000);
		   }
		   catch (InterruptedException ex)
		   {}

			//send exitMessage
			proxy.send(exitMsg);

		}
		catch (Exception e)
		{}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -