Search in sources :

Example 1 with SgipDeliverRequestMessage

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);
}
Also used : SgipDeliverRequestMessage(com.zx.sms.codec.sgip12.msg.SgipDeliverRequestMessage) ByteBuf(io.netty.buffer.ByteBuf) SmsDcs(org.marre.sms.SmsDcs)

Example 2 with SgipDeliverRequestMessage

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;
}
Also used : SgipDeliverRequestMessage(com.zx.sms.codec.sgip12.msg.SgipDeliverRequestMessage) ChannelFuture(io.netty.channel.ChannelFuture) SgipReportRequestMessage(com.zx.sms.codec.sgip12.msg.SgipReportRequestMessage) SgipSubmitRequestMessage(com.zx.sms.codec.sgip12.msg.SgipSubmitRequestMessage) SgipSubmitResponseMessage(com.zx.sms.codec.sgip12.msg.SgipSubmitResponseMessage) List(java.util.List) SgipDeliverResponseMessage(com.zx.sms.codec.sgip12.msg.SgipDeliverResponseMessage)

Example 3 with SgipDeliverRequestMessage

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;
    }
}
Also used : SgipDeliverRequestMessage(com.zx.sms.codec.sgip12.msg.SgipDeliverRequestMessage) SgipSubmitRequestMessage(com.zx.sms.codec.sgip12.msg.SgipSubmitRequestMessage) ServerEndpoint(com.zx.sms.connect.manager.ServerEndpoint)

Example 4 with SgipDeliverRequestMessage

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;
}
Also used : SgipDeliverResponseMessage(com.zx.sms.codec.sgip12.msg.SgipDeliverResponseMessage)

Aggregations

SgipDeliverRequestMessage (com.zx.sms.codec.sgip12.msg.SgipDeliverRequestMessage)3 SgipDeliverResponseMessage (com.zx.sms.codec.sgip12.msg.SgipDeliverResponseMessage)2 SgipSubmitRequestMessage (com.zx.sms.codec.sgip12.msg.SgipSubmitRequestMessage)2 SgipReportRequestMessage (com.zx.sms.codec.sgip12.msg.SgipReportRequestMessage)1 SgipSubmitResponseMessage (com.zx.sms.codec.sgip12.msg.SgipSubmitResponseMessage)1 ServerEndpoint (com.zx.sms.connect.manager.ServerEndpoint)1 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelFuture (io.netty.channel.ChannelFuture)1 List (java.util.List)1 SmsDcs (org.marre.sms.SmsDcs)1