Search in sources :

Example 1 with CmppQueryResponseMessage

use of com.zx.sms.codec.cmpp.msg.CmppQueryResponseMessage in project SMSGate by Lihuanghe.

the class CMPPSessionConnectedHandler method channelRead.

public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof CmppDeliverRequestMessage) {
        CmppDeliverRequestMessage e = (CmppDeliverRequestMessage) msg;
        if (e.getFragments() != null) {
            // 长短信会带有片断
            for (CmppDeliverRequestMessage frag : e.getFragments()) {
                CmppDeliverResponseMessage responseMessage = new CmppDeliverResponseMessage(frag.getHeader().getSequenceId());
                responseMessage.setResult(0);
                responseMessage.setMsgId(frag.getMsgId());
                ctx.channel().write(responseMessage);
            }
        }
        CmppDeliverResponseMessage responseMessage = new CmppDeliverResponseMessage(e.getHeader().getSequenceId());
        responseMessage.setResult(0);
        responseMessage.setMsgId(e.getMsgId());
        ctx.channel().writeAndFlush(responseMessage);
    } else if (msg instanceof CmppDeliverResponseMessage) {
        CmppDeliverResponseMessage e = (CmppDeliverResponseMessage) msg;
    } else if (msg instanceof CmppSubmitRequestMessage) {
        // 接收到 CmppSubmitRequestMessage 消息
        CmppSubmitRequestMessage e = (CmppSubmitRequestMessage) msg;
        final List<CmppDeliverRequestMessage> reportlist = new ArrayList<CmppDeliverRequestMessage>();
        if (e.getFragments() != null) {
            // 长短信会可能带有片断,每个片断都要回复一个response
            for (CmppSubmitRequestMessage frag : e.getFragments()) {
                CmppSubmitResponseMessage responseMessage = new CmppSubmitResponseMessage(frag.getHeader().getSequenceId());
                responseMessage.setResult(0);
                ctx.channel().write(responseMessage);
                CmppDeliverRequestMessage deliver = new CmppDeliverRequestMessage();
                deliver.setDestId(e.getSrcId());
                deliver.setSrcterminalId(e.getDestterminalId()[0]);
                CmppReportRequestMessage report = new CmppReportRequestMessage();
                report.setDestterminalId(deliver.getSrcterminalId());
                report.setMsgId(responseMessage.getMsgId());
                String t = DateFormatUtils.format(CachedMillisecondClock.INS.now(), "yyMMddHHmm");
                report.setSubmitTime(t);
                report.setDoneTime(t);
                report.setStat("DELIVRD");
                report.setSmscSequence(0);
                deliver.setReportRequestMessage(report);
                reportlist.add(deliver);
            }
        }
        final 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);
            reportlist.add(deliver);
            ctx.executor().submit(new Runnable() {

                public void run() {
                    for (CmppDeliverRequestMessage t : reportlist) ctx.channel().writeAndFlush(t);
                }
            });
        }
    } else if (msg instanceof CmppSubmitResponseMessage) {
        CmppSubmitResponseMessage e = (CmppSubmitResponseMessage) msg;
    } else if (msg instanceof CmppQueryRequestMessage) {
        CmppQueryRequestMessage e = (CmppQueryRequestMessage) msg;
        CmppQueryResponseMessage res = new CmppQueryResponseMessage(e.getHeader().getSequenceId());
        ctx.channel().writeAndFlush(res);
    } else {
        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) ArrayList(java.util.ArrayList) CmppReportRequestMessage(com.zx.sms.codec.cmpp.msg.CmppReportRequestMessage) CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage) CmppSubmitResponseMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage)

Example 2 with CmppQueryResponseMessage

use of com.zx.sms.codec.cmpp.msg.CmppQueryResponseMessage in project SMSGate by Lihuanghe.

the class CmppQueryResponseMessageCodec 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;
    }
    CmppQueryResponseMessage responseMessage = new CmppQueryResponseMessage(msg.getHeader());
    ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
    responseMessage.setTime(bodyBuffer.readCharSequence(CmppQueryResponse.TIME.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    responseMessage.setQueryType(bodyBuffer.readUnsignedByte());
    responseMessage.setQueryCode(bodyBuffer.readCharSequence(CmppQueryResponse.QUERYCODE.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    responseMessage.setMtTLMsg(bodyBuffer.readUnsignedInt());
    responseMessage.setMtTLUsr(bodyBuffer.readUnsignedInt());
    responseMessage.setMtScs(bodyBuffer.readUnsignedInt());
    responseMessage.setMtWT(bodyBuffer.readUnsignedInt());
    responseMessage.setMtFL(bodyBuffer.readUnsignedInt());
    responseMessage.setMoScs(bodyBuffer.readUnsignedInt());
    responseMessage.setMoWT(bodyBuffer.readUnsignedInt());
    responseMessage.setMoFL(bodyBuffer.readUnsignedInt());
    ReferenceCountUtil.release(bodyBuffer);
    out.add(responseMessage);
}
Also used : CmppQueryResponseMessage(com.zx.sms.codec.cmpp.msg.CmppQueryResponseMessage) ByteBuf(io.netty.buffer.ByteBuf)

Example 3 with CmppQueryResponseMessage

use of com.zx.sms.codec.cmpp.msg.CmppQueryResponseMessage 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)

Example 4 with CmppQueryResponseMessage

use of com.zx.sms.codec.cmpp.msg.CmppQueryResponseMessage in project SMSGate by Lihuanghe.

the class TestCmppQueryResponseMessageCodec method testCodec.

@Test
public void testCodec() {
    CmppQueryResponseMessage msg = new CmppQueryResponseMessage(1313);
    msg.setQueryCode("sdf");
    ByteBuf buf = encode(msg);
    ByteBuf copybuf = buf.copy();
    int length = buf.readableBytes();
    int expectLength = CmppQueryResponse.QUERYCODE.getBodyLength() + CmppHead.COMMANDID.getHeadLength();
    Assert.assertEquals(expectLength, length);
    Assert.assertEquals(expectLength, buf.readInt());
    Assert.assertEquals(msg.getPacketType().getCommandId(), buf.readInt());
    Assert.assertEquals(msg.getHeader().getSequenceId(), buf.readInt());
    CmppQueryResponseMessage result = decode(copybuf);
    Assert.assertEquals(msg.getHeader().getSequenceId(), result.getHeader().getSequenceId());
    Assert.assertEquals(msg.getQueryCode(), result.getQueryCode());
}
Also used : CmppQueryResponseMessage(com.zx.sms.codec.cmpp.msg.CmppQueryResponseMessage) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

CmppQueryResponseMessage (com.zx.sms.codec.cmpp.msg.CmppQueryResponseMessage)4 CmppDeliverRequestMessage (com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage)2 CmppDeliverResponseMessage (com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage)2 CmppQueryRequestMessage (com.zx.sms.codec.cmpp.msg.CmppQueryRequestMessage)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 ByteBuf (io.netty.buffer.ByteBuf)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1