⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shortmsgcmpp.java

📁 sp最新短信API(综合网关)
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package com.wayout.wayoutsp.communication;

import java.io.*;
import java.security.*;


import com.wayout.wayoutsp.publics.*;
/**
 * <p>Title: 公司运营项目</p>
 * <p>Description: 实现短信SP之功能.短信互动系统</p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: wayout</p>
 * @author wayout Software
 * @version 1.01
 */

public class ShortMsgCmpp implements ShortMsg {

    /**
    * Description:构造ShortMsgCmpp,变量初始化
    */
    public ShortMsgCmpp() {
          packetLength = 0;
          /**
          * 消息头
          */
          totalSize=0;                      //消息总长度
          headCmdID=0;                      //消息类型
          headCmdStatus=0x00000000;         //命令状态
          headSeqcNo = 0;                   //消息流水号(可以用来完成消息的确认)
          /**
          * 消息体 请求连接
          */
        submit_msg_id=0;                  //SMGW MsgId
        submit_destusr_tl= 1;             //群发数量
        msgPkTotal   =1;                  //同一消息组中消息总条数
        msgPkNumber =1;                  //同一消息组中消息顺序
        conSourceAddr="";	              //SP ID or MPCU ID
        conAuth = new byte[16] ;          //SP/MPCU认证码 使用MD5算法加密
        conBindType = 1;                  //用户登陆类型
        conVersion = 0;                   //接口版本号
        conTimestamp= 0;                  //login时间戳
        conTimestampBytes = new byte[4];  //login时间戳
        /**
        * 消息体 常规短消息
        */
        lastVersion=0 ;                   //MPCA/MPCU 支持的最高版本号
        repAuth = new byte[16];           //MPCA/MPCU 回应的认证码

        spId=Integer.toString(ComConstants.o_IsmgInfo.spId);                         //SP标志
        spUnionCode= ComConstants.o_IsmgInfo.spCode;
        msgId="";                         //信息标志码
        fwdFlag=0;                        //前转外发标志
        AccessorId=0;                     //短信中心ID
        smscSeqNo=0;                      //本条消息自Smsc发来的流水号
        moMsgId="";                       //MO信息标志码
        msgSpId="";                      //信息内容来源(SP_ID)
        msgSrcAddr="";                    //源终端MSISDN号码(没有可以为空)
        msgDestAddr="";                   //接收业务的MSISDN号码
        msgServiceType="";                //业务类型
        msgFeeType=1;                     //资费类别
        msgInfoFee=0;                     //资费代码(以分为单位)
        msgProtocolId=0;                  //协议标识
        msgMode=1;                        //消息模式,是否要状态报告
        //是否是控制信息,是否SIM卡操作
        msgPriority=1;                    //信息级别
        msgFeeUserType=0;                 //计费用户类型
        msgDataCoding=0;                  //数据编码
        msgDeliverTime="";                //交易请求到达时间
        msgDigest="";                     //数字摘要
        msgLength=0;                      //消息长度(<320个字节)
        msgContent="";                    //消息内容
        msgValidityPeriod="";             //存活有效期,格式遵循SMPP3.4协议
        msgSchedule="";                   //定时发送时间,格式遵循SMPP3...4协议
        msgReserve="Reserve";                    //保留字段
        TlsFlag=0;                        //是否使用TLS协议层
        ackMsgID=0;                       //HexString 短消息ID,当该消息是ACK时有效
        respResult=0;                     //结果
        parseResult=CmppConstants.success;//返回给sp的结果 add by me
        successId=0;                      //成功标识(0:成功;  1:失败)
        /**
         * 消息体 附加备用
         */
        spCode="";                       //SP的服务代码
        spIndex=0;                        //Sp索引序列号
        pushType=0;                       //路由更新类型
        sendCount=0;
        msgLinkId = "0";
    }
    /**
     * 以下是对各个字段的SET GET 方法
     */
     /**
      * ET GET 短消息长度 MsgLength
      * @return int packetLength
      */
    public int getMsgLength() {
        return packetLength;
    }

