📄 messages.cs
字号:
//Msg_Id 8
i += MessageHeader.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;
}
}
class CMPP_DELIVER_RESP : CMPP_Response
{
private MessageHeader _Header;
private UInt32 _Msg_Id;
private uint _Result;
public const int Bodylength = 8 + 1;//4
public CMPP_DELIVER_RESP(UInt32 Msg_Id, uint Result)
{
this._Msg_Id = Msg_Id;
this._Result = Result;
}
public byte[] ToBytes()
{
int i = 0;
byte[] bytes = new byte[MessageHeader.Length + Bodylength];
byte[] buffer = new byte[MessageHeader.Length];
//header
this._Header = new MessageHeader(MessageHeader.Length + Bodylength, CMPP_Command_Id.CMPP_DELIVER_RESP, 0);
buffer = this._Header.ToBytes();
Buffer.BlockCopy(buffer, 0, bytes, 0, buffer.Length);
i += MessageHeader.Length;
//msg_id 8
//for (int n = 0; n <= 7; i++)
//{
// buffer[n] = byte.Parse(Convert.ToString(_Msg_Id.Substring(2 * n, 2)));
//}
buffer = BitConverter.GetBytes(this._Msg_Id);
Array.Reverse(buffer);
buffer.CopyTo(bytes, i);
//result 4
i += 8;
bytes[i] = byte.Parse(this._Result.ToString());
// buffer = BitConverter.GetBytes(this._Result);
// Array.Reverse(buffer);
// buffer.CopyTo(bytes, i);
return bytes;
}
}
class CMPP_Msg_Content //状态报告
{
public const int BodyLength = 8 + 7 + 10 + 10 + 21 + 4;
private UInt32 _Msg_Id; // 8 Unsigned Integer 信息标识。SP提交短信(CMPP_SUBMIT)操作时,与SP相连的ISMG产生的Msg_Id。
private string _Stat; // 7 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);
//string t = string.Empty;
//foreach (byte b in buffer)
//{
// t += Convert.ToString(b, 16).PadLeft(2, '0');
//}
//testCpp2.BIConvert.DumpBytes(buffer, "c:\\CMPP_Msg_Content.txt");
this._Msg_Id = BitConverter.ToUInt32(buffer, 0);// Convert.ToUInt32(t.Substring(0, 16),10);//
//_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_time 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[21];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
this._Dest_terminal_Id = Encoding.ASCII.GetString(buffer);
//SMSC_sequence 4
i += 21;
buffer = new byte[4];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
Array.Reverse(buffer);
this._SMSC_sequence = BitConverter.ToUInt32(buffer, 0);
}
}
public UInt32 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
{
get
{
return this._SMSC_sequence;
}
set
{
this._SMSC_sequence = value;
}
}
private string _Dest_terminal_Id; // 32 Octet String 目的终端MSISDN号码(SP发送CMPP_SUBMIT消息的目标终端)。
private uint _SMSC_sequence; // 4 Unsigned Integer 取自SMSC发送状态报告的消息体中的消息标识。
}
#region CMPP_QUERY
class CMPP_QUERY : CMPP_Request
{
MessageHeader _Header;
string _Time; // 8 Octet String 时间YYYYMMDD(精确至日)。
uint _Query_Type; // 1 Unsigned Integer 查询类别:
// 0:总数查询;
// 1:按业务类型查询。
string _Query_Code; // 10 Octet String 查询码。
// 当Query_Type为0时,此项无效;当Query_Type为1时,此项填写业务类型Service_Id.。
string _Reserve; // 8 Octet String 保留。
public MessageHeader Header
{
get
{
return this._Header;
}
}
public string Time
{
get
{
return this._Time;
}
}
public uint Query_Type
{
get
{
return this._Query_Type;
}
}
public string Query_Code
{
get
{
return this._Query_Code;
}
}
public string Reserve
{
get
{
return this._Reserve;
}
}
public const int BodyLength = 8 + 1 + 10 + 8;
public CMPP_QUERY(System.DateTime Time, uint Query_Type, string Query_Code, string Reserve)
{
this._Time = Util.Get_YYYYMMDD_String(Time);
this._Query_Type = Query_Type;
this._Query_Code = Query_Code;
this._Reserve = Reserve;
}
public byte[] ToBytes()
{
int i = 0;
byte[] bytes = new byte[MessageHeader.Length + BodyLength];
//header
this._Header = new MessageHeader((uint)(MessageHeader.Length + BodyLength), CMPP_Command_Id.CMPP_QUERY, 0);
byte[] buffer = new byte[MessageHeader.Length];
buffer = this._Header.ToBytes();
buffer.CopyTo(bytes, 0);
//Time 8
i += MessageHeader.Length;
buffer = new byte[10];
buffer = Encoding.ASCII.GetBytes(this._Time);
buffer.CopyTo(bytes, i);
//Query_Type 1
i += 8;
bytes[i++] = (byte)this._Query_Type;
//Query_Code 10
buffer = new byte[10];
buffer = Encoding.ASCII.GetBytes(this._Query_Code);
buffer.CopyTo(bytes, i);
//Reserve 8
i += 10;
buffer = new byte[8];
buffer = Encoding.ASCII.GetBytes(this._Reserve);
buffer.CopyTo(bytes, i);
return bytes;
}
}
#endregion
#region CMPP_QUERY_RESP
public class CMPP_QUERY_RESP
{
public MessageHeader Header
{
get
{
return this._Header;
}
}
public string Time
{
get
{
return this._Time;
}
}
public uint Query_Type
{
get
{
return this._Query_Type;
}
}
public string Query_Code
{
get
{
return this._Query_Code;
}
}
public uint Mt_TlMsg
{
get
{
return this._MT_TLMsg;
}
}
public uint Mt_Tlusr
{
get
{
return this._MT_Tlusr;
}
}
public uint Mt_Scs
{
get
{
return this._MT_Scs;
}
}
public uint Mt_Wt
{
get
{
return this._MT_WT;
}
}
public uint Mt_Fl
{
get
{
return this._MT_FL;
}
}
public uint Mo_Scs
{
get
{
return this._MO_Scs;
}
}
public uint Mo_Wt
{
get
{
return this._MO_WT;
}
}
public uint Mo_Fl
{
get
{
return this._MO_FL;
}
}
MessageHeader _Header;
string _Time; // 8 Octet String 时间(精确至日)。
uint _Query_Type; // 1 Unsigned Integer 查询类别:
// 0:总数查询;
// 1:按业务类型查询。
string _Query_Code; // 10 Octet String 查询码。
uint _MT_TLMsg; // 4 Unsigned Integer 从SP接收信息总数。
uint _MT_Tlusr; // 4 Unsigned Integer 从SP接收用户总数。
uint _MT_Scs; // 4 Unsigned Integer 成功转发数量。
uint _MT_WT; // 4 Unsigned Integer 待转发数量。
uint _MT_FL; // 4 Unsigned Integer 转发失败数量。
uint _MO_Scs; // 4 Unsigned Integer 向SP成功送达数量。
uint _MO_WT; // 4 Unsigned Integer 向SP待送达数量。
uint _MO_FL; // 4 Unsigned Integer 向SP送达失败数量。
public const int BodyLength = 8 // Octet String 时间(精确至日)。
+ 1 // Unsigned Integer 查询类别:
// 0:总数查询;
// 1:按业务类型查询。
+ 10 // Octet String 查询码。
+ 4 // Unsigned Integer 从SP接收信息总数。
+ 4 // Unsigned Integer 从SP接收用户总数。
+ 4 // Unsigned Integer 成功转发数量。
+ 4 // Unsigned Integer 待转发数量。
+ 4 // Unsigned Integer 转发失败数量。
+ 4 // Unsigned Integer 向SP成功送达数量。
+ 4 // Unsigned Integer 向SP待送达数量。
+ 4; // Unsigned Integer 向SP送达失败数量。
public CMPP_QUERY_RESP(byte[] bytes)
{
int i = 0;
//header 12
byte[] buffer = new byte[MessageHeader.Length];
Buffer.BlockCopy(bytes, 0, buffer, 0, buffer.Length);
this._Header = new MessageHeader(buffer);
//Time 8
i += MessageHeader.Length;
buffer = new byte[8];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
this._Time = Encoding.ASCII.GetString(buffer);
//Query_Type 1
i += 8;
this._Query_Type = (uint) bytes[i++];
//Query_Code 10
buffer = new byte[10];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
this._Query_Code = Encoding.ASCII.GetString(buffer);
//MT_TLMsg 4
i += 10;
buffer = new byte[4];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
Array.Reverse(buffer);
this._MT_TLMsg = BitConverter.ToUInt32(buffer, 0);
//MT_Tlusr 4
i += 4;
buffer = new byte[4];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
Array.Reverse(buffer);
this._MT_Tlusr = BitConverter.ToUInt32(buffer, 0);
//MT_Scs 4
i += 4;
buffer = new byte[4];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
Array.Reverse(buffer);
this._MT_Scs = BitConverter.ToUInt32(buffer, 0);
//MT_WT 4
i += 4;
buffer = new byte[4];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
Array.Reverse(buffer);
this._MT_WT = BitConverter.ToUInt32(buffer, 0);
//MT_FL 4
i += 4;
buffer = new byte[4];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
Array.Reverse(buffer);
this._MT_FL = BitConverter.ToUInt32(buffer, 0);
//MO_Scs 4
i += 4;
buffer = new byte[4];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
Array.Reverse(buffer);
this._MO_Scs = BitConverter.ToUInt32(buffer, 0);
//MO_WT 4
i += 4;
buffer = new byte[4];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
Array.Reverse(buffer);
this._MO_WT = BitConverter.ToUInt32(buffer, 0);
//MO_FL 4
i += 4;
buffer = new byte[4];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
Array.Reverse(buffer);
this._MO_FL = BitConverter.ToUInt32(buffer, 0);
}
}
#endregion
#region CMPP_ACTIVE_TEST
class CMPP_ACTIVE_TEST
{
MessageHeader _Header;
public MessageHeader Header
{
get
{
return this._Header;
}
}
public CMPP_ACTIVE_TEST()
{
this._Header = new MessageHeader(MessageHeader.Length, CMPP_Command_Id.CMPP_ACTIVE_TEST, 0);
}
public byte[] ToBytes()
{
return this._Header.ToBytes();
}
}
#endregion
#region CMPP_ACTIVE_TEST_RESP
class CMPP_ACTIVE_TEST_RESP
{
MessageHeader _Header;
byte _Reserved;
public byte Reserved
{
get
{
return this._Reserved;
}
}
public MessageHeader Header
{
get
{
return this._Header;
}
}
public CMPP_ACTIVE_TEST_RESP(byte[] bytes)
{
int i = 0;
//header
byte[] buffer = new byte[MessageHeader.Length];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
this._Header = new MessageHeader(buffer);
//Reserved 1
i += MessageHeader.Length;
this._Reserved = bytes[i];
}
public byte[] ToBytes()
{
return this._Header.ToBytes();
}
}
#endregion
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -