use of com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage in project SMSGate by Lihuanghe.
the class CmppDeliverResponseMessageCodec method decode.
@Override
protected void decode(ChannelHandlerContext ctx, Message msg, List<Object> out) throws Exception {
int commandId = msg.getHeader().getCommandId();
if (packetType.getCommandId() != commandId) {
// 不解析,交给下一个codec
out.add(msg);
return;
}
CmppDeliverResponseMessage responseMessage = new CmppDeliverResponseMessage(msg.getHeader());
ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
responseMessage.setMsgId(DefaultMsgIdUtil.bytes2MsgId(toArray(bodyBuffer, CmppDeliverResponse.MSGID.getLength())));
responseMessage.setResult(bodyBuffer.readUnsignedInt());
ReferenceCountUtil.release(bodyBuffer);
out.add(responseMessage);
}
use of com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage in project SMSGate by Lihuanghe.
the class CMPPResponseSenderHandler method channelRead.
@Override
public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception {
// 此时未经过长短信合并
if (msg instanceof CmppDeliverRequestMessage) {
CmppDeliverRequestMessage e = (CmppDeliverRequestMessage) msg;
CmppDeliverResponseMessage responseMessage = new CmppDeliverResponseMessage(e.getHeader().getSequenceId());
responseMessage.setResult(0);
responseMessage.setMsgId(e.getMsgId());
ctx.channel().writeAndFlush(responseMessage);
} else if (msg instanceof CmppSubmitRequestMessage) {
CmppSubmitRequestMessage e = (CmppSubmitRequestMessage) msg;
CmppSubmitResponseMessage resp = new CmppSubmitResponseMessage(e.getHeader().getSequenceId());
resp.setResult(0);
ctx.channel().writeAndFlush(resp);
if (e.getRegisteredDelivery() == 1) {
final CmppDeliverRequestMessage deliver = new CmppDeliverRequestMessage();
deliver.setDestId(e.getSrcId());
deliver.setSrcterminalId(e.getDestterminalId()[0]);
CmppReportRequestMessage report = new CmppReportRequestMessage();
report.setDestterminalId(deliver.getSrcterminalId());
report.setMsgId(resp.getMsgId());
String t = DateFormatUtils.format(CachedMillisecondClock.INS.now(), "yyMMddHHmm");
report.setSubmitTime(t);
report.setDoneTime(t);
report.setStat("DELIVRD");
report.setSmscSequence(0);
deliver.setReportRequestMessage(report);
ctx.executor().submit(new Runnable() {
public void run() {
ctx.channel().writeAndFlush(deliver);
}
});
}
} else if (msg instanceof CmppQueryRequestMessage) {
CmppQueryRequestMessage e = (CmppQueryRequestMessage) msg;
CmppQueryResponseMessage res = new CmppQueryResponseMessage(e.getHeader().getSequenceId());
ctx.channel().writeAndFlush(res);
}
ctx.fireChannelRead(msg);
}
Aggregations