    /**
     * SET GET 解包结果 ParseResult
     */
    public int  getParseResult() {
        return parseResult;
    }
    /**
     * SET GET 消息命令类型 CommandId
     */
    public int   getCommandId() {
        return headCmdID;
    }
    public boolean  setCommandId(int i) {
        headCmdID=i;
        return true;
    }

    /**
     * SET GET 短消息状态 Command_Status
     */
    public int   getHeadCmdStatus() {
        return headCmdStatus;
    }
    public boolean  setHeadCmdStatus(int i) {
        headCmdStatus=i;
        return true;
    }
    /**
     * SET GET 短消模式 msgMode
     */
    public byte getMsgEsmClass() {
        return msgMode;
    }
    /**
     * GET 短消息编号 MsgId
     */
    public String   getMsgId()   {
        return msgId;
    }
    /**
     * GET 登录连接地址标志码,如SP_Id MPCU_ID
     */
    public String  getConSourceAddr() {
        return conSourceAddr;
    }
    /**
     * Description: 设置登录目的地址及其参数
     *
     * <p><b>处理流程.</b><p>
     * 1 确认MPCU的相关配置       <br>
     * 2 确认MPCA的配置信息       <br>
     * 3login时间戳 从1970-01-01到当前时刻所流逝的秒数
     * 4 MPCU登录到MPCA的共享密码用MD5算法进行加密       <br>
     * 5 写入其他信息,入版本号等       <br>
     * @param  s 要登录的目的地址,如MPCA_ID
     * @return boolean
     * @throws Exception 字符转换异常、空指针异常、未预知异常 <br>
     */
    public boolean  setConSourceAddr(String s) {

       spUnionUserName=s;           //sp在网关中的用户名
       spUnionPasswd=ComConstants.o_IsmgInfo.spPasswd;             //sp在网关中的用密码ComConstants.o_IsmgInfo.shareSecret;
       return true;
    }

    /**
     * SET 设置Sp的服务号码(Cmpp)
     */
    public void setSpCode(String ss) {
        spCode = ss;
    }

    /**
     * GET SET 设置MPCU支持的最高版本(Cmpp)
     */
    public byte     getLastVersion() {
        return lastVersion;
    }
    public boolean  setLastVersion(byte b) {
        lastVersion=b;
        return true;
    }

    /**
     * GET SET 登录返回认证码(Cmpp)
     */
    public byte[]   getRepAuth() {
        return repAuth;
    }
    public boolean  setRepAuth(byte[] b) {
        repAuth=b;
        return true;
    }

    /**
     * GET SET 登录认码(Cmpp)
     */
    public byte[]   getConAuth() {
        return conAuth;
    }
    public boolean  setConAuth(byte[] b) {
        conAuth=b;
        return true;
    }
    /**
     * MPCA返回的Login认证码进行合法性验证,并返回对比结果
     * @return boolean
     * @throws Exception none <br>
     */
    public  boolean  getRepAuthResult() {
        /**
        byte[]  aa;
        aa=Constants.o_MpcaInfo.shareSecret;
        int  len=aa.length;
        len=4+16+len;
        byte[]  bb=new byte[len];
        System.arraycopy(conAuth,0,bb,4,16);
        System.arraycopy(aa,0,bb,20,aa.length);
        byte[] comparStr=computeDigest(bb) ;
        if( CompBytes(comparStr,repAuth)==false ) {
            //    parseResult =CmppConstants.error_attestation;
            //System.out.println(" CmppConstants.error_attestation");
            /**
             * 调试信息
             * if(Constants.CmppPACK_DEBUG==true) {
                System.out.println();
                System.out.println("MPCA login Rep should be: ");
                for(int i=0;i<comparStr.length;i++)
                    System.out.print("["+comparStr[i]+"]");
                System.out.println();
                System.out.print("MPCA login Rep is: ");
                for(int i=0;i<repAuth.length;i++)
                    System.out.print("["+repAuth[i]+"]");
                System.out.println();
              }
            return false;
        } else*/
            return  true ;
    }
    /**
     * GET SET 登录目的系统编号 BindSystermId
     */
    public  String   getBindSysId() {
        return null;
    }
    /**
     * GET SET 登录类型 BindType
     */
    public boolean setBindType(byte i) {
        conBindType=1;
        return true;
    }
    public   byte  getBindType() {
        return  conBindType;
    }

