Search in sources :

Example 11 with MsgId

use of com.zx.sms.common.util.MsgId in project SMSGate by Lihuanghe.

the class TestSMPP2CMPPDeliverCodec method createTestReq.

private CmppDeliverRequestMessage createTestReq(String content) {
    Header header = new DefaultHeader();
    // 取时间,用来查看编码解码时间
    CmppDeliverRequestMessage msg = new CmppDeliverRequestMessage(header);
    msg.setDestId("13800138000");
    msg.setLinkid("0000");
    // 70个汉字
    msg.setMsgContent(content);
    msg.setMsgId(new MsgId());
    msg.setServiceid("10086");
    msg.setSrcterminalId("13800138000");
    msg.setSrcterminalType((short) 1);
    header.setSequenceId((int) System.nanoTime());
    return msg;
}
Also used : CmppDeliverRequestMessage(com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage) DefaultHeader(com.zx.sms.codec.cmpp.msg.DefaultHeader) Header(com.zx.sms.codec.cmpp.msg.Header) DefaultHeader(com.zx.sms.codec.cmpp.msg.DefaultHeader) MsgId(com.zx.sms.common.util.MsgId)

Example 12 with MsgId

use of com.zx.sms.common.util.MsgId 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 MsgId

use of com.zx.sms.common.util.MsgId in project SMSGate by Lihuanghe.

the class TestMsgId method testmsgid.

@Test
public void testmsgid() throws DecoderException, UnsupportedEncodingException {
    // 迈远格式的msgId与标准格式互转
    String maiyunMsgid = "9BD88980F32D1C3E";
    // String maiyunMsgid = "53265100001FA118";
    MsgId msgid = DefaultMsgIdUtil.bytes2MsgId(Hex.decodeHex(maiyunMsgid.toCharArray()));
    System.out.println(msgid);
    Assert.assertEquals(maiyunMsgid, msgid.toHexString(false));
    System.out.println(Hex.encodeHex(SmsPduUtil.getSeptets("Hello world")));
}
Also used : MsgId(com.zx.sms.common.util.MsgId) Test(org.junit.Test)

Example 14 with MsgId

use of com.zx.sms.common.util.MsgId in project SMSGate by Lihuanghe.

the class TestMsgId method testperformance.

@Test
public void testperformance() {
    System.out.println(new MsgId());
    long start = System.currentTimeMillis();
    for (int i = 0; i < 1000000; i++) {
        new MsgId().toString();
    }
    long end = System.currentTimeMillis();
    System.out.println(end - start);
}
Also used : MsgId(com.zx.sms.common.util.MsgId) Test(org.junit.Test)

Example 15 with MsgId

use of com.zx.sms.common.util.MsgId in project SMSGate by Lihuanghe.

the class TestMsgCmppSubmit7FDecoder method testlongCodec.

public void testlongCodec(String content) {
    CmppSubmitRequestMessage msg = new CmppSubmitRequestMessage();
    msg.setDestterminalId(new String[] { "13800138000" });
    msg.setLinkID("0000");
    msg.setMsgContent(content);
    msg.setMsgid(new MsgId());
    msg.setServiceId("10086");
    msg.setSrcId("10086");
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("a", 1);
    map.put("b", "adf");
    msg.setAttachment((Serializable) map);
    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.getServiceId(), result.getServiceId());
    Assert.assertEquals(msg.getMsgContent(), result.getMsgContent());
    Assert.assertTrue(result.getAttachment() instanceof Map);
    Map retmap = (Map) result.getAttachment();
    Assert.assertEquals("adf", retmap.get("b"));
}
Also used : HashMap(java.util.HashMap) CmppSubmitRequestMessage(com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage) ByteBuf(io.netty.buffer.ByteBuf) Map(java.util.Map) HashMap(java.util.HashMap) MsgId(com.zx.sms.common.util.MsgId)

Aggregations

MsgId (com.zx.sms.common.util.MsgId)23 Test (org.junit.Test)14 ByteBuf (io.netty.buffer.ByteBuf)10 CmppSubmitRequestMessage (com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage)9 CmppDeliverRequestMessage (com.zx.sms.codec.cmpp.msg.CmppDeliverRequestMessage)7 CmppReportRequestMessage (com.zx.sms.codec.cmpp.msg.CmppReportRequestMessage)3 CmppSubmitResponseMessage (com.zx.sms.codec.cmpp.msg.CmppSubmitResponseMessage)3 DefaultHeader (com.zx.sms.codec.cmpp.msg.DefaultHeader)3 Header (com.zx.sms.codec.cmpp.msg.Header)3 CmppDeliverResponseMessage (com.zx.sms.codec.cmpp.msg.CmppDeliverResponseMessage)2 CmppCancelRequestMessage (com.zx.sms.codec.cmpp.msg.CmppCancelRequestMessage)1 SMGPSubmitMessage (com.zx.sms.codec.smgp.msg.SMGPSubmitMessage)1 EndpointEntity (com.zx.sms.connect.manager.EndpointEntity)1 ServerEndpoint (com.zx.sms.connect.manager.ServerEndpoint)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 HashMap (java.util.HashMap)1