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

📄 smsender.java

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

import java.io.IOException ;
import java.sql.PreparedStatement ;
import java.util.LinkedList ;
import java.util.List ;

import com.huawei.smproxy.SMPPSMProxy34 ;
import com.huawei.smproxy.comm.smpp34.message.*;
import com.huawei.smproxy.util.Args ;
import com.huawei.smproxy.util.Debug ;
import com.huawei.smproxy.comm.smpp.message.SMPPMessage;
import com.huawei.smproxy.comm.smpp.SMPPConstant;
/**
 * A iuniform external interface for sending and receiving messages.
 * The SMSender class provides methods for connecting with the infoX-SMS GW and infoX-SMS, sending messages, and receiving messages.
 */
public class SMSender extends SMPPSMProxy34
{
	//Gets the information of system configuration in the configuration file, such as config.xml.
	//The Args class provide a container whith be used for saving various argument.
	private static Args arg = Env.getConfig ().getArgs ( "SMPPConnect" ) ;

	private static SMSender instance ;

	public static SMSender getInstance ()
	{
		if ( instance == null )
		{
			instance = new SMSender () ;
		}
		return instance ;
	}

	protected SMSender ()
	{
		super ( SMSender.arg ) ;
	}

	/**
	 * Do something when connection is interrupted.
	 * The method can be overwrited when necessary.
	 */
	public void OnTerminate ()
	{
		Debug.dump ( "Connection has been breaked! " ) ;
	}

	/**
	 * Handles the received deliver messages.
	 * The method can be overwrited by infoX-SMSAPI users.
	 * @param msg SMPPDeliverMessage - Message recieved from the SMSC.
	 * @return SMPPMessage - Response message received.
	 */
	public SMPPMessage onDeliver (final SMPPMessage msg)
	{
		if (msg.getCommandId()==SMPPConstant.Data_SM_Command_Id)
		{
			return new SMPP34DataRespMessage(0, null, null);
		}
		else if (msg.getCommandId()==SMPPConstant.Deliver_Command_Id)
		{
			SMPP34DeliverMessage dlvMsg =(SMPP34DeliverMessage)msg;
			if (dlvMsg.getRegisteredDelivery()==1)
			{//Status Report
				//Handles the Status Report, implements by infoX-SMSAPI users.
				return new SMPP34DeliverRespMessage(0);
			}
			else
			{//Deliver Message
				//Handles the Deliver Message, implements by infoX-SMSAPI users.
				System.out.println("Received a deliver message.");
				return new SMPP34DeliverRespMessage(0);
			}
		}
		else return null;
	}

	/**
	 * Sends the message.
	 * The method bloked till the response is received or the operation times out.
	 * @param msg SMPP34SubmitMessage - Returns the received message
	 * @return SMPP34SubmitRespMessage
	 */
	public SMPPMessage send (SMPPMessage msg)
	{
		if (msg==null)
		{
			return null;
		}
		SMPPMessage reportMsg = null;
		PreparedStatement stat = null;
		try
		{
			reportMsg = (SMPPMessage)super.send(msg);
		}
		catch (IOException ex)
		{
			Debug.dump("message sending error!");
			ex.printStackTrace();
			return null;
		}
		return reportMsg;
	}
}

⌨️ 快捷键说明

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