Search in sources :

Example 1 with CmppSubmitRequestMessage

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

the class CmppSubmitRequestMessageCodec 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;
    }
    CmppSubmitRequestMessage requestMessage = new CmppSubmitRequestMessage(msg.getHeader());
    ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
    requestMessage.setMsgid(DefaultMsgIdUtil.bytes2MsgId(toArray(bodyBuffer, CmppSubmitRequest.MSGID.getLength())));
    requestMessage.setPktotal(bodyBuffer.readUnsignedByte());
    requestMessage.setPknumber(bodyBuffer.readUnsignedByte());
    requestMessage.setRegisteredDelivery(bodyBuffer.readUnsignedByte());
    requestMessage.setMsglevel(bodyBuffer.readUnsignedByte());
    requestMessage.setServiceId(bodyBuffer.readCharSequence(CmppSubmitRequest.SERVICEID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setFeeUserType(bodyBuffer.readUnsignedByte());
    requestMessage.setFeeterminalId(bodyBuffer.readCharSequence(CmppSubmitRequest.FEETERMINALID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setFeeterminaltype(bodyBuffer.readUnsignedByte());
    requestMessage.setTppid(bodyBuffer.readUnsignedByte());
    requestMessage.setTpudhi(bodyBuffer.readUnsignedByte());
    requestMessage.setMsgfmt(new SmsDcs((byte) bodyBuffer.readUnsignedByte()));
    requestMessage.setMsgsrc(bodyBuffer.readCharSequence(CmppSubmitRequest.MSGSRC.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setFeeType(bodyBuffer.readCharSequence(CmppSubmitRequest.FEETYPE.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setFeeCode(bodyBuffer.readCharSequence(CmppSubmitRequest.FEECODE.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setValIdTime(bodyBuffer.readCharSequence(CmppSubmitRequest.VALIDTIME.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setAtTime(bodyBuffer.readCharSequence(CmppSubmitRequest.ATTIME.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setSrcId(bodyBuffer.readCharSequence(CmppSubmitRequest.SRCID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    short destUsrtl = bodyBuffer.readUnsignedByte();
    String[] destTermId = new String[destUsrtl];
    for (int i = 0; i < destUsrtl; i++) {
        destTermId[i] = bodyBuffer.readCharSequence(CmppSubmitRequest.DESTTERMINALID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim();
    }
    requestMessage.setDestterminalId(destTermId);
    requestMessage.setDestterminaltype(bodyBuffer.readUnsignedByte());
    short msgLength = (short) (bodyBuffer.readUnsignedByte() & 0xffff);
    byte[] contentbytes = new byte[msgLength];
    bodyBuffer.readBytes(contentbytes);
    requestMessage.setMsgContentBytes(contentbytes);
    requestMessage.setMsgLength((short) msgLength);
    requestMessage.setLinkID(bodyBuffer.readCharSequence(CmppSubmitRequest.LINKID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    out.add(requestMessage);
    ReferenceCountUtil.release(bodyBuffer);
}
Also used : CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage) ByteBuf(io.netty.buffer.ByteBuf) SmsDcs(org.marre.sms.SmsDcs)

Example 2 with CmppSubmitRequestMessage

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

the class TestCmpp20SubmitRequestMessageCodec method testCodec.

@Test
public void testCodec() {
    CmppSubmitRequestMessage msg = new CmppSubmitRequestMessage();
    msg.setDestterminalId(new String[] { "13800138000", "13800138001", "138001380002" });
    msg.setLinkID("0000");
    String content = UUID.randomUUID().toString();
    msg.setMsgContent(content);
    msg.setMsgContent(new SmsTextMessage("你好,我是闪信!", new SmsDcs((byte) 15)));
    msg.setMsgid(new MsgId());
    msg.setServiceId("10086");
    msg.setSrcId("10086");
    ByteBuf buf = encode(msg);
    ByteBuf copybuf = buf.copy();
    int length = buf.readableBytes();
    Assert.assertEquals(length, buf.readInt());
    Assert.assertEquals(msg.getPacketType().getCommandId(), buf.readInt());
    Assert.assertEquals(msg.getHeader().getSequenceId(), buf.readInt());
    CmppSubmitRequestMessage result = decode(copybuf);
    System.out.println(result);
    Assert.assertEquals(msg.getHeader().getSequenceId(), result.getHeader().getSequenceId());
    Assert.assertArrayEquals(msg.getDestterminalId(), result.getDestterminalId());
    Assert.assertEquals(msg.getMsgContent(), result.getMsgContent());
    Assert.assertEquals(msg.getServiceId(), result.getServiceId());
}
Also used : SmsTextMessage(org.marre.sms.SmsTextMessage) CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage) SmsDcs(org.marre.sms.SmsDcs) ByteBuf(io.netty.buffer.ByteBuf) MsgId(com.zx.sms.common.util.MsgId) Test(org.junit.Test)

Example 3 with CmppSubmitRequestMessage

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

the class TestCmpp20SubmitRequestMessageCodec method testlongCodec.

public void testlongCodec(String content) {
    CmppSubmitRequestMessage msg = new CmppSubmitRequestMessage();
    msg.setDestterminalId(new String[] { "13800138000", "13800138001", "138001380002" });
    msg.setLinkID("0000");
    msg.setMsgContent(content);
    msg.setMsgid(new MsgId());
    msg.setServiceId("10086");
    msg.setSrcId("10086");
    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);
    Assert.assertNotNull(result);
    System.out.println(result.getMsgContent());
    Assert.assertEquals(msg.getServiceId(), result.getServiceId());
    Assert.assertArrayEquals(msg.getDestterminalId(), result.getDestterminalId());
    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)

Example 4 with CmppSubmitRequestMessage

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

the class TestCmppSubmitRequestMessageCodec method testGBKMsg.

@Test
public void testGBKMsg() {
    CmppSubmitRequestMessage msg = createTestReq("");
    msg.setMsgContent(new SmsTextMessage("有没有发现,使用模型的表达要清晰易懂很多,而且也不需要做关于组合品的判断了,因为我们在系统中引入了更加贴近现实的对象模型(CombineBackO123456", new SmsDcs((byte) 0x0f)));
    CmppSubmitRequestMessage ret = testWapCodec(msg);
    Assert.assertEquals(msg.getMsgContent(), ret.getMsgContent());
}
Also used : SmsTextMessage(org.marre.sms.SmsTextMessage) CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage) SmsDcs(org.marre.sms.SmsDcs) Test(org.junit.Test)

Example 5 with CmppSubmitRequestMessage

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

the class TestCmppSubmitRequestMessageCodec 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();
    Assert.assertEquals(length, buf.readInt());
    Assert.assertEquals(msg.getPacketType().getCommandId(), buf.readInt());
    Assert.assertEquals(msg.getHeader().getSequenceId(), buf.readInt());
    CmppSubmitRequestMessage result = decode(copybuf);
    Assert.assertEquals(msg.getHeader().getSequenceId(), result.getHeader().getSequenceId());
    Assert.assertEquals(msg.getMsgContent(), result.getMsgContent());
    Assert.assertEquals(msg.getServiceId(), result.getServiceId());
}
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)

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