📄 smsender.java
字号:
package demo.smppdemo ;
import java.io.IOException ;
import java.sql.PreparedStatement ;
import java.util.LinkedList ;
import java.util.List ;
import com.huawei.smproxy.SMPPSMProxy ;
import com.huawei.smproxy.comm.smpp.message.* ;
import com.huawei.smproxy.util.Args ;
import com.huawei.smproxy.util.Debug ;
/**
* 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 SMPPSMProxy
{
//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 SMPPDeliverMessage msg)
{
//Status Report
if (msg.getRegisteredDelivery()==1)
{
//Handles the Status Report.
return new SMPPDeliverRespMessage(0);
}
//Deliver Message
else
{
//Handles the Deliver Message.
System.out.println("Received a deliver message.");
return new SMPPDeliverRespMessage(0);
}
}
/**
* 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 + -