namespace AsiaINFO.SMS.CMPP2
|
{
|
using System;
|
using System.Runtime.CompilerServices;
|
using System.Text;
|
|
public class CMPP_SUBMIT
|
{
|
private string _At_Time;
|
private int _BodyLength;
|
private string[] _Dest_terminal_Id;
|
private uint _DestUsr_tl;
|
private string _Fee_terminal_Id;
|
private uint _Fee_UserType;
|
private string _FeeCode;
|
private string _FeeType;
|
private MessageHeader _Header;
|
private string _Msg_Content;
|
private byte[] _Msg_Content_Bytes;
|
private uint _Msg_Fmt;
|
private ulong _Msg_Id;
|
private uint _Msg_Length;
|
private uint _Msg_level;
|
private string _Msg_src;
|
private uint _Pk_number;
|
private uint _Pk_total;
|
private uint _Registered_Delivery;
|
private string _Reserve;
|
private uint _Sequence_Id;
|
private string _Service_Id;
|
private string _Src_Id;
|
private uint _TP_pId;
|
private uint _TP_udhi;
|
private string _ValId_Time;
|
public const int FixedBodyLength = 0x7e;
|
|
public CMPP_SUBMIT(uint Sequence_Id)
|
{
|
this._Sequence_Id = Sequence_Id;
|
}
|
|
private void SetHeader()
|
{
|
if (!string.IsNullOrEmpty(this.WapURL))
|
{
|
this._Msg_Content_Bytes = WapPush.GetInstance().toBytes(this._Msg_Content, this.WapURL);
|
this._Msg_Fmt = 4;
|
this.TP_pId = 1;
|
this.TP_udhi = 1;
|
}
|
else
|
{
|
switch (this._Msg_Fmt)
|
{
|
case 8:
|
this._Msg_Content_Bytes = Encoding.BigEndianUnicode.GetBytes(this._Msg_Content);
|
break;
|
|
case 15:
|
this._Msg_Content_Bytes = Encoding.GetEncoding("gb2312").GetBytes(this._Msg_Content);
|
break;
|
|
default:
|
this._Msg_Content_Bytes = Encoding.ASCII.GetBytes(this._Msg_Content);
|
break;
|
}
|
if (this.Pk_total > 1)
|
{
|
this.TP_udhi = 1;
|
byte[] buffer = new byte[] { 5, 0, 3, 10, (byte) this.Pk_total, (byte) this.Pk_number };
|
byte[] array = new byte[this._Msg_Content_Bytes.Length + 6];
|
int index = 0;
|
buffer.CopyTo(array, index);
|
index += buffer.Length;
|
this._Msg_Content_Bytes.CopyTo(array, index);
|
this._Msg_Content_Bytes = array;
|
}
|
}
|
this._Msg_Length = (uint) this._Msg_Content_Bytes.Length;
|
this._BodyLength = (0x7e + (0x15 * this._Dest_terminal_Id.Length)) + ((int) this._Msg_Length);
|
this._Header = new MessageHeader((uint) (12 + this._BodyLength), CMPP_Command_Id.CMPP_SUBMIT, this._Sequence_Id);
|
}
|
|
public byte[] ToBytes()
|
{
|
int dstOffset = 0;
|
byte[] dst = new byte[12 + this._BodyLength];
|
byte[] src = this._Header.ToBytes();
|
Buffer.BlockCopy(src, 0, dst, 0, src.Length);
|
dstOffset += 12;
|
src = new byte[8];
|
src = BitConverter.GetBytes(this._Msg_Id);
|
Array.Reverse(src);
|
Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
|
dstOffset += 8;
|
dst[dstOffset++] = (byte) this._Pk_total;
|
dst[dstOffset++] = (byte) this._Pk_number;
|
dst[dstOffset++] = (byte) this._Registered_Delivery;
|
dst[dstOffset++] = (byte) this._Msg_level;
|
src = Encoding.ASCII.GetBytes(this._Service_Id);
|
Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
|
dstOffset += 10;
|
dst[dstOffset++] = (byte) this._Fee_UserType;
|
src = Encoding.ASCII.GetBytes(this._Fee_terminal_Id);
|
Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
|
dstOffset += 0x15;
|
dst[dstOffset++] = (byte) this._TP_pId;
|
dst[dstOffset++] = (byte) this._TP_udhi;
|
dst[dstOffset++] = (byte) this._Msg_Fmt;
|
src = Encoding.ASCII.GetBytes(this._Msg_src);
|
Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
|
dstOffset += 6;
|
src = Encoding.ASCII.GetBytes(this._FeeType);
|
Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
|
dstOffset += 2;
|
src = Encoding.ASCII.GetBytes(this._FeeCode);
|
Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
|
dstOffset += 6;
|
src = Encoding.ASCII.GetBytes(this._ValId_Time);
|
Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
|
dstOffset += 0x11;
|
src = Encoding.ASCII.GetBytes(this._At_Time);
|
Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
|
dstOffset += 0x11;
|
src = Encoding.ASCII.GetBytes(this._Src_Id);
|
Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
|
dstOffset += 0x15;
|
this._DestUsr_tl = (uint) this._Dest_terminal_Id.Length;
|
dst[dstOffset++] = (byte) this._DestUsr_tl;
|
foreach (string str in this._Dest_terminal_Id)
|
{
|
src = Encoding.ASCII.GetBytes(str);
|
Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
|
dstOffset += 0x15;
|
}
|
dst[dstOffset++] = (byte) this._Msg_Length;
|
Buffer.BlockCopy(this._Msg_Content_Bytes, 0, dst, dstOffset, this._Msg_Content_Bytes.Length);
|
dstOffset += (int) this._Msg_Length;
|
src = Encoding.ASCII.GetBytes(this._Reserve);
|
Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
|
return dst;
|
}
|
|
public override string ToString()
|
{
|
return ("[\r\n" + this._Header.ToString() + "\r\n" + string.Format("\tMessageBody:\r\n\t\tAt_Time: {0}\r\n\t\tBodyLength: {1}\r\n\t\tDest_terminal_Id: {2}\r\n\t\tDestUsr_tl: {3}\r\n\t\tFee_terminal_Id: {4}\r\n\t\tFee_UserType: {5}\r\n\t\tFeeCode: {6}\r\n\t\tFeeType: {7}\r\n\t\tReserve: {8}\r\n\t\tMsg_Content: {9}\r\n\t\tMsg_Fmt: {10}\r\n\t\tMsg_Id: {11}\r\n\t\tMsg_Length: {12}\r\n\t\tMsg_level: {13}\r\n\t\tMsg_src: {14}\r\n\t\tPk_number: {15}\r\n\t\tPk_total: {16}\r\n\t\tRegistered_Delivery: {17}\r\n\t\tSequence_Id: {18}\r\n\t\tService_Id: {19}\r\n\t\tSrc_Id: {20}\r\n\t\tTP_pId: {21}\r\n\t\tTP_udhi: {22}\r\n\t\tValId_Time: {23}", new object[] {
|
this._At_Time, this._BodyLength, string.Join(",", this._Dest_terminal_Id), this._DestUsr_tl, this._Fee_terminal_Id, this._Fee_UserType, this._FeeCode, this._FeeType, this._Reserve, this._Msg_Content, this._Msg_Fmt, this._Msg_Id, this._Msg_Length, this._Msg_level, this._Msg_src, this._Pk_number,
|
this._Pk_total, this._Registered_Delivery, this._Sequence_Id, this._Service_Id, this._Src_Id, this._TP_pId, this._TP_udhi, this._ValId_Time
|
}) + "\r\n]");
|
}
|
|
public string At_Time
|
{
|
get
|
{
|
return this._At_Time;
|
}
|
set
|
{
|
this._At_Time = value;
|
}
|
}
|
|
public string[] Dest_terminal_Id
|
{
|
get
|
{
|
return this._Dest_terminal_Id;
|
}
|
set
|
{
|
this._Dest_terminal_Id = value;
|
}
|
}
|
|
public uint DestUsr_tl
|
{
|
get
|
{
|
return this._DestUsr_tl;
|
}
|
set
|
{
|
this._DestUsr_tl = value;
|
}
|
}
|
|
public string Fee_terminal_Id
|
{
|
get
|
{
|
return this._Fee_terminal_Id;
|
}
|
set
|
{
|
this._Fee_terminal_Id = value;
|
}
|
}
|
|
public uint Fee_UserType
|
{
|
get
|
{
|
return this._Fee_UserType;
|
}
|
set
|
{
|
this._Fee_UserType = value;
|
}
|
}
|
|
public string FeeCode
|
{
|
get
|
{
|
return this._FeeCode;
|
}
|
set
|
{
|
this._FeeCode = value;
|
}
|
}
|
|
public string FeeType
|
{
|
get
|
{
|
return this._FeeType;
|
}
|
set
|
{
|
this._FeeType = value;
|
}
|
}
|
|
public MessageHeader Header
|
{
|
get
|
{
|
return this._Header;
|
}
|
set
|
{
|
this._Header = value;
|
}
|
}
|
|
public string Msg_Content
|
{
|
get
|
{
|
return this._Msg_Content;
|
}
|
set
|
{
|
this._Msg_Content = value;
|
this.SetHeader();
|
}
|
}
|
|
public uint Msg_Fmt
|
{
|
get
|
{
|
return this._Msg_Fmt;
|
}
|
set
|
{
|
this._Msg_Fmt = value;
|
}
|
}
|
|
public ulong Msg_Id
|
{
|
get
|
{
|
return this._Msg_Id;
|
}
|
set
|
{
|
this._Msg_Id = value;
|
}
|
}
|
|
public uint Msg_Length
|
{
|
get
|
{
|
return this._Msg_Length;
|
}
|
set
|
{
|
this._Msg_Length = value;
|
}
|
}
|
|
public uint Msg_level
|
{
|
get
|
{
|
return this._Msg_level;
|
}
|
set
|
{
|
this._Msg_level = value;
|
}
|
}
|
|
public string Msg_src
|
{
|
get
|
{
|
return this._Msg_src;
|
}
|
set
|
{
|
this._Msg_src = value;
|
}
|
}
|
|
public uint Pk_number
|
{
|
get
|
{
|
return this._Pk_number;
|
}
|
set
|
{
|
this._Pk_number = value;
|
}
|
}
|
|
public uint Pk_total
|
{
|
get
|
{
|
return this._Pk_total;
|
}
|
set
|
{
|
this._Pk_total = value;
|
}
|
}
|
|
public uint Registered_Delivery
|
{
|
get
|
{
|
return this._Registered_Delivery;
|
}
|
set
|
{
|
this._Registered_Delivery = value;
|
}
|
}
|
|
public string Reserve
|
{
|
get
|
{
|
return this._Reserve;
|
}
|
set
|
{
|
this._Reserve = value;
|
}
|
}
|
|
public string Service_Id
|
{
|
get
|
{
|
return this._Service_Id;
|
}
|
set
|
{
|
this._Service_Id = value;
|
}
|
}
|
|
public string Src_Id
|
{
|
get
|
{
|
return this._Src_Id;
|
}
|
set
|
{
|
this._Src_Id = value;
|
}
|
}
|
|
public uint TP_pId
|
{
|
get
|
{
|
return this._TP_pId;
|
}
|
set
|
{
|
this._TP_pId = value;
|
}
|
}
|
|
public uint TP_udhi
|
{
|
get
|
{
|
return this._TP_udhi;
|
}
|
set
|
{
|
this._TP_udhi = value;
|
}
|
}
|
|
public string ValId_Time
|
{
|
get
|
{
|
return this._ValId_Time;
|
}
|
set
|
{
|
this._ValId_Time = value;
|
}
|
}
|
|
public string WapURL { get; set; }
|
}
|
}
|