use of com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage in project SMSGate by Lihuanghe.
the class TestSMPP2CMPPSubmitCodec method testSLPUSH.
@Test
public void testSLPUSH() {
CmppSubmitRequestMessage msg = createTestReq("");
WapSLPush sl = new WapSLPush("http://www.baidu.com");
SmsMessage wap = new SmsWapPushMessage(sl);
msg.setMsgContent(wap);
CmppSubmitRequestMessage result = testWapCodec(msg);
SmsWapPushMessage smsmsg = (SmsWapPushMessage) result.getSmsMessage();
WapSLPush actsl = (WapSLPush) smsmsg.getWbxml();
Assert.assertEquals(sl.getUri(), actsl.getUri());
}
use of com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage 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());
}
use of com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage in project SMSGate by Lihuanghe.
the class TestSMPP2CMPPSubmitCodec method testlongCodec.
public void testlongCodec(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.getMsgContent());
Assert.assertEquals(msg.getMsgContent(), result.getMsgContent());
}
use of com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage in project SMSGate by Lihuanghe.
the class TestSMPP2CMPPSubmitCodec method testSIPUSH.
@Test
public void testSIPUSH() {
CmppSubmitRequestMessage msg = createTestReq("");
WapSIPush si = new WapSIPush("http://www.baidu.com", "baidu");
SmsMessage wap = new SmsWapPushMessage(si);
msg.setMsgContent(wap);
CmppSubmitRequestMessage result = testWapCodec(msg);
SmsWapPushMessage smsmsg = (SmsWapPushMessage) result.getSmsMessage();
WapSIPush actsi = (WapSIPush) smsmsg.getWbxml();
Assert.assertEquals(si.getUri(), actsi.getUri());
Assert.assertEquals(si.getMessage(), actsi.getMessage());
}
use of com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage in project SMSGate by Lihuanghe.
the class CMPPSessionConnectedHandler method channelRead.
public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof CmppDeliverRequestMessage) {
CmppDeliverRequestMessage e = (CmppDeliverRequestMessage) msg;
if (e.getFragments() != null) {
// 长短信会带有片断
for (CmppDeliverRequestMessage frag : e.getFragments()) {
CmppDeliverResponseMessage responseMessage = new CmppDeliverResponseMessage(frag.getHeader().getSequenceId());
responseMessage.setResult(0);
responseMessage.setMsgId(frag.getMsgId());
ctx.channel().write(responseMessage);
}
}
CmppDeliverResponseMessage responseMessage = new CmppDeliverResponseMessage(e.getHeader().getSequenceId());
responseMessage.setResult(0);
responseMessage.setMsgId(e.getMsgId());
ctx.channel().writeAndFlush(responseMessage);
} else if (msg instanceof CmppDeliverResponseMessage) {
CmppDeliverResponseMessage e = (CmppDeliverResponseMessage) msg;
} else if (msg instanceof CmppSubmitRequestMessage) {
// 接收到 CmppSubmitRequestMessage 消息
CmppSubmitRequestMessage e = (CmppSubmitRequestMessage) msg;
final List<CmppDeliverRequestMessage> reportlist = new ArrayList<CmppDeliverRequestMessage>();
if (e.getFragments() != null) {
// 长短信会可能带有片断,每个片断都要回复一个response
for (CmppSubmitRequestMessage frag : e.getFragments()) {
CmppSubmitResponseMessage responseMessage = new CmppSubmitResponseMessage(frag.getHeader().getSequenceId());
responseMessage.setResult(0);
ctx.channel().write(responseMessage);
CmppDeliverRequestMessage deliver = new CmppDeliverRequestMessage();
deliver.setDestId(e.getSrcId());
deliver.setSrcterminalId(e.getDestterminalId()[0]);
CmppReportRequestMessage report = new CmppReportRequestMessage();
report.setDestterminalId(deliver.getSrcterminalId());
report.setMsgId(responseMessage.getMsgId());
String t = DateFormatUtils.format(CachedMillisecondClock.INS.now(), "yyMMddHHmm");
report.setSubmitTime(t);
report.setDoneTime(t);
report.setStat("DELIVRD");
report.setSmscSequence(0);
deliver.setReportRequestMessage(report);
reportlist.add(deliver);
}
}
final 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);
reportlist.add(deliver);
ctx.executor().submit(new Runnable() {
public void run() {
for (CmppDeliverRequestMessage t : reportlist) ctx.channel().writeAndFlush(t);
}
});
}
} else if (msg instanceof CmppSubmitResponseMessage) {
CmppSubmitResponseMessage e = (CmppSubmitResponseMessage) msg;
} else if (msg instanceof CmppQueryRequestMessage) {
CmppQueryRequestMessage e = (CmppQueryRequestMessage) msg;
CmppQueryResponseMessage res = new CmppQueryResponseMessage(e.getHeader().getSequenceId());
ctx.channel().writeAndFlush(res);
} else {
ctx.fireChannelRead(msg);
}
}
Aggregations