我正在使用JSMPP(SMPP的Java实现)将SMS从我的Web应用程序发送到SMS中心。我有以下代码来接收任何已发送短信的发送报告。
public class MessageListenerImplementation implements MessageReceiverListener {
public void onAcceptDeliverSm(DeliverSm deliverSm) throws ProcessRequestException {
if (MessageType.SMSC_DEL_RECEIPT.containedIn(deliverSm.getEsmClass())) {
try {
DeliveryReceipt deliveryReceipt = deliverSm.getShortMessageAsDeliveryReceipt();
long id = Long.parseLong(deliveryReceipt.getId()) & 0xffffffff;
String messageId = Long.toString(id, 16).toUpperCase();
System.out.println("Delivery receipt for message '" + messageId + " ' from " + deliverSm.getSourceAddr() + " to " + deliverSm.getDestAddress() + " : " + deliveryReceipt);
}catch (InvalidDeliveryReceiptException e) {
System.err.println("Failed getting delivery receipt");
e.printStackTrace();
}
}
}
}
当我注册上述收听者收发短信并发送时,会收到如下送达回执
,交货收据如下
id:5 sub:001 dlvrd:001 submit date:1312091213 done date:1312091213 stat:DELIVRD err:000 text:Hello SMSC from ESME
现在我想知道如何在某个整数范围内检索发送状态,无论是发送,失败还是仍然挂起,以便我可以使用它来相应地更新我的数据库?
答案 0 :(得分:3)
Jsmpp中有针对所有传递状态代码的DeliveryReceiptState启动。
试试deliveryReceipt.getFinalStatus().value()
,你会给你整数值来更新数据库。
您将获得以下状态代码的整数值。
/**
* DELIVERED
*/
DELIVRD(1),
/**
* EXPIRED
*/
EXPIRED(2),
/**
* DELETED
*/
DELETED(3),
/**
* UNDELIVERABLE
*/
UNDELIV(4),
/**
* ACCEPTED
*/
ACCEPTD(5),
/**
* UNKNOWN
*/
UNKNOWN(6),
/**
* REJECTED
*/
REJECTD(7);