gpt4 book ai didi

java - 如何使用cloudhopper异步发送deliverS Resp

转载 作者:行者123 更新时间:2023-12-01 17:36:09 28 4
gpt4 key购买 nike

希望大家都能安然度过这次疫情。

我收到一条来自 SMSC 的短信,我想向他发送一条 Deliver_sm_resp。

我尝试这样实现:

@Override
public PduResponse firePduRequestReceived(PduRequest pduRequest) {
logger.warn("***** BIND RECEIVER *****");
DeliverSm sms = null;

if ((pduRequest != null) && pduRequest.getName().equals("deliver_sm")) {
sms = (DeliverSm) pduRequest;
}
if ((pduRequest != null) && pduRequest.getName().equals("enquire_link")) {
return pduRequest.createResponse();
}
if ( sms !=null && (int)sms.getDataCoding() == 0 ) {
//message content is English
logger.warn("***** New Message Received *****");
logger.warn("From: " + sms.getSourceAddress().getAddress());
logger.warn("To: " + sms.getDestAddress().getAddress());
logger.warn("Content: " + new String(sms.getShortMessage()));


DeliverSm deliver = new DeliverSm();
deliver.setSourceAddress(sms.getSourceAddress());
deliver.setDestAddress(sms.getDestAddress());
deliver.setDataCoding(sms.getDataCoding());
try {
deliver.setShortMessage(sms.getShortMessage());
} catch (SmppInvalidArgumentException e) {
e.printStackTrace();
}
deliver.setSequenceNumber(sms.getSequenceNumber());
//deliver.setCommandLength(sms.getCommandLength());
deliver.setCommandStatus(sms.getCommandStatus());


runDeliverSmRespSmppSessionHandler(session, deliver);

}
return super.firePduRequestReceived(pduRequest);
}

我异步调用 runDeliverSmRespSmppSessionHandler,如下所示:

    public class RunDeliverSmRespSmppSessionHandler extends DefaultSmppSessionHandler implements Runnable {
.
.
.
public void run() {
logger.info("welcome to deliver TestSmppSessionHandler RUN");

sendRequestPdu(session, deliver);
}
private void sendRequestPdu(SmppSession session, DeliverSm deliver) {
logger.info("welcome to deliver TestSmppSessionHandler sendRequestPdu");

try {
WindowFuture<Integer,PduRequest,PduResponse> future = session.sendRequestPdu(deliver, 10000, false);
if (!future.await()) {
logger.error("Failed to receive deliver_sm_resp within specified time");
} else if (future.isSuccess()) {
DeliverSmResp deliverSmResp = (DeliverSmResp)future.getResponse();
logger.info("deliver_sm_resp: commandStatus [" + deliverSmResp.getCommandStatus() + "=" + deliverSmResp.getResultMessage() + "]");
} else {
logger.error("Failed to properly receive deliver_sm_resp: " + future.getCause());
}
} catch (Exception e) {
logger.error("message catched in smDeliver : "+e.getMessage()+" get stackTrace : "+e.getStackTrace());

}
}

不幸的是,我在 sendRequestPdu() 中遇到了这个错误:

04-04-2020 23:15:41 ERROR TestSmppSessionHandler:61 - Failed to receive deliver_sm_resp within specified time
04-04-2020 23:16:06 WARN EnquireLinkTask:37 - Enquire link failed, executing reconnect:
com.cloudhopper.smpp.type.SmppTimeoutException: Unable to accept offer within [10000 ms] (window full)
at com.cloudhopper.smpp.impl.DefaultSmppSession.sendRequestPdu(DefaultSmppSession.java:508)
at com.cloudhopper.smpp.impl.DefaultSmppSession.sendRequestAndGetResponse(DefaultSmppSession.java:464)

感谢您的帮助

最佳答案

要发送回复以告知 SMSC 您收到了 SMS,您必须使用

   private void sendResponsePdu(SmppSession session, DeliverSmResp deliver) {
logger.info("welcome to deliver TestSmppSessionHandlerV2 sendRequestPdu");

try {
session.sendResponsePdu(deliver);
logger.info("message deliver response sent successfully !!!");

} catch (Exception e) {
logger.error("message catched in smDeliver : "+e.getMessage()+" get stackTrace : "+e.getStackTrace());

}

关于DeliverSmResp Deliver,您可以这样初始化:

            DeliverSmResp deliver_sm_resp = new DeliverSmResp();

deliver_sm_resp.setCommandLength(17);
deliver_sm_resp.setCommandStatus(sms.getCommandStatus());
deliver_sm_resp.setSequenceNumber(sms.getSequenceNumber());
deliver_sm_resp.setMessageId("");

关于java - 如何使用cloudhopper异步发送deliverS Resp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61034979/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com