Search in sources :

Example 6 with CmppDeliverResponseMessage

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);
}
Also used : CmppDeliverResponseMessage(com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage) ByteBuf(io.netty.buffer.ByteBuf)

Example 7 with CmppDeliverResponseMessage

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);
}
Also used : CmppQueryRequestMessage(com.zx.sms.codec.cmpp.msg.CmppQueryRequestMessage) CmppQueryResponseMessage(com.zx.sms.codec.cmpp.msg.CmppQueryResponseMessage) CmppDeliverRequestMessage(com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage) CmppDeliverResponseMessage(com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage) CmppReportRequestMessage(com.zx.sms.codec.cmpp.msg.CmppReportRequestMessage) CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage) CmppSubmitResponseMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage)

Aggregations

CmppDeliverResponseMessage (com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage)7 ByteBuf (io.netty.buffer.ByteBuf)4 CmppDeliverRequestMessage (com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage)2 CmppQueryRequestMessage (com.zx.sms.codec.cmpp.msg.CmppQueryRequestMessage)2 CmppQueryResponseMessage (com.zx.sms.codec.cmpp.msg.CmppQueryResponseMessage)2 CmppReportRequestMessage (com.zx.sms.codec.cmpp.msg.CmppReportRequestMessage)2 CmppSubmitRequestMessage (com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage)2 CmppSubmitResponseMessage (com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage)2 MsgId (com.zx.sms.common.util.MsgId)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1