Search in sources :

Example 26 with CmppSubmitRequestMessage

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

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

the class CMPPSessionConnectedHandler method createTestReq.

@Override
protected BaseMessage createTestReq(String content) {
    final EndpointEntity finalentity = getEndpointEntity();
    if (finalentity instanceof ServerEndpoint) {
        CmppDeliverRequestMessage msg = new CmppDeliverRequestMessage();
        msg.setDestId(String.valueOf(System.nanoTime()));
        msg.setLinkid("0000");
        msg.setMsgContent(content);
        msg.setMsgId(new MsgId());
        msg.setServiceid("10086");
        msg.setSrcterminalId(String.valueOf(System.nanoTime()));
        msg.setSrcterminalType((short) 1);
        return msg;
    } else {
        CmppSubmitRequestMessage msg = new CmppSubmitRequestMessage();
        msg.setDestterminalId(String.valueOf(System.nanoTime()));
        msg.setSrcId(String.valueOf(System.nanoTime()));
        msg.setLinkID("0000");
        msg.setMsgContent(content);
        msg.setRegisteredDelivery((short) 0);
        msg.setServiceId("10086");
        return msg;
    }
}
Also used : CmppDeliverRequestMessage(com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage) ServerEndpoint(com.zx.sms.connect.manager.ServerEndpoint) CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage) MsgId(com.zx.sms.common.util.MsgId) EndpointEntity(com.zx.sms.connect.manager.EndpointEntity)

Example 28 with CmppSubmitRequestMessage

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

the class TestRemoteWriteCardSubmitMsg method testDecode.

@Test
public void testDecode() throws Exception {
    ByteBuf buf = Unpooled.buffer();
    buf.writeBytes(prepareMsgData());
    ch.writeInbound(buf);
    CmppSubmitRequestMessage submit = (CmppSubmitRequestMessage) ch.readInbound();
    System.out.println(submit);
    byte[] serialdata = FstObjectSerializeUtil.write(submit);
    ch.writeOutbound(FstObjectSerializeUtil.read(serialdata));
    ByteBuf resultni = ch.readOutbound();
    System.out.println(ByteBufUtil.hexDump(resultni));
    Assert.assertArrayEquals(prepareMsgData(), NettyByteBufUtil.toArray(resultni, resultni.readableBytes()));
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage) Test(org.junit.Test)

Example 29 with CmppSubmitRequestMessage

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

the class TestSpeedError method testterminated.

@Test
public void testterminated() throws IOException, ClassNotFoundException, InterruptedException {
    CmppSubmitRequestMessage msg = new CmppSubmitRequestMessage();
    msg.setDestterminalId(new String[] { "13800138000" });
    msg.setLinkID("0000");
    msg.setMsgContent("123asdf23asdgq5");
    msg.setMsgid(new MsgId());
    msg.setServiceId("10086");
    msg.setSrcId("10086");
    // 设置短信的生存时间为2s
    msg.setLifeTime(2);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bos);
    out.writeObject(msg);
    byte[] b = bos.toByteArray();
    Thread.sleep(3000);
    ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(b));
    CmppSubmitRequestMessage result = (CmppSubmitRequestMessage) in.readObject();
    ChannelFuture futurn = ch.writeAndFlush(result);
    // System.out.println(futurn.isSuccess());
    // Thread.sleep(100);
    Assert.assertTrue(!futurn.isSuccess());
    Assert.assertTrue("Msg Life over".equals(futurn.cause().getMessage()));
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage) ObjectOutputStream(java.io.ObjectOutputStream) MsgId(com.zx.sms.common.util.MsgId) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 30 with CmppSubmitRequestMessage

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

the class TestUnkownTypeSubmitMsg method testDecode.

@Test
public void testDecode() throws Exception {
    CmppSubmitRequestMessage submit = new CmppSubmitRequestMessage();
    submit.setDestterminalId("13800138000");
    submit.setTppid((short) 0x7f);
    submit.setMsg(new SmsUnkownTypeMessage((byte) 0xf6, prepareMsgData()));
    ch.writeOutbound(submit);
    ByteBuf resultni = ch.readOutbound();
    System.out.println(ByteBufUtil.hexDump(resultni));
// Assert.assertArrayEquals(prepareMsgData(), NettyByteBufUtil.toArray(resultni, resultni.readableBytes()));
}
Also used : SmsUnkownTypeMessage(org.marre.sms.SmsUnkownTypeMessage) CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

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