    /**
     *  GET 短信中心编码(SMPP)
     */
    public boolean setAccessorId(int s) {
        return true;
    }

    /**
     *  GET 接收消息的MSISDN号码
     */
    public String   getDestId() {
        return msgSrcAddr;
    }

    /**
     *  GET 消息模式(Cmpp)
     */
    public byte getMsgMode() {
        return msgMode;
    }
    /**
     * 打包,根据当前的命令类型得到相应的数据包
     *
     * <p><b>处理流程.</b><p>
     * 1 建立字节流输出管道  <br>
     * 2 根据命令类型 headCmdID 调用相应的方法  <br>
     * 3 输出字节数组       <br>
     * 判断标志  headCmdID
     * @return byte[] package 打包为字节数组
     * @throws IOException 输入输出异常
     * @throws Exception 未知异常<br>
     */
    public  byte[] getPackage() {
        ByteArrayOutputStream byteArrayOutStream = new ByteArrayOutputStream();
        DataOutputStream dataOutStream = new DataOutputStream(byteArrayOutStream);
        try {
            switch(headCmdID) {
              case CmppConstants.Cmpp_Deliver_Resp:         //前转submit回应
                getDeliverRep(dataOutStream);
                break;
              case CmppConstants.Cmpp_Submit:               //前转下发短信
                recvTimeStamp = PublicFuction.getCurrentTimeForUnionSeq();
                headSeqcNo=ComConstants.getSeqNo();
                getSubmit(dataOutStream);
                break;
              case CmppConstants.Cmpp_Report_Resp:               //前转下发短信
                getReportRep(dataOutStream);
                break;
              case CmppConstants.Cmpp_Login:           //Cmpp_MPCU login请求
                recvTimeStamp = PublicFuction.getCurrentTimeForUnionSeq();
                headSeqcNo=ComConstants.getSeqNo();
                getSpLogin(dataOutStream);
                break;
              case CmppConstants.Cmpp_Login_Resp:           //Cmpp_MPCU login请求
                getHead(dataOutStream,29);
                dataOutStream.writeByte(0);
                writeString(dataOutStream,"",8);
                break;
              case CmppConstants.Cmpp_Logout:          //Cmpp_MPCU Logout请求
                recvTimeStamp = PublicFuction.getCurrentTimeForUnionSeq();
                headSeqcNo=ComConstants.getSeqNo();
                getHead(dataOutStream,20);
                break;
              case CmppConstants.Cmpp_Logout_Resp:          //Cmpp_MPCU Logout请求
                getHead(dataOutStream,20);
                break;
              case CmppConstants.Cmpp_Nack_Resp:
                getHead(dataOutStream,29);                //要预先设置headCmdStatus未知错误应答
                dataOutStream.writeByte(0);
                writeString(dataOutStream,"",8);
                break;
              default:
                System.out.println("ShortMsgCmpp GetPackage can not find the CommandId:"+headCmdID);
            }
            byte[] b = byteArrayOutStream.toByteArray();
            /**
             * 测试信息
             * for(int i=0;i<b.length ;i++)
            System.out.print(" "+b[i]);
            System.out.println("  " ) ;*/
            return  b;
        } catch(Exception e) {
            System.out.println("mpcu.ShortMsgCmpp GetPackage Thrown Exception"+e);
            return  "Erro".getBytes();
        }

    }

    /**
     * 解包,根据当前的命令类型得到相应ShortMsgCmpp实例

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -