📄 messagehead.cs
字号:
{
return this._BodyLength;
}
}
public CMPP_DELIVER(byte[] bytes)
{
int i = 0;
byte[] buffer = new byte[Message_Header.Length];
Buffer.BlockCopy(bytes, 0, buffer, 0, Message_Header.Length);
this._Header = new Message_Header(buffer);
//Msg_Id 8
i += Message_Header.Length;
buffer = new byte[8];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
Array.Reverse(buffer);
this._Msg_Id = BitConverter.ToUInt64(buffer, 0);
string s = null;
//Dest_Id 21
i += 8;
buffer = new byte[21];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
s = Encoding.ASCII.GetString(buffer).Trim();
s = s.Substring(0, s.IndexOf('\0'));
this._Dest_Id = s;
//Service_Id 20
i += 21;
buffer = new byte[10];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
s = Encoding.ASCII.GetString(buffer).Trim();
s = s.Substring(0, s.IndexOf('\0'));
this._Service_Id = s;
//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);
s = Encoding.ASCII.GetString(buffer).Trim();
s = s.Substring(0, s.IndexOf('\0'));
this._Src_terminal_Id = s;
//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);
s = Encoding.ASCII.GetString(buffer).Trim();
s = s.Substring(0, s.IndexOf('\0'));
this._LinkID = s;
}
public byte[] ToBytes()
{
//Msg_Length Msg_Content
byte[] buf;
switch (this._Msg_Fmt)
{
case 8:
buf = Encoding.BigEndianUnicode.GetBytes(this._Msg_Content);
break;
case 15: //gb2312
buf = Encoding.GetEncoding("gb2312").GetBytes(this._Msg_Content);
break;
case 0://ascii
case 3://短信写卡操作
case 4://二进制信息
default:
buf = Encoding.ASCII.GetBytes(this._Msg_Content);
break;
}
this._Msg_Length = (uint)buf.Length;
this._BodyLength = FixedBodyLength + (int)this._Msg_Length;
byte[] bytes = new byte[Message_Header.Length + this._BodyLength];
int i = 0;
byte[] buffer = null;
//header 12
this._Header = new Message_Header((uint)(Message_Header.Length + this._BodyLength), CMPP_Command_Id.CMPP_DELIVER, 0);
//Msg_Id 8
i += Message_Header.Length;
buffer = new Byte[8];
buffer = BitConverter.GetBytes(this._Msg_Id);
Array.Reverse(buffer);
Buffer.BlockCopy(buffer, 0, bytes, i, buffer.Length);
//Dest_Id 21
i += 8;
buffer = new byte[21];
buffer = Encoding.ASCII.GetBytes(this._Dest_Id);
Buffer.BlockCopy(buffer, 0, bytes, i, buffer.Length);
//Service_Id 10
i += 21;
buffer = new byte[10];
buffer = Encoding.ASCII.GetBytes(this._Service_Id);
Buffer.BlockCopy(buffer, 0, bytes, i, buffer.Length);
//TP_pid 1
i += 10;
bytes[i++] = (byte)this._TP_pid;
bytes[i++] = (byte)this._TP_udhi;
bytes[i++] = (byte)this._Msg_Fmt;
//Src_terminal_Id 32
buffer = new byte[32];
buffer = Encoding.ASCII.GetBytes(this._Src_terminal_Id);
Buffer.BlockCopy(buffer, 0, bytes, i, buffer.Length);
//Src_terminal_type 1
i += 32;
bytes[i++] = (byte)this._Src_terminal_type;
bytes[i++] = (byte)this._Registered_Delivery;
bytes[i++] = (byte)this._Msg_Length;
//Msg_Content
Buffer.BlockCopy(buf, 0, bytes, i, buf.Length);
//LinkID
i += (int)this._Msg_Length;
return bytes;
}
public override string ToString()
{
return "[\r\n"
+ this._Header.ToString() + "\r\n"
+ string.Format
(
"\tMessageBody:"
+ "\r\n\t\tBodyLength: {0}"
+ "\r\n\t\tDest_Id: {1}"
+ "\r\n\t\tLinkID: {2}"
+ "\r\n\t\tMsg_Content: {3}"
+ "\r\n\t\tMsg_Fmt: {4}"
+ "\r\n\t\tMsg_Id: {5}"
+ "\r\n\t\tMsg_Length: {6}"
+ "\r\n\t\tRegistered_Delivery: {7}"
+ "\r\n\t\tService_Id: {8}"
+ "\r\n\t\tSrc_terminal_Id: {9}"
+ "\r\n\t\tSrc_terminal_type: {10}"
+ "\r\n\t\tTP_pid: {11}"
+ "\r\n\t\tTP_udhi: {12}"
, this._BodyLength
, this._Dest_Id
, this._LinkID
, this._Msg_Content
, this._Msg_Fmt
, this._Msg_Id
, this._Msg_Length
, this._Registered_Delivery
, this._Service_Id
, this._Src_terminal_Id
, this._Src_terminal_type
, this._TP_pid
, this._TP_udhi
)
+ "\r\n]";
}
}
public class CMPP_DELIVER_RESP
{
private Message_Header _Header;
private ulong _Msg_Id;
private uint _Result;
public const int Bodylength = 8 + 4;
public CMPP_DELIVER_RESP(ulong Msg_Id, uint Result)
{
this._Msg_Id = Msg_Id;
this._Result = Result;
}
public byte[] ToBytes()
{
int i = 0;
byte[] bytes = new byte[Message_Header.Length + Bodylength];
byte[] buffer = new byte[Message_Header.Length];
//header
this._Header = new Message_Header(Message_Header.Length + Bodylength, CMPP_Command_Id.CMPP_DELIVER_RESP, 0);
buffer = this._Header.ToBytes();
Buffer.BlockCopy(buffer, 0, bytes, 0, buffer.Length);
i += Message_Header.Length;
//msg_id 8
buffer = BitConverter.GetBytes(this._Msg_Id);
Array.Reverse(buffer);
buffer.CopyTo(bytes, i);
//result 4
i += 8;
buffer = BitConverter.GetBytes(this._Result);
Array.Reverse(buffer);
buffer.CopyTo(bytes, i);
return bytes;
}
public override string ToString()
{
return this._Header.ToString() + "\r\n"
+ string.Format
(
"[\r\nMessageBody:"
+ "\r\n\tMsg_Id: {0}"
+ "\r\n\tResult: {1}"
+ "\r\n]"
, this._Msg_Id
, this._Result
);
}
}
public class CMPP_Msg_Content
{
public const int BodyLength = 8 + 7 + 10 + 10 + 32 + 4;
private uint _Msg_Id;//8 Unsigned Integer 信息标识。SP提交短信(CMPP_SUBMIT)操作时,与SP相连的ISMG产生的Msg_Id。
private string _Stat;//7 Octet7 Octet String 发送短信的应答结果,含义详见表一。SP根据该字段确定CMPP_SUBMIT消息的处理状态。
private string _Submit_time;//10 Octet String YYMMDDHHMM(YY为年的后两位00-99,MM:01-12,DD:01-31,HH:00-23,MM:00-59)。
private string _Done_time;//10 Octet String YYMMDDHHMM。
public CMPP_Msg_Content(byte[] bytes)
{
if (bytes.Length == BodyLength)
{
int i = 0;
//_Msg_Id 8
byte[] buffer = new byte[8];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
Array.Reverse(buffer);
this._Msg_Id = BitConverter.ToUInt32(buffer, 0);
//_Stat 7
i += 8;
buffer = new byte[7];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
this._Stat = Encoding.ASCII.GetString(buffer);
//_Submit_time 10
i += 7;
buffer = new byte[10];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
this._Submit_time = Encoding.ASCII.GetString(buffer);
//_Done_tiem 10
i += 10;
buffer = new byte[10];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
this._Done_time = Encoding.ASCII.GetString(buffer);
//Dest_terminal_Id 32
i += 10;
buffer = new byte[32];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
this._Dest_terminal_Id = Encoding.ASCII.GetString(buffer);
//SMSC_sequence 4
i += 32;
buffer = new byte[4];
Buffer.BlockCopy(bytes,i,buffer,0,buffer.Length);
Array.Reverse(buffer);
this._SMSC_sequence = BitConverter.ToUInt32(buffer, 0);
}
}
public uint Msg_Id
{
get
{
return this._Msg_Id;
}
set
{
this._Msg_Id = value;
}
}
public string Stat
{
get
{
return this._Stat;
}
set
{
this._Stat = value;
}
}
public string Submit_time
{
get
{
return this._Submit_time;
}
set
{
this._Submit_time = value;
}
}
public string Done_time
{
get
{
return this._Done_time;
}
set
{
this._Done_time = value;
}
}
public string Dest_terminal_Id
{
get
{
return this._Dest_terminal_Id;
}
set
{
this._Dest_terminal_Id = value;
}
}
public uint SMSC_sequence
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -