Search in sources :

Example 11 with CmppSubmitRequestMessage

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

the class TestSMPP2CMPPSubmitCodec method testSLPUSH.

@Test
public void testSLPUSH() {
    CmppSubmitRequestMessage msg = createTestReq("");
    WapSLPush sl = new WapSLPush("http://www.baidu.com");
    SmsMessage wap = new SmsWapPushMessage(sl);
    msg.setMsgContent(wap);
    CmppSubmitRequestMessage result = testWapCodec(msg);
    SmsWapPushMessage smsmsg = (SmsWapPushMessage) result.getSmsMessage();
    WapSLPush actsl = (WapSLPush) smsmsg.getWbxml();
    Assert.assertEquals(sl.getUri(), actsl.getUri());
}
Also used : SmsWapPushMessage(org.marre.wap.push.SmsWapPushMessage) SmsMessage(org.marre.sms.SmsMessage) CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage) WapSLPush(org.marre.wap.push.WapSLPush) Test(org.junit.Test)

Example 12 with CmppSubmitRequestMessage

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

the class TestSMPP2CMPPSubmitCodec method testCodec.

@Test
public void testCodec() {
    CmppSubmitRequestMessage msg = new CmppSubmitRequestMessage();
    msg.setDestterminalId(new String[] { "13800138000" });
    msg.setLinkID("0000");
    msg.setMsgContent("123");
    msg.setMsgid(new MsgId());
    msg.setServiceId("10086");
    msg.setSrcId("10086");
    ByteBuf buf = encode(msg);
    ByteBuf copybuf = buf.copy();
    int length = buf.readableBytes();
    CmppSubmitRequestMessage result = decode(copybuf);
    Assert.assertEquals(msg.getHeader().getSequenceId(), result.getHeader().getSequenceId());
    Assert.assertEquals(msg.getMsgContent(), result.getMsgContent());
}
Also used : CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage) ByteBuf(io.netty.buffer.ByteBuf) MsgId(com.zx.sms.common.util.MsgId) Test(org.junit.Test)

Example 13 with CmppSubmitRequestMessage

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

the class TestSMPP2CMPPSubmitCodec method testlongCodec.

public void testlongCodec(CmppSubmitRequestMessage msg) {
    channel().writeOutbound(msg);
    ByteBuf buf = (ByteBuf) channel().readOutbound();
    ByteBuf copybuf = Unpooled.buffer();
    while (buf != null) {
        copybuf.writeBytes(buf.copy());
        int length = buf.readableBytes();
        Assert.assertEquals(length, buf.readInt());
        Assert.assertEquals(msg.getPacketType().getCommandId(), buf.readInt());
        buf = (ByteBuf) channel().readOutbound();
    }
    CmppSubmitRequestMessage result = decode(copybuf);
    System.out.println(result.getMsgContent());
    Assert.assertEquals(msg.getMsgContent(), result.getMsgContent());
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage)

Example 14 with CmppSubmitRequestMessage

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

the class TestSMPP2CMPPSubmitCodec method testSIPUSH.

@Test
public void testSIPUSH() {
    CmppSubmitRequestMessage msg = createTestReq("");
    WapSIPush si = new WapSIPush("http://www.baidu.com", "baidu");
    SmsMessage wap = new SmsWapPushMessage(si);
    msg.setMsgContent(wap);
    CmppSubmitRequestMessage result = testWapCodec(msg);
    SmsWapPushMessage smsmsg = (SmsWapPushMessage) result.getSmsMessage();
    WapSIPush actsi = (WapSIPush) smsmsg.getWbxml();
    Assert.assertEquals(si.getUri(), actsi.getUri());
    Assert.assertEquals(si.getMessage(), actsi.getMessage());
}
Also used : SmsWapPushMessage(org.marre.wap.push.SmsWapPushMessage) SmsMessage(org.marre.sms.SmsMessage) CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage) WapSIPush(org.marre.wap.push.WapSIPush) Test(org.junit.Test)

Example 15 with CmppSubmitRequestMessage

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

Aggregations

CmppSubmitRequestMessage (com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage)39 Test (org.junit.Test)24 ByteBuf (io.netty.buffer.ByteBuf)21 MsgId (com.zx.sms.common.util.MsgId)9 SmsMessage (org.marre.sms.SmsMessage)6 SmsDcs (org.marre.sms.SmsDcs)5 SmsTextMessage (org.marre.sms.SmsTextMessage)4 SmsWapPushMessage (org.marre.wap.push.SmsWapPushMessage)4 CmppDeliverRequestMessage (com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage)3 CmppSubmitResponseMessage (com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage)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 CmppReportRequestMessage (com.zx.sms.codec.cmpp.msg.CmppReportRequestMessage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 HashMap (java.util.HashMap)2 Random (java.util.Random)2