Search in sources :

Example 1 with CmppReportRequestMessage

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

the class TestCmppDeliverRequestMessageCodec method testReportCodec.

@Test
public void testReportCodec() {
    CmppDeliverRequestMessage msg = createTestReq("k k k ");
    msg.setMsgContent((SmsMessage) null);
    CmppReportRequestMessage reportRequestMessage = new CmppReportRequestMessage();
    reportRequestMessage.setSmscSequence(0x1234L);
    reportRequestMessage.setMsgId(new MsgId());
    reportRequestMessage.setDestterminalId("13800138000");
    reportRequestMessage.setStat("9876");
    msg.setReportRequestMessage(reportRequestMessage);
    test0(msg);
}
Also used : CmppDeliverRequestMessage(com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage) CmppReportRequestMessage(com.zx.sms.codec.cmpp.msg.CmppReportRequestMessage) MsgId(com.zx.sms.common.util.MsgId) Test(org.junit.Test)

Example 2 with CmppReportRequestMessage

use of com.zx.sms.codec.cmpp.msg.CmppReportRequestMessage 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 3 with CmppReportRequestMessage

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

the class CmppDeliverRequestMessageCodec 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;
    }
    CmppDeliverRequestMessage requestMessage = new CmppDeliverRequestMessage(msg.getHeader());
    ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
    requestMessage.setMsgId(DefaultMsgIdUtil.bytes2MsgId(toArray(bodyBuffer, CmppDeliverRequest.MSGID.getLength())));
    requestMessage.setDestId(bodyBuffer.readCharSequence(CmppDeliverRequest.DESTID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setServiceid(bodyBuffer.readCharSequence(CmppDeliverRequest.SERVICEID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setTppid(bodyBuffer.readUnsignedByte());
    requestMessage.setTpudhi(bodyBuffer.readUnsignedByte());
    requestMessage.setMsgfmt(new SmsDcs((byte) bodyBuffer.readUnsignedByte()));
    requestMessage.setSrcterminalId(bodyBuffer.readCharSequence(CmppDeliverRequest.SRCTERMINALID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setSrcterminalType(bodyBuffer.readUnsignedByte());
    short registeredDelivery = bodyBuffer.readUnsignedByte();
    int frameLength = (short) (bodyBuffer.readUnsignedByte() & 0xffff);
    if (registeredDelivery == 0) {
        byte[] contentbytes = new byte[frameLength];
        bodyBuffer.readBytes(contentbytes);
        requestMessage.setMsgContentBytes(contentbytes);
        requestMessage.setMsgLength((short) frameLength);
    } else {
        if (frameLength != CmppReportRequest.DESTTERMINALID.getBodyLength()) {
            logger.warn("CmppDeliverRequestMessage - MsgContent length is {}. should be {}.", frameLength, CmppReportRequest.DESTTERMINALID.getBodyLength());
        }
        ;
        requestMessage.setReportRequestMessage(new CmppReportRequestMessage());
        requestMessage.getReportRequestMessage().setMsgId(DefaultMsgIdUtil.bytes2MsgId(toArray(bodyBuffer, CmppReportRequest.MSGID.getLength())));
        requestMessage.getReportRequestMessage().setStat(bodyBuffer.readCharSequence(CmppReportRequest.STAT.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
        requestMessage.getReportRequestMessage().setSubmitTime(bodyBuffer.readCharSequence(CmppReportRequest.SUBMITTIME.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
        requestMessage.getReportRequestMessage().setDoneTime(bodyBuffer.readCharSequence(CmppReportRequest.DONETIME.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
        requestMessage.getReportRequestMessage().setDestterminalId(bodyBuffer.readCharSequence(CmppReportRequest.DESTTERMINALID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
        requestMessage.getReportRequestMessage().setSmscSequence(bodyBuffer.readUnsignedInt());
    }
    // 卓望发送的状态报告 少了11个字节, 剩下的字节全部读取
    requestMessage.setLinkid(bodyBuffer.readCharSequence(bodyBuffer.readableBytes(), GlobalConstance.defaultTransportCharset).toString().trim());
    out.add(requestMessage);
    ReferenceCountUtil.release(bodyBuffer);
}
Also used : CmppDeliverRequestMessage(com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage) CmppReportRequestMessage(com.zx.sms.codec.cmpp.msg.CmppReportRequestMessage) ByteBuf(io.netty.buffer.ByteBuf) SmsDcs(org.marre.sms.SmsDcs)

Example 4 with CmppReportRequestMessage

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

the class Cmpp7FDeliverRequestMessageCodec 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;
    }
    CmppDeliverRequestMessage requestMessage = new CmppDeliverRequestMessage(msg.getHeader());
    ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
    requestMessage.setMsgId(DefaultMsgIdUtil.bytes2MsgId(toArray(bodyBuffer, CmppDeliverRequest.MSGID.getLength())));
    requestMessage.setDestId(bodyBuffer.readCharSequence(CmppDeliverRequest.DESTID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setServiceid(bodyBuffer.readCharSequence(CmppDeliverRequest.SERVICEID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setTppid(bodyBuffer.readUnsignedByte());
    requestMessage.setTpudhi(bodyBuffer.readUnsignedByte());
    requestMessage.setMsgfmt(new SmsDcs((byte) bodyBuffer.readUnsignedByte()));
    requestMessage.setSrcterminalId(bodyBuffer.readCharSequence(CmppDeliverRequest.SRCTERMINALID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setSrcterminalType(bodyBuffer.readUnsignedByte());
    short registeredDelivery = bodyBuffer.readUnsignedByte();
    short frameLength = (short) (bodyBuffer.readUnsignedByte() & 0xffff);
    if (registeredDelivery == 0) {
        byte[] contentbytes = new byte[frameLength];
        bodyBuffer.readBytes(contentbytes);
        requestMessage.setMsgContentBytes(contentbytes);
        requestMessage.setMsgLength((short) frameLength);
    } else {
        requestMessage.setReportRequestMessage(new CmppReportRequestMessage());
        requestMessage.getReportRequestMessage().setMsgId(DefaultMsgIdUtil.bytes2MsgId(toArray(bodyBuffer, CmppReportRequest.MSGID.getLength())));
        requestMessage.getReportRequestMessage().setStat(bodyBuffer.readCharSequence(CmppReportRequest.STAT.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
        requestMessage.getReportRequestMessage().setSubmitTime(bodyBuffer.readCharSequence(CmppReportRequest.SUBMITTIME.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
        requestMessage.getReportRequestMessage().setDoneTime(bodyBuffer.readCharSequence(CmppReportRequest.DONETIME.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
        requestMessage.getReportRequestMessage().setDestterminalId(bodyBuffer.readCharSequence(CmppReportRequest.DESTTERMINALID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
        requestMessage.getReportRequestMessage().setSmscSequence(bodyBuffer.readUnsignedInt());
    }
    requestMessage.setLinkid(bodyBuffer.readCharSequence(CmppDeliverRequest.LINKID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    // 在线公司自定义的字段
    int attach = bodyBuffer.readInt();
    if (attach != 0) {
        byte[] objbytes = new byte[attach];
        bodyBuffer.readBytes(objbytes);
        try {
            requestMessage.setAttachment(FstObjectSerializeUtil.read(objbytes));
        } catch (Exception ex) {
            logger.warn("Attachment decode error", ex);
        }
    }
    out.add(requestMessage);
    ReferenceCountUtil.release(bodyBuffer);
}
Also used : CmppDeliverRequestMessage(com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage) CmppReportRequestMessage(com.zx.sms.codec.cmpp.msg.CmppReportRequestMessage) ByteBuf(io.netty.buffer.ByteBuf) SmsDcs(org.marre.sms.SmsDcs)

Example 5 with CmppReportRequestMessage

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

the class Cmpp20DeliverRequestMessageCodec 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;
    }
    CmppDeliverRequestMessage requestMessage = new CmppDeliverRequestMessage(msg.getHeader());
    ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
    requestMessage.setMsgId(DefaultMsgIdUtil.bytes2MsgId(toArray(bodyBuffer, Cmpp20DeliverRequest.MSGID.getLength())));
    requestMessage.setDestId(bodyBuffer.readCharSequence(Cmpp20DeliverRequest.DESTID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setServiceid(bodyBuffer.readCharSequence(Cmpp20DeliverRequest.SERVICEID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setTppid(bodyBuffer.readUnsignedByte());
    requestMessage.setTpudhi(bodyBuffer.readUnsignedByte());
    requestMessage.setMsgfmt(new SmsDcs((byte) bodyBuffer.readUnsignedByte()));
    requestMessage.setSrcterminalId(bodyBuffer.readCharSequence(Cmpp20DeliverRequest.SRCTERMINALID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    // requestMessage.setSrcterminalType(bodyBuffer.readUnsignedByte());//CMPP2.0
    // SrcterminalType不进行编解码
    short registeredDelivery = bodyBuffer.readUnsignedByte();
    short frameLength = (short) (bodyBuffer.readUnsignedByte() & 0xffff);
    if (registeredDelivery == 0) {
        byte[] contentbytes = new byte[frameLength];
        bodyBuffer.readBytes(contentbytes);
        requestMessage.setMsgContentBytes(contentbytes);
        requestMessage.setMsgLength((short) frameLength);
    } else {
        if (frameLength != Cmpp20ReportRequest.DESTTERMINALID.getBodyLength()) {
            logger.warn("CmppDeliverRequestMessage20 - MsgContent length is {}. should be {}.", frameLength, Cmpp20ReportRequest.DESTTERMINALID.getBodyLength());
        }
        ;
        requestMessage.setReportRequestMessage(new CmppReportRequestMessage());
        requestMessage.getReportRequestMessage().setMsgId(DefaultMsgIdUtil.bytes2MsgId(toArray(bodyBuffer, Cmpp20ReportRequest.MSGID.getLength())));
        requestMessage.getReportRequestMessage().setStat(bodyBuffer.readCharSequence(Cmpp20ReportRequest.STAT.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
        requestMessage.getReportRequestMessage().setSubmitTime(bodyBuffer.readCharSequence(Cmpp20ReportRequest.SUBMITTIME.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
        requestMessage.getReportRequestMessage().setDoneTime(bodyBuffer.readCharSequence(Cmpp20ReportRequest.DONETIME.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
        requestMessage.getReportRequestMessage().setDestterminalId(bodyBuffer.readCharSequence(Cmpp20ReportRequest.DESTTERMINALID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
        requestMessage.getReportRequestMessage().setSmscSequence(bodyBuffer.readUnsignedInt());
    }
    // 剩下的字节全部读取
    requestMessage.setReserved(bodyBuffer.readCharSequence(Cmpp20DeliverRequest.RESERVED.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    ReferenceCountUtil.release(bodyBuffer);
    out.add(requestMessage);
}
Also used : CmppDeliverRequestMessage(com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage) CmppReportRequestMessage(com.zx.sms.codec.cmpp.msg.CmppReportRequestMessage) ByteBuf(io.netty.buffer.ByteBuf) SmsDcs(org.marre.sms.SmsDcs)

Aggregations

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