use of com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage in project SMSGate by Lihuanghe.
the class Cmpp20SubmitRequestMessageCodec 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, Cmpp20SubmitRequest.MSGID.getLength())));
requestMessage.setPktotal(bodyBuffer.readUnsignedByte());
requestMessage.setPknumber(bodyBuffer.readUnsignedByte());
requestMessage.setRegisteredDelivery(bodyBuffer.readUnsignedByte());
requestMessage.setMsglevel(bodyBuffer.readUnsignedByte());
requestMessage.setServiceId(bodyBuffer.readCharSequence(Cmpp20SubmitRequest.SERVICEID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
requestMessage.setFeeUserType(bodyBuffer.readUnsignedByte());
requestMessage.setFeeterminalId(bodyBuffer.readCharSequence(Cmpp20SubmitRequest.FEETERMINALID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
// requestMessage.setFeeterminaltype(bodyBuffer.readUnsignedByte());//CMPP2.0
// 无该字段 不进行编解码
requestMessage.setTppid(bodyBuffer.readUnsignedByte());
requestMessage.setTpudhi(bodyBuffer.readUnsignedByte());
requestMessage.setMsgfmt(new SmsDcs((byte) bodyBuffer.readUnsignedByte()));
requestMessage.setMsgsrc(bodyBuffer.readCharSequence(Cmpp20SubmitRequest.MSGSRC.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
requestMessage.setFeeType(bodyBuffer.readCharSequence(Cmpp20SubmitRequest.FEETYPE.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
requestMessage.setFeeCode(bodyBuffer.readCharSequence(Cmpp20SubmitRequest.FEECODE.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
requestMessage.setValIdTime(bodyBuffer.readCharSequence(Cmpp20SubmitRequest.VALIDTIME.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
requestMessage.setAtTime(bodyBuffer.readCharSequence(Cmpp20SubmitRequest.ATTIME.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
requestMessage.setSrcId(bodyBuffer.readCharSequence(Cmpp20SubmitRequest.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(Cmpp20SubmitRequest.DESTTERMINALID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim();
}
requestMessage.setDestterminalId(destTermId);
// requestMessage.setDestterminaltype(bodyBuffer.readUnsignedByte());//CMPP2.0
// 无该字段 不进行编解码
short msgLength = (short) (bodyBuffer.readUnsignedByte() & 0xffff);
byte[] contentbytes = new byte[msgLength];
bodyBuffer.readBytes(contentbytes);
requestMessage.setMsgContentBytes(contentbytes);
requestMessage.setMsgLength((short) msgLength);
requestMessage.setReserve(bodyBuffer.readCharSequence(Cmpp20SubmitRequest.RESERVE.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
ReferenceCountUtil.release(bodyBuffer);
out.add(requestMessage);
}
use of com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage in project SMSGate by Lihuanghe.
the class TestSMPP2CMPPSubmitCodec method testPortTextSMSH.
@Test
public void testPortTextSMSH() {
Random rnd_ = new Random();
CmppSubmitRequestMessage msg = createTestReq("");
SmsPortAddressedTextMessage textMsg = new SmsPortAddressedTextMessage(new SmsPort(rnd_.nextInt() & 0xffff, ""), new SmsPort(rnd_.nextInt() & 0xffff, ""), "这是一条端口文本短信");
msg.setMsgContent(textMsg);
CmppSubmitRequestMessage result = testWapCodec(msg);
SmsPortAddressedTextMessage smsmsg = (SmsPortAddressedTextMessage) result.getSmsMessage();
Assert.assertEquals(textMsg.getDestPort_(), smsmsg.getDestPort_());
Assert.assertEquals(textMsg.getOrigPort_(), smsmsg.getOrigPort_());
Assert.assertEquals(textMsg.getText(), smsmsg.getText());
}
use of com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage in project SMSGate by Lihuanghe.
the class TestSMPP2CMPPSubmitCodec method createTestReq.
private CmppSubmitRequestMessage createTestReq(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");
return msg;
}
use of com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage in project SMSGate by Lihuanghe.
the class TestSMPP2CMPPSubmitCodec method testWapCodec.
public CmppSubmitRequestMessage testWapCodec(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);
Assert.assertTrue(result.getSmsMessage() instanceof SmsMessage);
return result;
}
use of com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage in project SMSGate by Lihuanghe.
the class TestSMPP2CMPPSubmitCodec method testMMSPUSH.
@Test
public void testMMSPUSH() {
CmppSubmitRequestMessage msg = createTestReq("");
SmsMmsNotificationMessage mms = new SmsMmsNotificationMessage("https://www.baidu.com/s?wd=SMPPv3.4%20%E9%95%BF%E7%9F%AD%E4%BF%A1&rsv_spt=1&rsv_iqid=0xdd4666100001e74c&issp=1&f=8&rsv_bp=1&rsv_idx=2&ie=utf-8&rqlang=cn&tn=baiduhome_pg&rsv_enter=0&oq=SMPPv%2526lt%253B.4%2520ton%2520npi&rsv_t=50fdNrphqry%2FYfHh29wvp8KzJ9ogqigiPr33FT%2FpcGQu6X34vByQNu4O%2FLNZgIiXdd16&inputT=3203&rsv_pq=d576ead9000016eb&rsv_sug3=60&rsv_sug1=15&rsv_sug7=000&rsv_sug2=0&rsv_sug4=3937&rsv_sug=1", 50 * 1024);
mms.setFrom("10085");
mms.setSubject("这是一条测试彩信,彩信消息ID是:121241");
msg.setMsgContent(mms);
CmppSubmitRequestMessage result = testWapCodec(msg);
SmsMmsNotificationMessage smsmsg = (SmsMmsNotificationMessage) result.getSmsMessage();
Assert.assertEquals(mms.getSubject_(), smsmsg.getSubject_());
Assert.assertEquals(mms.getContentLocation_(), smsmsg.getContentLocation_());
Assert.assertEquals(mms.getFrom_(), smsmsg.getFrom_());
}
Aggregations