Search in sources :

Example 1 with SgipSubmitRequestMessage

use of com.zx.sms.codec.sgip12.msg.SgipSubmitRequestMessage in project SMSGate by Lihuanghe.

the class SgipSubmitRequestMessageCodec 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;
    }
    SgipSubmitRequestMessage requestMessage = new SgipSubmitRequestMessage(msg.getHeader());
    requestMessage.setTimestamp(msg.getTimestamp());
    ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
    requestMessage.setSpnumber(bodyBuffer.readCharSequence(SgipSubmitRequest.SPNUMBER.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setChargenumber(bodyBuffer.readCharSequence(SgipSubmitRequest.CHARGENUMBER.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    int usercount = bodyBuffer.readUnsignedByte();
    String[] nums = new String[usercount];
    for (int i = 0; i < usercount; i++) {
        nums[i] = bodyBuffer.readCharSequence(SgipSubmitRequest.USERNUMBER.getLength(), GlobalConstance.defaultTransportCharset).toString().trim();
    }
    requestMessage.setUsernumber(nums);
    requestMessage.setCorpid(bodyBuffer.readCharSequence(SgipSubmitRequest.CORPID.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setServicetype(bodyBuffer.readCharSequence(SgipSubmitRequest.SERVICETYPE.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setFeetype(bodyBuffer.readUnsignedByte());
    requestMessage.setFeevalue(bodyBuffer.readCharSequence(SgipSubmitRequest.FEEVALUE.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setGivenvalue(bodyBuffer.readCharSequence(SgipSubmitRequest.GIVENVALUE.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setAgentflag(bodyBuffer.readUnsignedByte());
    requestMessage.setMorelatetomtflag(bodyBuffer.readUnsignedByte());
    requestMessage.setPriority(bodyBuffer.readUnsignedByte());
    requestMessage.setExpiretime(bodyBuffer.readCharSequence(SgipSubmitRequest.EXPIRETIME.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setScheduletime(bodyBuffer.readCharSequence(SgipSubmitRequest.SCHEDULETIME.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setReportflag(bodyBuffer.readUnsignedByte());
    requestMessage.setTppid(bodyBuffer.readUnsignedByte());
    requestMessage.setTpudhi(bodyBuffer.readUnsignedByte());
    requestMessage.setMsgfmt(new SmsDcs((byte) bodyBuffer.readUnsignedByte()));
    requestMessage.setMessagetype(bodyBuffer.readUnsignedByte());
    int msgLength = bodyBuffer.readInt();
    byte[] contentbytes = new byte[msgLength];
    bodyBuffer.readBytes(contentbytes);
    requestMessage.setMsgContentBytes(contentbytes);
    requestMessage.setMessagelength(msgLength);
    requestMessage.setReserve(bodyBuffer.readCharSequence(SgipSubmitRequest.RESERVE.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    out.add(requestMessage);
    ReferenceCountUtil.release(bodyBuffer);
}
Also used : SgipSubmitRequestMessage(com.zx.sms.codec.sgip12.msg.SgipSubmitRequestMessage) ByteBuf(io.netty.buffer.ByteBuf) SmsDcs(org.marre.sms.SmsDcs)

Example 2 with SgipSubmitRequestMessage

use of com.zx.sms.codec.sgip12.msg.SgipSubmitRequestMessage 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 SgipSubmitRequestMessage

use of com.zx.sms.codec.sgip12.msg.SgipSubmitRequestMessage 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 SgipSubmitRequestMessage

use of com.zx.sms.codec.sgip12.msg.SgipSubmitRequestMessage in project SMSGate by Lihuanghe.

the class TestSGIPcodec method test.

@Test
public void test() throws DecoderException {
    System.out.println(new SmsDcs((byte) 8).getAlphabet());
    System.out.println(new SequenceNumber());
    ByteBuf buffer = Unpooled.wrappedBuffer(Hex.decodeHex("000000a8000000030000000011f333f26ebb10dd31303635353931323530323800000000000000000000000000000000000000000000000000000000000001383631383635373131383633360000000000000000363131313800000000000000000000020000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000000010000000000000004323333610000000000000000".toCharArray()));
    SgipSubmitRequestMessage msg = decode(buffer);
    Assert.assertNotNull(msg);
    System.out.println(msg);
    Assert.assertEquals("106559125028", msg.getSpnumber());
    Assert.assertEquals("233a", msg.getMsgContent());
}
Also used : SgipSubmitRequestMessage(com.zx.sms.codec.sgip12.msg.SgipSubmitRequestMessage) SequenceNumber(com.zx.sms.common.util.SequenceNumber) SmsDcs(org.marre.sms.SmsDcs) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

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