Search in sources :

Example 1 with SubmitSm

use of com.zx.sms.codec.smpp.msg.SubmitSm in project SMSGate by Lihuanghe.

the class TestBaseSmCodec method testLongmSubmitSm.

@Test
public void testLongmSubmitSm() {
    SubmitSm pdu = new SubmitSm();
    pdu.setDestAddress(new Address((byte) 0, (byte) 0, "1111"));
    pdu.setSourceAddress(new Address((byte) 0, (byte) 0, "2222"));
    pdu.setSmsMsg("尊敬的客户,您好!您于2016-03-23 14:51:36通过中国移动10085销售专线订购的【一加手机高清防刮保护膜】,请点击支付http://www.10085.cn/web85/page/zyzxpay/wap_order.html?orderId=76DEF9AE1808F506FD4E6CB782E3B8E7EE875E766D3D335C 完成下单。请在60分钟内完成支付,如有疑问,请致电10085咨询,谢谢!中国移动10085");
    testlongCodec(pdu);
}
Also used : SubmitSm(com.zx.sms.codec.smpp.msg.SubmitSm) Test(org.junit.Test)

Example 2 with SubmitSm

use of com.zx.sms.codec.smpp.msg.SubmitSm in project SMSGate by Lihuanghe.

the class SMPPMessageReceiveHandler method reponse.

@Override
protected ChannelFuture reponse(final ChannelHandlerContext ctx, Object msg) {
    if (msg instanceof DeliverSmReceipt) {
        DeliverSmResp res = ((DeliverSm) msg).createResponse();
        res.setMessageId(String.valueOf(System.currentTimeMillis()));
        return ctx.writeAndFlush(res);
    } else if (msg instanceof DeliverSm) {
        DeliverSmResp res = ((DeliverSm) msg).createResponse();
        String msgcontent = ((DeliverSm) msg).getMsgContent();
        res.setMessageId(DigestUtils.md5Hex(msgcontent.getBytes(StandardCharsets.UTF_8)));
        return ctx.writeAndFlush(res);
    } else if (msg instanceof SubmitSm) {
        SubmitSmResp res = ((SubmitSm) msg).createResponse();
        String msgcontent = ((SubmitSm) msg).getMsgContent();
        byte[] receive = msgcontent.getBytes(StandardCharsets.UTF_8);
        res.setMessageId(DigestUtils.md5Hex(receive));
        ChannelFuture future = ctx.writeAndFlush(res);
        List<SubmitSm> frags = ((SubmitSm) msg).getFragments();
        if (frags != null && !frags.isEmpty()) {
            for (SubmitSm fragment : frags) {
                SubmitSmResp fragres = ((SubmitSm) fragment).createResponse();
                res.setMessageId(String.valueOf(System.currentTimeMillis()));
                ctx.writeAndFlush(fragres);
                if (((SubmitSm) msg).getRegisteredDelivery() == 1) {
                    DeliverSmReceipt report = new DeliverSmReceipt();
                    report.setId(String.valueOf(fragment.getSequenceNumber()));
                    report.setSourceAddress(((SubmitSm) msg).getDestAddress());
                    report.setDestAddress(((SubmitSm) msg).getSourceAddress());
                    report.setStat("DELIVRD");
                    report.setText(fragment.getMsgContent());
                    report.setSubmit_date(DateFormatUtils.format(new Date(), "yyMMddHHmm"));
                    report.setDone_date(DateFormatUtils.format(new Date(), "yyMMddHHmm"));
                    ctx.writeAndFlush(report);
                }
            }
        }
        if (((SubmitSm) msg).getRegisteredDelivery() == 1) {
            DeliverSmReceipt report = new DeliverSmReceipt();
            report.setId(String.valueOf(res.getSequenceNumber()));
            report.setSourceAddress(((SubmitSm) msg).getDestAddress());
            report.setDestAddress(((SubmitSm) msg).getSourceAddress());
            report.setStat("DELIVRD");
            report.setText(((SubmitSm) msg).getMsgContent());
            report.setSubmit_date(DateFormatUtils.format(new Date(), "yyMMddHHmm"));
            report.setDone_date(DateFormatUtils.format(new Date(), "yyMMddHHmm"));
            try {
                ChannelUtil.syncWriteLongMsgToEntity(getEndpointEntity(), report);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return future;
    }
    return null;
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) DeliverSmReceipt(com.zx.sms.codec.smpp.msg.DeliverSmReceipt) SubmitSmResp(com.zx.sms.codec.smpp.msg.SubmitSmResp) SubmitSm(com.zx.sms.codec.smpp.msg.SubmitSm) Date(java.util.Date) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DeliverSmResp(com.zx.sms.codec.smpp.msg.DeliverSmResp) DeliverSm(com.zx.sms.codec.smpp.msg.DeliverSm)

Example 3 with SubmitSm

use of com.zx.sms.codec.smpp.msg.SubmitSm in project SMSGate by Lihuanghe.

the class SMPPSessionConnectedHandler method createTestReq.

@Override
protected BaseMessage createTestReq(String str) {
    final EndpointEntity finalentity = getEndpointEntity();
    // String content = "£$¥èéùì@";
    if (finalentity instanceof ServerEndpoint) {
        DeliverSm pdu = new DeliverSm();
        pdu.setSourceAddress(new Address((byte) 0, (byte) 0, "13800138000"));
        pdu.setDestAddress(new Address((byte) 0, (byte) 0, "10086"));
        // pdu.setSmsMsg(new SmsTextMessage(content,SmsDcs.getGeneralDataCodingDcs(SmsAlphabet.GSM,SmsMsgClass.CLASS_UNKNOWN)));
        pdu.setSmsMsg(str);
        return pdu;
    } else {
        SubmitSm pdu = new SubmitSm();
        pdu.setRegisteredDelivery((byte) 0);
        pdu.setSourceAddress(new Address((byte) 0, (byte) 0, "10086"));
        pdu.setDestAddress(new Address((byte) 0, (byte) 0, "13800138000"));
        // pdu.setSmsMsg(new SmsTextMessage(content,SmsDcs.getGeneralDataCodingDcs(SmsAlphabet.GSM,SmsMsgClass.CLASS_UNKNOWN)));
        pdu.setSmsMsg(str);
        return pdu;
    }
}
Also used : Address(com.zx.sms.codec.smpp.Address) SubmitSm(com.zx.sms.codec.smpp.msg.SubmitSm) ServerEndpoint(com.zx.sms.connect.manager.ServerEndpoint) EndpointEntity(com.zx.sms.connect.manager.EndpointEntity) DeliverSm(com.zx.sms.codec.smpp.msg.DeliverSm)

Example 4 with SubmitSm

use of com.zx.sms.codec.smpp.msg.SubmitSm in project SMSGate by Lihuanghe.

the class DefaultPduTranscoder method doDecode.

protected Pdu doDecode(int commandLength, ByteBuf buffer) throws UnrecoverablePduException, RecoverablePduException {
    // skip the length field because we already parsed it
    buffer.skipBytes(SmppConstants.PDU_INT_LENGTH);
    // read the remaining portion of the PDU header
    int commandId = buffer.readInt();
    int commandStatus = buffer.readInt();
    int sequenceNumber = buffer.readInt();
    Pdu pdu = null;
    // any command id with its 31st bit set to true is a response
    if (PduUtil.isRequestCommandId(commandId)) {
        if (commandId == SmppConstants.CMD_ID_ENQUIRE_LINK) {
            pdu = new EnquireLink();
        } else if (commandId == SmppConstants.CMD_ID_DELIVER_SM) {
            pdu = new DeliverSm();
        } else if (commandId == SmppConstants.CMD_ID_SUBMIT_SM) {
            pdu = new SubmitSm();
        } else if (commandId == SmppConstants.CMD_ID_DATA_SM) {
            pdu = new DataSm();
        } else if (commandId == SmppConstants.CMD_ID_CANCEL_SM) {
            pdu = new CancelSm();
        } else if (commandId == SmppConstants.CMD_ID_QUERY_SM) {
            pdu = new QuerySm();
        } else if (commandId == SmppConstants.CMD_ID_REPLACE_SM) {
            pdu = new ReplaceSm();
        } else if (commandId == SmppConstants.CMD_ID_BIND_TRANSCEIVER) {
            pdu = new BindTransceiver();
        } else if (commandId == SmppConstants.CMD_ID_BIND_TRANSMITTER) {
            pdu = new BindTransmitter();
        } else if (commandId == SmppConstants.CMD_ID_BIND_RECEIVER) {
            pdu = new BindReceiver();
        } else if (commandId == SmppConstants.CMD_ID_UNBIND) {
            pdu = new Unbind();
        } else if (commandId == SmppConstants.CMD_ID_ALERT_NOTIFICATION) {
            pdu = new AlertNotification();
        } else {
            pdu = new PartialPdu(commandId);
        }
    } else {
        if (commandId == SmppConstants.CMD_ID_SUBMIT_SM_RESP) {
            pdu = new SubmitSmResp();
        } else if (commandId == SmppConstants.CMD_ID_DELIVER_SM_RESP) {
            pdu = new DeliverSmResp();
        } else if (commandId == SmppConstants.CMD_ID_DATA_SM_RESP) {
            pdu = new DataSmResp();
        } else if (commandId == SmppConstants.CMD_ID_CANCEL_SM_RESP) {
            pdu = new CancelSmResp();
        } else if (commandId == SmppConstants.CMD_ID_QUERY_SM_RESP) {
            pdu = new QuerySmResp();
        } else if (commandId == SmppConstants.CMD_ID_REPLACE_SM_RESP) {
            pdu = new ReplaceSmResp();
        } else if (commandId == SmppConstants.CMD_ID_ENQUIRE_LINK_RESP) {
            pdu = new EnquireLinkResp();
        } else if (commandId == SmppConstants.CMD_ID_BIND_TRANSCEIVER_RESP) {
            pdu = new BindTransceiverResp();
        } else if (commandId == SmppConstants.CMD_ID_BIND_RECEIVER_RESP) {
            pdu = new BindReceiverResp();
        } else if (commandId == SmppConstants.CMD_ID_BIND_TRANSMITTER_RESP) {
            pdu = new BindTransmitterResp();
        } else if (commandId == SmppConstants.CMD_ID_UNBIND_RESP) {
            pdu = new UnbindResp();
        } else if (commandId == SmppConstants.CMD_ID_GENERIC_NACK) {
            pdu = new GenericNack();
        } else {
            pdu = new PartialPduResp(commandId);
        }
    }
    // set pdu header values
    pdu.setCommandLength(commandLength);
    pdu.setCommandStatus(commandStatus);
    pdu.setSequenceNumber(sequenceNumber);
    // check if we need to throw an exception
    if (pdu instanceof PartialPdu) {
        throw new UnknownCommandIdException(pdu, "Unsupported or unknown PDU request commandId [0x" + HexUtil.toHexString(commandId) + "]");
    } else if (pdu instanceof PartialPduResp) {
        throw new UnknownCommandIdException(pdu, "Unsupported or unknown PDU response commandId [0x" + HexUtil.toHexString(commandId) + "]");
    }
    // see if we can map the command status into a message
    if (pdu instanceof PduResponse) {
        PduResponse response = (PduResponse) pdu;
        response.setResultMessage(context.lookupResultMessage(commandStatus));
    }
    try {
        // parse pdu body parameters (may throw exception)
        pdu.readBody(buffer);
        // parse pdu optional parameters (may throw exception)
        pdu.readOptionalParameters(buffer, context);
    } catch (RecoverablePduException e) {
        // check if we should add the partial pdu to the exception
        if (e.getPartialPdu() == null) {
            e.setPartialPdu(pdu);
        }
        // rethrow it
        throw e;
    }
    return pdu;
}
Also used : BindTransceiver(com.zx.sms.codec.smpp.msg.BindTransceiver) BindReceiverResp(com.zx.sms.codec.smpp.msg.BindReceiverResp) GenericNack(com.zx.sms.codec.smpp.msg.GenericNack) PduResponse(com.zx.sms.codec.smpp.msg.PduResponse) ReplaceSm(com.zx.sms.codec.smpp.msg.ReplaceSm) BindTransmitter(com.zx.sms.codec.smpp.msg.BindTransmitter) ReplaceSmResp(com.zx.sms.codec.smpp.msg.ReplaceSmResp) DataSmResp(com.zx.sms.codec.smpp.msg.DataSmResp) PartialPdu(com.zx.sms.codec.smpp.msg.PartialPdu) EnquireLink(com.zx.sms.codec.smpp.msg.EnquireLink) DataSm(com.zx.sms.codec.smpp.msg.DataSm) SubmitSm(com.zx.sms.codec.smpp.msg.SubmitSm) CancelSm(com.zx.sms.codec.smpp.msg.CancelSm) QuerySmResp(com.zx.sms.codec.smpp.msg.QuerySmResp) DeliverSmResp(com.zx.sms.codec.smpp.msg.DeliverSmResp) PartialPdu(com.zx.sms.codec.smpp.msg.PartialPdu) Pdu(com.zx.sms.codec.smpp.msg.Pdu) AlertNotification(com.zx.sms.codec.smpp.msg.AlertNotification) QuerySm(com.zx.sms.codec.smpp.msg.QuerySm) BindReceiver(com.zx.sms.codec.smpp.msg.BindReceiver) EnquireLinkResp(com.zx.sms.codec.smpp.msg.EnquireLinkResp) CancelSmResp(com.zx.sms.codec.smpp.msg.CancelSmResp) BindTransmitterResp(com.zx.sms.codec.smpp.msg.BindTransmitterResp) BindTransceiverResp(com.zx.sms.codec.smpp.msg.BindTransceiverResp) UnbindResp(com.zx.sms.codec.smpp.msg.UnbindResp) SubmitSmResp(com.zx.sms.codec.smpp.msg.SubmitSmResp) PartialPduResp(com.zx.sms.codec.smpp.msg.PartialPduResp) Unbind(com.zx.sms.codec.smpp.msg.Unbind) DeliverSm(com.zx.sms.codec.smpp.msg.DeliverSm)

Example 5 with SubmitSm

use of com.zx.sms.codec.smpp.msg.SubmitSm in project SMSGate by Lihuanghe.

the class TestBaseSmCodec method testASCIIcode.

@Test
public void testASCIIcode() {
    SubmitSm pdu = new SubmitSm();
    pdu.setDestAddress(new Address((byte) 0, (byte) 0, "1111"));
    pdu.setSourceAddress(new Address((byte) 0, (byte) 0, "2222"));
    pdu.setSmsMsg(new SmsTextMessage("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", SmppSmsDcs.getGeneralDataCodingDcs(SmsAlphabet.GSM, SmsMsgClass.CLASS_UNKNOWN)));
    testlongCodec(pdu);
}
Also used : SmsTextMessage(org.marre.sms.SmsTextMessage) SubmitSm(com.zx.sms.codec.smpp.msg.SubmitSm) Test(org.junit.Test)

Aggregations

SubmitSm (com.zx.sms.codec.smpp.msg.SubmitSm)8 Test (org.junit.Test)5 DeliverSm (com.zx.sms.codec.smpp.msg.DeliverSm)3 SmsTextMessage (org.marre.sms.SmsTextMessage)3 DeliverSmResp (com.zx.sms.codec.smpp.msg.DeliverSmResp)2 SubmitSmResp (com.zx.sms.codec.smpp.msg.SubmitSmResp)2 Address (com.zx.sms.codec.smpp.Address)1 AlertNotification (com.zx.sms.codec.smpp.msg.AlertNotification)1 BindReceiver (com.zx.sms.codec.smpp.msg.BindReceiver)1 BindReceiverResp (com.zx.sms.codec.smpp.msg.BindReceiverResp)1 BindTransceiver (com.zx.sms.codec.smpp.msg.BindTransceiver)1 BindTransceiverResp (com.zx.sms.codec.smpp.msg.BindTransceiverResp)1 BindTransmitter (com.zx.sms.codec.smpp.msg.BindTransmitter)1 BindTransmitterResp (com.zx.sms.codec.smpp.msg.BindTransmitterResp)1 CancelSm (com.zx.sms.codec.smpp.msg.CancelSm)1 CancelSmResp (com.zx.sms.codec.smpp.msg.CancelSmResp)1 DataSm (com.zx.sms.codec.smpp.msg.DataSm)1 DataSmResp (com.zx.sms.codec.smpp.msg.DataSmResp)1 DeliverSmReceipt (com.zx.sms.codec.smpp.msg.DeliverSmReceipt)1 EnquireLink (com.zx.sms.codec.smpp.msg.EnquireLink)1