use of com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage in project SMSGate by Lihuanghe.
the class CMPPResponseSenderHandler method channelRead.
@Override
public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception {
// 此时未经过长短信合并
if (msg instanceof CmppDeliverRequestMessage) {
CmppDeliverRequestMessage e = (CmppDeliverRequestMessage) msg;
CmppDeliverResponseMessage responseMessage = new CmppDeliverResponseMessage(e.getHeader().getSequenceId());
responseMessage.setResult(0);
responseMessage.setMsgId(e.getMsgId());
ctx.channel().writeAndFlush(responseMessage);
} else if (msg instanceof CmppSubmitRequestMessage) {
CmppSubmitRequestMessage e = (CmppSubmitRequestMessage) msg;
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);
ctx.executor().submit(new Runnable() {
public void run() {
ctx.channel().writeAndFlush(deliver);
}
});
}
} else if (msg instanceof CmppQueryRequestMessage) {
CmppQueryRequestMessage e = (CmppQueryRequestMessage) msg;
CmppQueryResponseMessage res = new CmppQueryResponseMessage(e.getHeader().getSequenceId());
ctx.channel().writeAndFlush(res);
}
ctx.fireChannelRead(msg);
}
use of com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage in project SMSGate by Lihuanghe.
the class CMPPSessionConnectedHandler method createTestReq.
@Override
protected BaseMessage createTestReq(String content) {
final EndpointEntity finalentity = getEndpointEntity();
if (finalentity instanceof ServerEndpoint) {
CmppDeliverRequestMessage msg = new CmppDeliverRequestMessage();
msg.setDestId(String.valueOf(System.nanoTime()));
msg.setLinkid("0000");
msg.setMsgContent(content);
msg.setMsgId(new MsgId());
msg.setServiceid("10086");
msg.setSrcterminalId(String.valueOf(System.nanoTime()));
msg.setSrcterminalType((short) 1);
return msg;
} else {
CmppSubmitRequestMessage msg = new CmppSubmitRequestMessage();
msg.setDestterminalId(String.valueOf(System.nanoTime()));
msg.setSrcId(String.valueOf(System.nanoTime()));
msg.setLinkID("0000");
msg.setMsgContent(content);
msg.setRegisteredDelivery((short) 0);
msg.setServiceId("10086");
return msg;
}
}
use of com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage in project SMSGate by Lihuanghe.
the class TestRemoteWriteCardSubmitMsg method testDecode.
@Test
public void testDecode() throws Exception {
ByteBuf buf = Unpooled.buffer();
buf.writeBytes(prepareMsgData());
ch.writeInbound(buf);
CmppSubmitRequestMessage submit = (CmppSubmitRequestMessage) ch.readInbound();
System.out.println(submit);
byte[] serialdata = FstObjectSerializeUtil.write(submit);
ch.writeOutbound(FstObjectSerializeUtil.read(serialdata));
ByteBuf resultni = ch.readOutbound();
System.out.println(ByteBufUtil.hexDump(resultni));
Assert.assertArrayEquals(prepareMsgData(), NettyByteBufUtil.toArray(resultni, resultni.readableBytes()));
}
use of com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage in project SMSGate by Lihuanghe.
the class TestSpeedError method testterminated.
@Test
public void testterminated() throws IOException, ClassNotFoundException, InterruptedException {
CmppSubmitRequestMessage msg = new CmppSubmitRequestMessage();
msg.setDestterminalId(new String[] { "13800138000" });
msg.setLinkID("0000");
msg.setMsgContent("123asdf23asdgq5");
msg.setMsgid(new MsgId());
msg.setServiceId("10086");
msg.setSrcId("10086");
// 设置短信的生存时间为2s
msg.setLifeTime(2);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(msg);
byte[] b = bos.toByteArray();
Thread.sleep(3000);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(b));
CmppSubmitRequestMessage result = (CmppSubmitRequestMessage) in.readObject();
ChannelFuture futurn = ch.writeAndFlush(result);
// System.out.println(futurn.isSuccess());
// Thread.sleep(100);
Assert.assertTrue(!futurn.isSuccess());
Assert.assertTrue("Msg Life over".equals(futurn.cause().getMessage()));
}
use of com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage in project SMSGate by Lihuanghe.
the class TestUnkownTypeSubmitMsg method testDecode.
@Test
public void testDecode() throws Exception {
CmppSubmitRequestMessage submit = new CmppSubmitRequestMessage();
submit.setDestterminalId("13800138000");
submit.setTppid((short) 0x7f);
submit.setMsg(new SmsUnkownTypeMessage((byte) 0xf6, prepareMsgData()));
ch.writeOutbound(submit);
ByteBuf resultni = ch.readOutbound();
System.out.println(ByteBufUtil.hexDump(resultni));
// Assert.assertArrayEquals(prepareMsgData(), NettyByteBufUtil.toArray(resultni, resultni.readableBytes()));
}
Aggregations