我正在使用 JSMPP
我已经和 smsc
我在试着发信息,试着收到送货收据
我正面临一个问题,我只想创建一个连接。如果你能帮我,那就太好了。我的代码是:
package com.jsmpp.dialerintegration;
public class SenderToMsgBroker{
public String sendingSms(String [] mobileNo) {
String [] receiverMobileNo = mobileNo;
String blankMSG="";
SMPPSession session = new SMPPSession();
try{
session.connectAndBind("ip", port,
new BindParameter(BindType.BIND_TRX, "username", "password",
"cp", TypeOfNumber.UNKNOWN,
NumberingPlanIndicator.UNKNOWN, null),1000*60*30,session);
System.out.println("Connection Established And SessionId :"+session.getSessionId());
System.out.println("SessionState"+session.getSessionState());
}
catch (IOException e) {
System.err.println("Failed connect and bind to host");
e.printStackTrace();
}
try {
for(int i=0;i<receiverMobileNo.length;i++)
{
session.setMessageReceiverListener(new MessageReceiverListenerImpl());
System.out.println("Trying to send the message->>>");
String messageId = session
.submitShortMessage(
null,
TypeOfNumber.UNKNOWN,
NumberingPlanIndicator.UNKNOWN,
"51633",
TypeOfNumber.UNKNOWN,
NumberingPlanIndicator.UNKNOWN,
receiverMobileNo[i],
new ESMClass(),
(byte) 0,
(byte) 1,
null,
null,
new RegisteredDelivery(
SMSCDeliveryReceipt.SUCCESS_FAILURE),
(byte) 0,
new GeneralDataCoding((byte) 0xc0),
(byte) 0,blankMSG.getBytes());
System.out.println("Message submitted, message_id is " + messageId);
System.out.println("Message Receiver Mobile No is :"
+ receiverMobileNo[i]);
}
} catch (PDUException e) {
// Invalid PDU parameter
System.err.println("Invalid PDU parameter");
e.printStackTrace();
return "PDUException";
} catch (ResponseTimeoutException e) {
// Response timeout
System.err.println("Response timeout");
e.printStackTrace();
return "ResponseTimeoutException";
} catch (InvalidResponseException e) {
// Invalid response
System.err.println("Receive invalid respose");
e.printStackTrace();
return "InvalidResponseException";
} catch (NegativeResponseException e) {
// Receiving negative response (non-zero command_status)
System.err.println("Receive negative response");
e.printStackTrace();
return "NegativeResponseException";
} catch (IOException e) {
System.err.println("IO error occur");
e.printStackTrace();
}
catch (Exception e) {
System.err.println("Exeption Occur");
e.printStackTrace();
return "Eror";
}
return "Success";
}
}
请帮我弄清楚我的问题
2条答案
按热度按时间mmvthczy1#
将smppsession对象作为示例变量移动,以便会话对象保持不变。
e5nszbig2#
您必须创建一个全局静态smppsession变量,如下所示。