public CMPP_DELIVER(byte[] bytes) 

int i = 0; 
byte[] buffer = new byte[MessageHeader.Length]; 
Buffer.BlockCopy(bytes, 0, buffer, 0, MessageHeader.Length); 
this._Header = new MessageHeader(buffer);  //Msg_Id 8 
i += MessageHeader.Length; 
buffer = new byte[8]; 
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length); 
Array.Reverse(buffer); 
this._Msg_Id = BitConverter.ToUInt64(buffer, 0);  //Dest_Id 21 
i += 8; 
buffer = new byte[21]; 
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length); 
this._Dest_Id = Encoding.ASCII.GetString(buffer).Trim();  //Service_Id 10 
i += 21; 
buffer = new byte[10]; 
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length); 
this._Service_Id = Encoding.ASCII.GetString(buffer).Trim();  //TP_pid 1 
i += 10; 
this._TP_pid = (uint) bytes[i++]; 
this._TP_udhi = (uint) bytes[i++]; 
this._Msg_Fmt = (uint) bytes[i++];  //Src_terminal_Id 32 
buffer = new byte[32]; 
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length); 
this._Src_terminal_Id = Encoding.ASCII.GetString(buffer).Trim();  //Src_terminal_type 1 
i += 32; 
this._Src_terminal_type = (uint) bytes[i++]; 
this._Registered_Delivery = (uint) bytes[i++]; 
this._Msg_Length = (uint) bytes[i++];  //Msg_Content 
buffer = new byte[this._Msg_Length]; 
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length); 
switch (this._Msg_Fmt) 

case 8: 
this._Msg_Content = Encoding.BigEndianUnicode.GetString(buffer).Trim(); 
break; 
case 15: //gb2312 
this._Msg_Content = Encoding.GetEncoding("gb2312").GetString(buffer).Trim(); 
break; 
case 0: //ascii 
case 3: //短信写卡操作 
case 4: //二进制信息 
default: 
this._Msg_Content = Encoding.ASCII.GetString(buffer).ToString(); 
break; 
}  //Linkid 20 
i += (int) this._Msg_Length; 
buffer = new byte[20]; 
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length); 
this._LinkID = Encoding.ASCII.GetString(buffer).Trim();  }
我用这个构造函数设置各个属性,通过模拟网关下发mt后只得到到Msg_Id,Dest_Id的值。为什么啊怎么改啊?

解决方案 »

  1.   

    /// <summary>
    /// 上行信息包
    /// </summary>
    public class CMPP_MSG_DELIVER
    {
    CMPP_MSG_Header header;
    System.UInt64 _msgid;
    string _destid;
    string _serviceID;
    int _tpid;
    int _udhi;
    int _msgfmt;
    string _srctid;
    bool _isReport;
    int _msglength;
    string _msg; System.UInt64 _reportForMsgid;
    string _reportState;
    string _submitTime;
    string _doneTime;
    string _reportDesttid;
    int _smscSequence; /// <summary>
    /// 上行信息包
    /// </summary>
    /// <param name="bs"></param>
    public CMPP_MSG_DELIVER(byte[] bs)
    {
    header = new MSG.CMPP_MSG_Header(bs);
    int index = MSG.CMPP_MSG_Header.HeaderLength;
    this._msgid = BitConverter.ToUInt64(bs, index);
    index += 8;
    this._destid = Encoding.ASCII.GetString(bs, index, 21);
    index = index + 21;
    this._serviceID = Encoding.ASCII.GetString(bs, index, 10);
    index = index + 10;
    this._tpid = (int)bs[index++];
    this._udhi = (int)bs[index++];
    this._msgfmt = (int)bs[index++];
    this._srctid = Encoding.ASCII.GetString(bs, index, 21);
    index += 21;
    if (bs[index++] == 1)
    {
    this._isReport = true;
    }
    else
    {
    this._isReport = false;
    }
    this._msglength = (int)bs[index++];
    if (!this._isReport)
    {
    switch (this._msgfmt)
    {
    case (int)MSG.Msg_Format.ASCII:
    this._msg = Encoding.ASCII.GetString(bs, index, this._msglength);
    index += this._msglength;
    break;
    case (int)MSG.Msg_Format.BINARY:
    this._msg = Encoding.Default.GetString(bs, index, this._msglength);
    index += this._msglength;
    break; case (int)MSG.Msg_Format.GB2312:
    this._msg = Encoding.Default.GetString(bs, index, this._msglength);
    index += this._msglength;
    break; case (int)MSG.Msg_Format.UCS2:
    this._msg = Encoding.BigEndianUnicode.GetString(bs, index, this._msglength);
    index += this._msglength;
    break; default:
    break;
    }
    }
    else
    {//状态报告
    this._reportForMsgid = BitConverter.ToUInt64(bs, index);
    index += 8;
    this._reportState = BitConverter.ToString(bs, index, 7);
    index += 7;
    this._submitTime = BitConverter.ToString(bs, index, 10);
    index += 10;
    this._doneTime = BitConverter.ToString(bs, index, 10);
    index += 10;
    this._reportDesttid = BitConverter.ToString(bs, index, 21);
    index += 21;
    this._smscSequence = (int)BIConvert.Bytes2UInt(bs, index);
    }
    } /// <summary>
    /// 是否为状态报告
    /// </summary>
    public bool isReport
    {
    get
    {
    return (_isReport);
    }
    } /// <summary>
    /// MSG
    /// </summary>
    public string Msg
    {
    get
    {
    return (this._msg);
    }
    } /// <summary>
    /// 原号码
    /// </summary>
    public string SrcID
    {
    get
    {
    return (this._srctid);
    }
    } /// <summary>
    /// 服务编号
    /// </summary>
    public string SvcCode
    {
    get
    {
    return (this._serviceID);
    }
    } /// <summary>
    /// 手机号码
    /// </summary>
    public string DestID
    {
    get
    {
    return (this._destid);
    }
    } /// <summary>
    /// 给应用程序提供序号
    /// </summary>
    public UInt64 MsgID   
    {
    get
    {
    return (this._msgid);
    }
    } /// <summary>
    /// 状态报告
    /// </summary>
    public string StateReport
    {
    get
    {
    return (this._reportState);
    }
    } /// <summary>
    /// 报告MsgID
    /// </summary>
    public UInt64 ReportMsgID
    {
    get
    {
    return (this._reportForMsgid);
    }
    } /// <summary>
    /// 提交时间
    /// </summary>
    public string SubmitTime
    {
    get
    {
    return (this._submitTime);
    }
    } /// <summary>
    /// 完成时间
    /// </summary>
    public string DoneTime
    {
    get
    {
    return (this._doneTime);
    }
    } /// <summary>
    /// 
    /// </summary>
    public string ReportbyDestID
    {
    get
    {
    return (this._reportDesttid);
    }
    } /// <summary>
    /// SMSC序号
    /// </summary>
    public int SMSCSequence
    {
    get
    {
    return (this._smscSequence);
    }
    } /// <summary>
    /// ISMG序号
    /// </summary>
    public int ISMGSequence
    {
    get
    {
    return ((int)this.header.SequenceId);
    }
    } /// <summary>
    /// 返回deliver包的报告正文长度 
    /// </summary>
    public int MsgBytelen
    {
    get
    {
    return (this._msglength);
    }
    }
    }