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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations