MAS_长短信

使用移动代理服务器发送长短信
(使用软件包jtp.jar
软件的名称:MAS2.0
软件开发者:神州数码思特奇信息技术股份有限公司
)

问题描述:
按照demo写出发短信程序无问题,
短信内容超过70汉字,发送后服务器无发送成功响应。短信接收不到。

解决过程:
查阅资料,网上大多数在讲CMPP协议,加协议头,拆分。=没有效果。

经过对jar源码的反编译,发现此段代码:

 public static String sendSMS(SUBMIT mt)
    {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        int containCount = Integer.parseInt(config.getDefault_poolNum());
        if(powerFlag.getConnFlag() == 1)
        {
            logger.error("connection was not prepared!");
            return "2";
        }
        if(!judgeFluxSms.judge())
        {
            logger.error("the flux was over stander!");
            return "3";
        }
        if("".equals(mt.getServiceID()) || "0".equals(mt.getServiceID()))
            mt.setServiceID(config.getINTERSERVICEID());
        String msgContent = mt.getMsgContent();
        boolean acsiiFlag = isPureAscii(msgContent);
        int msgLength1 = mt.getMsgContent().length();
        int msgLength = 0;
        try
        {
            msgLength = mt.getMsgContent().getBytes("gbk").length;
        }
        catch(UnsupportedEncodingException e1)
        {
            logger.error(e1);
        }
        mt.head.setSeqno(getSequence1());
        String sendId = (new StringBuilder(String.valueOf(df.format(new Date())))).append((new Integer(mt.head.getSeqno())).toString()).toString();
        mt.setSendId(sendId);
        int normalSmsLen = Integer.parseInt(config.getNormalSmsLen());
        String nullStr = "                                                                                                          ";
        if(msgLength1 > normalSmsLen && msgLength1 < 67)
        {
            mt.setMsgContent((new StringBuilder(String.valueOf(mt.getMsgContent()))).append(nullStr.substring(0, (67 - msgLength1) + 1)).toString());
            msgContent = (new StringBuilder(String.valueOf(mt.getMsgContent()))).append(nullStr.substring(0, (67 - msgLength1) + 1)).toString();
            msgLength1 = mt.getMsgContent().length();
            try
            {
                msgLength = mt.getMsgContent().getBytes("gbk").length;
            }
            catch(UnsupportedEncodingException e1)
            {
                logger.error(e1);
            }
        }
        if(msgLength1 <= normalSmsLen)
        {
            mt.head.commandid = 3;
            mt.setMessageType(0);
            mt.setMsgLength((byte)msgLength);
            mt.setPkTotal((byte)1);
            mt.setPkNumber((byte)1);
            mt.setDestType((byte)0);
            mt.setFeeTerminalType((byte)0);
            mt.setFeeUserType((byte)0);
            mt.setFeeTerminalID(mt.getDestID());
            if(acsiiFlag)
                mt.setMsgFmt((byte)0);
            else
                mt.setMsgFmt((byte)15);
            if(smsPool.getSubmitSize() < containCount && smsPool.getSubmitSavePoolSize() < containCount)
            {
                smsPool.addSUBMIT(mt);
                return mt.getSendId();
            } else
            {
                logger.error("the SubmitPool was full.");
                return "1";
            }
        }
        int configLen = Integer.parseInt(config.getLongSms_Len());
        if(msgLength1 < configLen)
        {
            int total = msgLength1 / 67;
            if(msgLength1 % 67 != 0)
                total++;
            String msgStr[] = new String[total];
            for(int i = 0; i < total; i++)
            {
                int contentLength = i != total - 1 ? 67 : msgLength1 - i * 67;
                msgStr[i] = msgContent.substring(i * 67, i * 67 + contentLength);
            }

            lSmsFlag++;
            if(lSmsFlag == 99)
                lSmsFlag = 0;
            for(int i = 0; i < total; i++)
            {
                SUBMIT smt = new SUBMIT();
                smt.setFlag("1");
                smt.setSrcID(mt.getSrcID());
                smt.setDestID(mt.getDestID());
                smt.setFeeType(mt.getFeeType());
                smt.setFeeCode(mt.getFeeCode());
                smt.setLinkID(mt.getLinkID());
                if(acsiiFlag)
                    mt.setMsgFmt((byte)0);
                else
                    smt.setMsgFmt((byte)8);
                smt.setServiceID(mt.getServiceID());
                smt.head.commandid = 3;
                smt.setMessageType(0);
                smt.setPkTotal((byte)total);
                smt.setPkNumber((byte)(i + 1));
                byte msgHead[] = new byte[6];
                msgHead[0] = 5;
                msgHead[1] = 0;
                msgHead[2] = 3;
                msgHead[3] = (byte)lSmsFlag;
                msgHead[4] = (byte)total;
                msgHead[5] = (byte)(i + 1);
                smt.setLongmsgHead(msgHead);
                smt.setMsgContent(msgStr[i]);
                smt.setMsgLength((byte)(msgStr[i].length() * 2 + 6));
                smt.setDestType((byte)0);
                smt.setFeeTerminalType((byte)0);
                smt.setFeeUserType((byte)0);
                smt.setFeeTerminalID(mt.getDestID());
                if(smsPool.getSubmitSize() > containCount || smsPool.getSubmitSavePoolSize() > containCount)
                    return "1";
                smt.head.setSeqno(getSequence1());
                smt.setSendId(mt.getSendId());
                smsPool.addSUBMIT(smt);
            }

        } else
        {
            return "4";
        }
        return mt.getSendId();
    }


说明在提供的封装程序中已经包含对是否是长短信的支持,只要在对应配置文件中加上或者更改
normalSmsLen的值即可
我参考源码给的值是70,
经过测试可以正常发送长短信。

你可能感兴趣的:(java,mas,长短信)