📄 sms.cs
字号:
}
}
public uint Status
{
get
{
return _Status;
}
}
public uint Version
{
get
{
return _Version;
}
}
public MessageHeader Header
{
get
{
return _Header;
}
}
public CMPP_CONNECT_RESP(byte[] bytes)
{
//header 12
int i = 0;
byte[] buffer = new byte[MessageHeader.Length];
Buffer.BlockCopy(bytes, 0, buffer, 0, buffer.Length);
_Header = new MessageHeader(buffer);
//status 4
i += MessageHeader.Length;
buffer = new byte[4];
Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
Array.Reverse(buffer);
_Status = BitConverter.ToUInt32(buffer, 0);
//AuthenticatorISMG 16
i += 4;
_AuthenticatorISMG = new byte[16];
Buffer.BlockCopy
(
bytes
, MessageHeader.Length + 4
, _AuthenticatorISMG
, 0
, _AuthenticatorISMG.Length
);
//version
i += 16;
_Version = bytes[i];
}
public override string ToString()
{
return "[\r\n"
+ _Header.ToString() + "\r\n"
+ "\t"
+ string.Format
(
"MessageBody:"
+ "{0}AuthenticatorISMG: {1}"
+ "{0}BodyLength: {2}"
+ "{0}Status: {3}"
+ "{0}Version: {4}"
, "\r\n\t\t"
, Utility.BytesArrayToHexString(_AuthenticatorISMG)
, CMPP_CONNECT_RESP.BodyLength
, _Status
, _Version
)
+ "\r\n]";
}
}
public class CMPP_SUBMIT //: CMPP_Request
{
private int _BodyLength;
//without _Dest_terminal_Id Msg_Content
public const int FixedBodyLength = 8
+ 1
+ 1
+ 1
+ 1
+ 10
+ 1
+ 32
+ 1
+ 1
+ 1
+ 1
+ 6
+ 2
+ 6
+ 17
+ 17
+ 21
+ 1
//+ 32*DestUsr_tl
+ 1
+ 1
//+ Msg_length
+ 20;
private ulong _Msg_Id; // 8 Unsigned Integer 信息标识。
private uint _Pk_total; // 1 Unsigned Integer 相同Msg_Id的信息总条数,从1开始。
private uint _Pk_number; // 1 Unsigned Integer 相同Msg_Id的信息序号,从1开始。
private uint _Registered_Delivery; // 1 Unsigned Integer 是否要求返回状态确认报告:
// 0:不需要;
// 1:需要。
private uint _Msg_level; // 1 Unsigned Integer 信息级别。
private string _Service_Id; // 10 Octet String 业务标识,是数字、字母和符号的组合。
private uint _Fee_UserType; // 1 Unsigned Integer 计费用户类型字段:
// 0:对目的终端MSISDN计费;
// 1:对源终端MSISDN计费;
// 2:对SP计费;
// 3:表示本字段无效,对谁计费参见Fee_terminal_Id字段。
private string _Fee_terminal_Id; // 32 Octet String 被计费用户的号码,当Fee_UserType为3时该值有效,当Fee_UserType为0、1、2时该值无意义。
private uint _Fee_terminal_type; // 1 Unsigned Integer 被计费用户的号码类型,0:真实号码;1:伪码。
private uint _TP_pId; // 1 Unsigned Integer GSM协议类型。详细是解释请参考GSM03.40中的9.2.3.9。
private uint _TP_udhi; // 1 Unsigned Integer GSM协议类型。详细是解释请参考GSM03.40中的9.2.3.23,仅使用1位,右对齐。
private uint _Msg_Fmt; // 1 Unsigned Integer 信息格式:
// 0:ASCII串;
// 3:短信写卡操作;
// 4:二进制信息;
// 8:UCS2编码;
// 15:含GB汉字......
private string _Msg_src; // 6 Octet String 信息内容来源(SP_Id)。
private string _FeeType; // 2 Octet String 资费类别:
// 01:对"计费用户号码"免费;
// 02:对"计费用户号码"按条计信息费;
// 03:对"计费用户号码"按包月收取信息费。
private string _FeeCode; // 6 Octet String 资费代码(以分为单位)。
private string _ValId_Time; // 17 Octet String 存活有效期,格式遵循SMPP3.3协议。
private string _At_Time; // 17 Octet String 定时发送时间,格式遵循SMPP3.3协议。
private string _Src_Id; // 21 Octet String 源号码。SP的服务代码或前缀为服务代码的长号码, 网关将该号码完整的填到SMPP协议Submit_SM消息相应的source_addr字段,该号码最终在用户手机上显示为短消息的主叫号码。
private uint _DestUsr_tl; // 1 Unsigned Integer 接收信息的用户数量(小于100个用户)。
private string[] _Dest_terminal_Id; // 32*DestUsr_tl Octet String 接收短信的MSISDN号码。
private uint _Dest_terminal_type; // 1 Unsigned Integer 接收短信的用户的号码类型,0:真实号码;1:伪码。
private uint _Msg_Length; // 1 Unsigned Integer 信息长度(Msg_Fmt值为0时:<160个字节;其它<=140个字节),取值大于或等于0。
private string _Msg_Content; // Msg_length Octet String 信息内容。
private string _LinkID; // 20 Octet String 点播业务使用的LinkID,非点播类业务的MT流程不使用该字段。
public MessageHeader Header
{
get
{
return _Header;
}
set
{
_Header = value;
}
}
private MessageHeader _Header;
private uint _Sequence_Id;
public CMPP_SUBMIT(uint Sequence_Id)
{
_Sequence_Id = Sequence_Id;
}
private byte[] _Msg_Content_Bytes;
private void SetHeader()
{
//byte[] buf;
switch (_Msg_Fmt)
{
case 8:
_Msg_Content_Bytes = Encoding.BigEndianUnicode.GetBytes(_Msg_Content);
break;
case 15: //gb2312
_Msg_Content_Bytes = Encoding.GetEncoding("gb2312").GetBytes(_Msg_Content);
break;
case 0: //ascii
case 3: //短信写卡操作
case 4: //二进制信息
default:
_Msg_Content_Bytes = Encoding.ASCII.GetBytes(_Msg_Content);
break;
}
_Msg_Length = (uint)_Msg_Content_Bytes.Length;
_BodyLength = (int)(FixedBodyLength + 32 * _Dest_terminal_Id.Length + _Msg_Length);
_Header = new MessageHeader
(
(uint)(MessageHeader.Length + _BodyLength)
, CMPP_Command_Id.CMPP_SUBMIT
, _Sequence_Id
);
}
public byte[] ToBytes()
{
//Msg_Length Msg_Content
int i = 0;
byte[] bytes = new byte[MessageHeader.Length + _BodyLength];
byte[] buffer = _Header.ToBytes();
Buffer.BlockCopy(buffer, 0, bytes, 0, buffer.Length);
i += MessageHeader.Length;
//Msg_Id //8 [12,19]
buffer = new byte[8];
buffer = BitConverter.GetBytes(_Msg_Id);
Array.Reverse(buffer);
Buffer.BlockCopy(buffer, 0, bytes, i, buffer.Length); //10 //[24,33]
//_Pk_total
i += 8;
bytes[i++] = (byte)_Pk_total; //[20,20]
bytes[i++] = (byte)_Pk_number; //[21,21]
bytes[i++] = (byte)_Registered_Delivery; //[22,22]
bytes[i++] = (byte)_Msg_level; //[23,23]
//Service_Id
buffer = Encoding.ASCII.GetBytes(_Service_Id);
Buffer.BlockCopy(buffer, 0, bytes, i, buffer.Length); //10 //[24,33]
//Fee_UserType
i += 10;
bytes[i++] = (byte)_Fee_UserType; //[34,34]
//Fee_terminal_Id
buffer = Encoding.ASCII.GetBytes(_Fee_terminal_Id);
Buffer.BlockCopy(buffer, 0, bytes, i, buffer.Length); //32 //[35,66]
//Fee_terminal_type
i += 32;
bytes[i++] = (byte)_Fee_terminal_type; //[67,67]
bytes[i++] = (byte)_TP_pId; //[68,68]
bytes[i++] = (byte)_TP_udhi; //[69,69]
bytes[i++] = (byte)_Msg_Fmt; //[70,70]
//Msg_src
buffer = Encoding.ASCII.GetBytes(_Msg_src);
Buffer.BlockCopy(buffer, 0, bytes, i, buffer.Length); //6 //[71,76]
//FeeType
i += 6;
buffer = Encoding.ASCII.GetBytes(_FeeType);
Buffer.BlockCopy(buffer, 0, bytes, i, buffer.Length); //2 //[77,78]
//FeeCode
i += 2;
buffer = Encoding.ASCII.GetBytes(_FeeCode);
Buffer.BlockCopy(buffer, 0, bytes, i, buffer.Length); //6 //[79,84]
//ValId_Time
i += 6;
buffer = Encoding.ASCII.GetBytes(_ValId_Time);
Buffer.BlockCopy(buffer, 0, bytes, i, buffer.Length); //17 //[85,101]
//At_Time
i += 17;
buffer = Encoding.ASCII.GetBytes(_At_Time);
Buffer.BlockCopy(buffer, 0, bytes, i, buffer.Length); //17 //[102,118]
//Src_Id
i += 17;
buffer = Encoding.ASCII.GetBytes(_Src_Id);
Buffer.BlockCopy(buffer, 0, bytes, i, buffer.Length); //21 //[119,139]
//DestUsr_tl
i += 21;
_DestUsr_tl = (uint)_Dest_terminal_Id.Length;
bytes[i++] = (byte)_DestUsr_tl; //[140,140]
//Dest_terminal_Id
foreach (string s in _Dest_terminal_Id)
{
buffer = Encoding.ASCII.GetBytes(s);
Buffer.BlockCopy(buffer, 0, bytes, i, buffer.Length);
i += 32;
}
//Dest_terminal_type
bytes[i++] = (byte)_Dest_terminal_type;
//Msg_Length
bytes[i++] = (byte)_Msg_Length;
//Msg_Content
//buffer = Encoding.
Buffer.BlockCopy
(
_Msg_Content_Bytes
, 0
, bytes
, i, _Msg_Content_Bytes.Length
);
//LinkID
i += (int)_Msg_Length;
buffer = Encoding.ASCII.GetBytes(_LinkID);
Buffer.BlockCopy(buffer, 0, bytes, i, buffer.Length); //20
return bytes;
}
public ulong Msg_Id
{
get
{
return _Msg_Id;
}
set
{
_Msg_Id = value;
}
}
public uint Pk_total
{
get
{
return _Pk_total;
}
set
{
_Pk_total = value;
}
}
public uint Pk_number
{
get
{
return _Pk_number;
}
set
{
_Pk_number = value;
}
}
public uint Registered_Delivery
{
get
{
return _Registered_Delivery;
}
set
{
_Registered_Delivery = value;
}
}
public uint Msg_level
{
get
{
return _Msg_level;
}
set
{
_Msg_level = value;
}
}
public string Service_Id
{
get
{
return _Service_Id;
}
set
{
_Service_Id = value;
}
}
public uint Fee_UserType
{
get
{
return _Fee_UserType;
}
set
{
_Fee_UserType = value;
}
}
public string Fee_terminal_Id
{
get
{
return _Fee_terminal_Id;
}
set
{
_Fee_terminal_Id = value;
}
}
public uint Fee_terminal_type
{
get
{
return _Fee_terminal_type;
}
set
{
_Fee_terminal_type = value;
}
}
public uint TP_pId
{
get
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -