use of com.zx.sms.codec.sgip12.msg.SgipDeliverRequestMessage in project SMSGate by Lihuanghe.
the class SgipDeliverRequestMessageCodec method decode.
@Override
protected void decode(ChannelHandlerContext ctx, Message message, List<Object> out) throws Exception {
int commandId = message.getHeader().getCommandId();
if (packetType.getCommandId() != commandId) {
// 不解析,交给下一个codec
out.add(message);
return;
}
ByteBuf bodyBuffer = Unpooled.wrappedBuffer(message.getBodyBuffer());
SgipDeliverRequestMessage requestMessage = new SgipDeliverRequestMessage(message.getHeader());
requestMessage.setTimestamp(message.getTimestamp());
requestMessage.setUsernumber(bodyBuffer.readCharSequence(SgipDeliverRequest.USERNUMBER.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
requestMessage.setSpnumber(bodyBuffer.readCharSequence(SgipDeliverRequest.SPNUMBER.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
requestMessage.setTppid(bodyBuffer.readUnsignedByte());
requestMessage.setTpudhi(bodyBuffer.readUnsignedByte());
requestMessage.setMsgfmt(new SmsDcs((byte) bodyBuffer.readUnsignedByte()));
int frameLength = bodyBuffer.readInt();
byte[] contentbytes = new byte[frameLength];
bodyBuffer.readBytes(contentbytes);
requestMessage.setMsgContentBytes(contentbytes);
requestMessage.setMessagelength(frameLength);
requestMessage.setReserve(bodyBuffer.readCharSequence(SgipDeliverRequest.RESERVE.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
out.add(requestMessage);
ReferenceCountUtil.release(bodyBuffer);
}
use of com.zx.sms.codec.sgip12.msg.SgipDeliverRequestMessage in project SMSGate by Lihuanghe.
the class SGIPMessageReceiveHandler method reponse.
@Override
protected ChannelFuture reponse(final ChannelHandlerContext ctx, Object msg) {
if (msg instanceof SgipDeliverRequestMessage) {
SgipDeliverRequestMessage deli = (SgipDeliverRequestMessage) msg;
SgipDeliverResponseMessage resp = new SgipDeliverResponseMessage(deli.getHeader());
resp.setResult((short) 0);
resp.setTimestamp(deli.getTimestamp());
List<SgipDeliverRequestMessage> deliarr = deli.getFragments();
if (deliarr != null) {
for (SgipDeliverRequestMessage item : deliarr) {
SgipDeliverResponseMessage item_resp = new SgipDeliverResponseMessage(item.getHeader());
item_resp.setResult((short) 0);
item_resp.setTimestamp(item.getTimestamp());
ctx.writeAndFlush(item_resp);
}
}
return ctx.writeAndFlush(resp);
} else if (msg instanceof SgipSubmitRequestMessage) {
SgipSubmitRequestMessage submit = (SgipSubmitRequestMessage) msg;
SgipSubmitResponseMessage resp = new SgipSubmitResponseMessage(submit.getHeader());
resp.setTimestamp(submit.getTimestamp());
resp.setResult((short) 0);
boolean sendreport = 1 == submit.getReportflag();
List<SgipSubmitRequestMessage> deliarr = submit.getFragments();
if (deliarr != null) {
for (SgipSubmitRequestMessage item : deliarr) {
SgipSubmitResponseMessage item_resp = new SgipSubmitResponseMessage(item.getHeader());
item_resp.setResult((short) 0);
item_resp.setTimestamp(item.getTimestamp());
ctx.writeAndFlush(item_resp);
if (sendreport) {
SgipReportRequestMessage report = new SgipReportRequestMessage();
report.setSequenceId(item_resp.getSequenceNumber());
ctx.writeAndFlush(report);
}
}
}
ChannelFuture future = ctx.writeAndFlush(resp);
if (sendreport) {
SgipReportRequestMessage report = new SgipReportRequestMessage();
report.setSequenceId(resp.getSequenceNumber());
ctx.writeAndFlush(report);
}
return future;
}
return null;
}
use of com.zx.sms.codec.sgip12.msg.SgipDeliverRequestMessage in project SMSGate by Lihuanghe.
the class SGIPSessionConnectedHandler method createTestReq.
@Override
protected BaseMessage createTestReq(String content) {
final SgipEndpointEntity finalentity = (SgipEndpointEntity) getEndpointEntity();
String sms = "【费用提醒】尊敬的客户,截止2018年2月1日17时";
if (finalentity instanceof ServerEndpoint) {
SgipDeliverRequestMessage sgipmsg = new SgipDeliverRequestMessage();
sgipmsg.setUsernumber("13800138000");
sgipmsg.setSpnumber("10086");
sgipmsg.setMsgContent(sms);
return sgipmsg;
} else {
SgipSubmitRequestMessage requestMessage = new SgipSubmitRequestMessage();
requestMessage.setSpnumber("10086");
requestMessage.setUsernumber("13800138000");
requestMessage.setMsgContent(sms);
requestMessage.setReportflag((short) 0);
return requestMessage;
}
}
use of com.zx.sms.codec.sgip12.msg.SgipDeliverRequestMessage in project SMSGate by Lihuanghe.
the class SgipDeliverLongMessageHandler method response.
@Override
protected BaseMessage response(SgipDeliverRequestMessage msg) {
// 短信片断未接收完全,直接给网关回复resp,等待其它片断
SgipDeliverResponseMessage responseMessage = new SgipDeliverResponseMessage(msg.getHeader());
responseMessage.setResult((short) 0);
return responseMessage;
}
Aggregations