版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、亿阳超长信息发布软件V1.0 源代码60-1using System;using System.Collections.Generic;using System.Text;using System.Security.Cryptography;namespace CMPP.API.MT#region CMPP 消息类定义 C# namespace MSG#region 枚举类型public enum CMPP_COMMAND_ID : uintCMPP_CONNECT = 1, CMPP_CONNECT_RESP = 0x80000001,CMPP_TERMINATE = 0x00000002,
2、 / 终止连接CMPP_TERMINATE_RESP = 0x80000002, / 终止连接应答CMPP_SUBMIT = 0x00000004,/提交CMPP_SUBMIT_RESP = 0x80000004,/ 提交下发/ 下发状态应答CMPP_DELIVER = 0x00000005,/CMPP_DELIVER_RESP = 0x80000005, CMPP_QUERY = 0x00000006, / CMPP_QUERY_RESP = 0x80000006, /CMPP_CANCEL = 0x00000007, / 删除应答状态应答CMPP_CANCEL_RESP = 0x80000
3、007, / 删除CMPP_ACTIVE_TEST = 0x00000008, /激活测试应答CMPP_ACTIVE_TEST_RESP = 0x80000008 / 激活测试应答public enum FeeUserTypeFEE_TERMINAL_ID = 0,FEE_SOURCE_ID = 1,FEE_SP = 2,FEE_NULL = 3public enum Msg_FormatASCII = 0,WRITECARD = 1,BINARY = 4,UCS2 = 8,GB2312 = 15public enum SUBMIT_RESULTSUCC = 0,/MSG_STRUCTURE_
4、ERR = 1,COMMANID_ERR = 2,MSG_SEQUENCE_ERR = 3,MSG_LENGTH_ERR = 4,亿阳超长信息发布软件V1.0 源代码60-2FEE_CODE_ERR = 5,OUT_OF_MSG_LEN_ERR = 6,SVC_CODE_ERR = 7,FLUX_ERR = 8,OTHER_ERR = 9#endregion#region 结构定义public struct FeeTypepublic static readonly string FEE_TERMINAL_FREE = "01" public static readonly
5、 string FEE_TERMINAL_PERITEM = "02" public static readonly string FEE_TERMINAL_MONTH = "03" public static readonly string FEE_TERMINAL_TOP = "04" public static readonly string FEE_TERMINAL_SP = "05"public struct DELIVER_STATEpublic static readonly string DELIV
6、ERED = "DELIVRD" public static readonly string EXPIRED = "EXPIRED" public static readonly string DELETED = "DELETED"public static readonly string UNDELIVERABLE = "UNDELIV" public static readonly string ACCEPTED = "ACCEPTD"public static readonly strin
7、g UNKNOWN = "UNKNOWN" public static readonly string REJECTED = "REJECTD"#endregionpublic class CMPP_MSG_Header /消息头private byte initValue = new byteMSG.CMPP_MSG_Header.HeaderLength;public CMPP_MSG_Header(CMPP_COMMAND_ID Command_ID) /BIConvert.Int2Bytes(uint)Command_ID).CopyTo(ini
8、tValue, 4);前public CMPP_MSG_Header(byte bs) /根据受到的字节进行构造 字节序列int l = MSG.CMPP_MSG_Header.HeaderLength; for (int i = 0; i < l; i+)initValuei = bsi;public CMPP_MSG_Header(byte bs, int baseIndex) /根据受到的字节进行构造 字节序列int l = MSG.CMPP_MSG_Header.HeaderLength;亿阳超长信息发布软件V1.0 源代码60-3for (int i = 0; i < l
9、; i+)initValuei = bsbaseIndex + i;public uint MSGLength /获取此消息头代表的消息的整个长度getreturn (BIConvert.Bytes2UInt(initValue, 0);setbyte t = BIConvert.Int2Bytes(value); for (int i = 0; i < 4; i+)initValuei = ti;public uint Command_IDgetreturn (BIConvert.Bytes2UInt(initValue, 4);setbyte t = BIConvert.Int2By
10、tes(value); for (int i = 0; i < 4; i+)initValuei + 4 = ti;public uint SequenceIdgetreturn (BIConvert.Bytes2UInt(initValue, 8);setbyte t = BIConvert.Int2Bytes(value); for (int i = 0; i < 4; i+)亿阳超长信息发布软件V1.0 源代码60-4initValuei + 4 + 4 = ti;public byte toBytes()return (initValue); /将字段转化为字节public
11、 void fromBytes(byte bs)for (int i = 0; i < MSG.CMPP_MSG_Header.HeaderLength; i+)initValuei = bsi;public static int HeaderLengthgetreturn (4 + 4 + 4);public class CMPP_MSG_CONNECTCMPP_MSG_Header header; byte initValue;byte body;int baseIndex = MSG.CMPP_MSG_Header.HeaderLength; /消息的起始byte ver = 0x
12、30;byte AuthenticatorSource = new Byte16; string _SystemID = "000000"string _Password = "00000000" string _timestamp = "0000000000"/的验证信息public CMPP_MSG_CONNECT(uint sequence)header=newMSG.CMPP_MSG_Header(MSG.CMPP_COMMAND_ID.CMPP_CONNECT);header.SequenceId = sequence;he
13、ader.MSGLength MSG.CMPP_MSG_Header.HeaderLength);=(uint)(this.BodyLength+body = new bytethis.BodyLength;public CMPP_MSG_CONNECT(byte bs)亿阳超长信息发布软件V1.0 源代码60-5initValue = new bytebs.Length; bs.CopyTo(initValue, 0); /进行初始化行为byte temp = new byteMSG.CMPP_MSG_Header.HeaderLength; for (int i = 0; i < t
14、emp.Length; i+)tempi = bsi;byte body = new Bytebs.Length - MSG.CMPP_MSG_Header.HeaderLength; for (int i = 0; i < body.Length; i+)bodyi = bsMSG.CMPP_MSG_Header.HeaderLength + i; /将消息的字节存储header = new MSG.CMPP_MSG_Header(temp); /构造 消息头header.MSGLength MSG.CMPP_MSG_Header.HeaderLength);=(uint)(this.
15、BodyLength+header.Command_ID = (uint)MSG.CMPP_COMMAND_ID.CMPP_CONNECT;public int BodyLengthgetreturn (6 + 16 + 4 + 1);public string SourceAddset_SystemID = value;byte t = Encoding.ASCII.GetBytes(_SystemID); /转换为字节数组t.CopyTo(body, 0);public string Passwordset_Password = value;public string Versionset
16、ver = Convert.ToByte("0x" + value, 16);亿阳超长信息发布软件V1.0 源代码60-6public string Versetver = Convert.ToByte(value);private static string getTimestamp() /返回一个时间戳 4 字节DateTime msgtime = DateTime.Now;string u = msgtime.Month.ToString().PadLeft(2, '0'); u = u + msgtime.Day.ToString().PadLeft
17、(2, '0');u = u + msgtime.Hour.ToString().PadLeft(2, '0');u = u + msgtime.Minute.ToString().PadLeft(2, '0'); u = u + msgtime.Second.ToString().PadLeft(2, '0'); return (u);private byte getMd5Code()MD5 md5 = new MD5CryptoServiceProvider(); /创建MD5 类别byte buf = new byte6 +
18、 9 + _Password.Length + 10;byte s_a = Encoding.ASCII.GetBytes(_SystemID); /Source_ADD 就是企业代码byte s_0 = 0, 0, 0, 0, 0, 0, 0, 0, 0 ;/9 字节的0,此处当作右补0byte s_p = Encoding.ASCII.GetBytes(_Password); /this._timestamp = getTimestamp();/取得认证码时赋值字符串byte s_t = Encoding.ASCII.GetBytes(_timestamp); /10 位的字符串字节数组s
19、_a.CopyTo(buf, 0);s_0.CopyTo(buf, 6);s_p.CopyTo(buf, 6 + 9);/base 0/base 6/base 6+9s_t.CopyTo(buf, 6 + 9 + _Password.Length); /base 6+9+password.lengthreturn (md5.ComputeHash(buf, 0, buf.Length);private byte getSourceAdd()return (Encoding.ASCII.GetBytes(this._SystemID);public byte ToBytes()/返回当前对象的字
20、节数组印象bytereVal=newByteMSG.CMPP_MSG_Header.HeaderLength+this.BodyLength;header.toBytes().CopyTo(reVal, 0);/消息头getSourceAdd().CopyTo(reVal, MSG.CMPP_MSG_Header.HeaderLength); /源地址 企业代码getMd5Code().CopyTo(reVal, MSG.CMPP_MSG_Header.HeaderLength + 6);/认证md5reValMSG.CMPP_MSG_Header.HeaderLength + 6 + 16
21、= this.ver;/版本字亿阳超长信息发布软件V1.0 源代码60-7节BIConvert.Int2Bytes(Convert.ToUInt32(this._timestamp).CopyTo(reVal, MSG.CMPP_MSG_Header.HeaderLength + 6 + 16 + 1);return (reVal);public class CMPP_MSG_CONNECT_RESPCMPP_MSG_Header header; uint _status;byte AuthenticatorISMG; byte _Version;public CMPP_MSG_CONNECT
22、_RESP(byte bs)byte temp_head = new ByteMSG.CMPP_MSG_Header.HeaderLength; int index = 0;for (int i = 0; i < MSG.CMPP_MSG_Header.HeaderLength; i+)temp_headi = bsindex+;header = new MSG.CMPP_MSG_Header(temp_head); this._status = BIConvert.Bytes2UInt(bs, index); /状态字节index += 4;AuthenticatorISMG = ne
23、w byte16;/回应摘要for (int i = 0; i < AuthenticatorISMG.Length; i+)AuthenticatorISMGi = bsindex+;_Version = bsindex+;public bool isOkgetreturn (true);public string Vergetreturn (Convert.ToString(this._Version, 16);public string ISMGREturnAuthCode亿阳超长信息发布软件V1.0 源代码60-8getreturn (Encoding.ASCII.GetStri
24、ng(AuthenticatorISMG);public uint Command_IDgetreturn (header.Command_ID);setheader.Command_ID = value;public uint Sequencegetreturn (header.SequenceId);public int Statusgetreturn (int)this._status);public class CMPP_MSG_TERMINATECMPP_MSG_Header header;public CMPP_MSG_TERMINATE(uint sequence)header=
25、newMSG.CMPP_MSG_Header(MSG.CMPP_COMMAND_ID.CMPP_TERMINATE);header.MSGLength = (uint)MSG.CMPP_MSG_Header.HeaderLength; header.SequenceId = sequence;public CMPP_MSG_TERMINATE(byte bs)header = new MSG.CMPP_MSG_Header(bs);public byte toBytes()亿阳超长信息发布软件V1.0 源代码60-9return (header.toBytes();public uint Se
26、quencegetreturn (header.SequenceId);public class CMPP_MSG_TERMINATE_RESPCMPP_MSG_Header header;public CMPP_MSG_TERMINATE_RESP(byte bs)header = new CMPP_MSG_Header(bs);public CMPP_MSG_TERMINATE_RESP(uint sequence)header=newMSG.CMPP_MSG_Header(MSG.CMPP_COMMAND_ID.CMPP_TERMINATE_RESP);header.MSGLength
27、= (uint)MSG.CMPP_MSG_Header.HeaderLength; header.SequenceId = sequence;public byte toBytes()return (header.toBytes();public uint Command_IDgetreturn (header.Command_ID);setheader.Command_ID = value;public uint Sequencegetreturn (header.SequenceId);亿阳超长信息发布软件V1.0 源代码60-10public class CMPP_MSG_SUBMITC
28、MPP_MSG_Header header;/int _isReportOrSMC = 1;/是否需要状态报告int _isReportOrSMC = 0;/是否需要状态报告 0 不要,1 需要int _msgTotal = 1; int _msgNumber = 1; int _msgLevel = 0;/相同消息的条数/消息级别string _svcCode = "" /业务类型int _feeUserType = 0;/计费用户类型字段0:对目的终端MSISDN 计费;1:对源终端MSISDN 计费;2:对SP 计费;3:表示本字段无效,对谁计费参见Fee_termi
29、nal_Id 字段string _feeTerminalId = "" /被计费终端int _feempType = 0; int _tpPid = 0;int _tpUDHI = 0;uint _msgFmt = (int)MSG.Msg_Format.GB2312; /消息格式string _msgsrc = ""/消息来源 即spidstring _feeType = MSG.FeeType.FEE_TERMINAL_PERITEM;/string _feeCode = "" string _valIdTime = "
30、" string _atTime = ""/资费/存活期/调度时间string _srcId = ""int _destUsrNum = 1;/源号码,就是在上显示的号码/接受消息的数string _destTerminalIds = "" /UserMP int _usermpType = 0;int _msgLengt = 0; string _MsgContent = ""UInt64 _MsgID;/返回的消息ID string _LinkID = ""public CMPP_
31、MSG_SUBMIT(uint MtID)header=newMSG.CMPP_MSG_Header(MSG.CMPP_COMMAND_ID.CMPP_SUBMIT);header.SequenceId = MtID;#region 字段属性/属性/ public string MtMsgsetthis._MsgContent = value;byte t = Encoding.ASCII.GetBytes(value); this._msgLengt = t.Length;亿阳超长信息发布软件V1.0 源代码60-11public int MsgLevelsetthis._msgLevel
32、= value;public string FeeMPsetthis._feeTerminalId = value;public string UserMPsetthis._destTerminalIds = value;public string SPIDsetthis._msgsrc = value;public string ServiceNumsetthis._srcId = value;/可以此处确定长号码public string ServiceIDsetthis._svcCode = value;public string FeeTypeset亿阳超长信息发布软件V1.0 源代码
33、60-12this._feeType = value.PadLeft(2, '0');public string FeeCodesetthis._feeCode = value;public string ValIdTimesetthis._valIdTime = value;public string AtTimesetthis._atTime = value;public UInt64 MsgIDsetthis._MsgID = value;getreturn (this._MsgID);public string LinkIDsetthis._LinkID = value
34、;/属性结束/ #endregion亿阳超长信息发布软件V1.0 源代码60-13public byte toBytes() /返回字节数印象byte submitData = new byte800;int index = MSG.CMPP_MSG_Header.HeaderLength;#region 进入填充包的过程/当前包的填充指针index = index + 8;/msgid 跳过submitDataindex+ = (byte)this._msgTotal; submitDataindex+ = (byte)this._msgNumber; submitDataindex+ =
35、(byte)this._isReportOrSMC; submitDataindex+ = (byte)this._msgLevel;byte svccode = Encoding.ASCII.GetBytes(this._svcCode);svccode.CopyTo(submitData, index);/拷贝到目标index = index + 10;/index 增加submitDataindex+ = (byte)this._feeUserType;byte feetid = Encoding.ASCII.GetBytes(this._feeTerminalId); feetid.C
36、opyTo(submitData, index);index = index + 32;submitDataindex+ = (byte)this._feempType; submitDataindex+ = (byte)this._tpPid; submitDataindex+ = (byte)this._tpUDHI; submitDataindex+ = (byte)this._msgFmt;byte spid = Encoding.ASCII.GetBytes(this._msgsrc); spid.CopyTo(submitData, index);index = index + 6
37、;byte feetype = Encoding.ASCII.GetBytes(this._feeType); feetype.CopyTo(submitData, index);index = index + 2;byte feecode = Encoding.ASCII.GetBytes(this._feeCode); feecode.CopyTo(submitData, index);index = index + 6;/byte validtime=Encoding.ASCII.GetBytes(this._valIdTime);/validtime.CopyTo (submitDat
38、a,index); index = index + 17;/byte attime=Encoding.ASCII.GetBytes(this._valIdTime);/attime.CopyTo (submitData,index); index = index + 17;byte srcid = Encoding.ASCII.GetBytes(this._srcId); srcid.CopyTo(submitData, index);index = index + 21;submitDataindex+ = (byte)this._destUsrNum;byte temp = Encodin
39、g.ASCII.GetBytes(this._destTerminalIds); temp.CopyTo(submitData, index);index = index + 32;submitDataindex+ = (byte)this._usermpType; submitDataindex+ = (byte)this._msgLengt; byte msg = null;switch (this._msgFmt)#region 根据编码类型确定转换字节case (uint)MSG.Msg_Format.ASCII:亿阳超长信息发布软件V1.0 源代码60-14msg = Encodin
40、g.ASCII.GetBytes(this._MsgContent); msg.CopyTo(submitData, index);submitDataindex - 1 = (byte)msg.Length; index = index + msg.Length;break;/重新设定长度case (uint)MSG.Msg_Format.BINARY:msg = Encoding.ASCII.GetBytes(this._MsgContent); msg.CopyTo(submitData, index);submitDataindex - 1 = (byte)msg.Length; in
41、dex = index + msg.Length;break;/重新设定长度case (uint)MSG.Msg_Format.GB2312:msg = Encoding.Default.GetBytes(this._MsgContent); msg.CopyTo(submitData, index);submitDataindex - 1 = (byte)msg.Length; index = index + msg.Length;break;/重新设定长度case (uint)MSG.Msg_Format.UCS2:msg = Encoding.BigEndianUnicode.GetBy
42、tes(this._MsgContent); msg.CopyTo(submitData, index);submitDataindex - 1 = (byte)msg.Length;/重新设定长度index = index + msg.Length;break;case (uint)MSG.Msg_Format.WRITECARD:/写卡操作msg = Encoding.ASCII.GetBytes(this._MsgContent); msg.CopyTo(submitData, index);submitDataindex - 1 = (byte)msg.Length; index =
43、index + msg.Length;break; default:/重新设定长度msg = Encoding.ASCII.GetBytes(this._MsgContent); msg.CopyTo(submitData, index);submitDataindex - 1 = (byte)msg.Length; index = index + msg.Length;break; #endregion/重新设定长度byte linkid = Encoding.ASCII.GetBytes(this._LinkID); linkid.CopyTo(submitData, index);ind
44、ex = index + 20; #endregionheader.MSGLength = (uint)index;/根据index 的长度决定传输数据字节长度byte reVal = new byteindex;header.toBytes().CopyTo(reVal, 0);for (int i = MSG.CMPP_MSG_Header.HeaderLength; i < reVal.Length; i+)亿阳超长信息发布软件V1.0 源代码60-15reVali = submitDatai;return (reVal);public class CMPP_MSG_SUBMIT_
45、LONGCMPP_MSG_Header header;int _isReportOrSMC = 0;/是否需要状态报告 0 表示不需要,1 需要int _msgTotal = 1; int _msgNumber = 1; int _msgLevel = 0;/相同消息的条数/消息级别string _svcCode = "" /业务类型int _feeUserType = 0;/计费用户类型字段0:对目的终端MSISDN 计费;1:对源终端MSISDN 计费;2:对SP 计费;3:表示本字段无效,对谁计费参见Fee_terminal_Id 字段string _feeTermi
46、nalId = "" /被计费终端int _feempType = 0; int _tpPid = 0;int _tpUDHI = 0x01; uint _msgFmt = 0x08;string _msgsrc = ""/消息来源 即spidstring _feeType = MSG.FeeType.FEE_TERMINAL_PERITEM;/string _feeCode = "" string _valIdTime = "" string _atTime = ""/资费/存活期/调度时间s
47、tring _srcId = ""int _destUsrNum = 1;/源号码,就是在上显示的号码/接受消息的数string _destTerminalIds = "" /UserMP int _usermpType = 0;int _msgLengt = 0; string _MsgContent = ""UInt64 _MsgID;/返回的消息ID string _LinkID = ""public CMPP_MSG_SUBMIT_LONG(uint MtID)header=newMSG.CMPP_MSG_
48、Header(MSG.CMPP_COMMAND_ID.CMPP_SUBMIT);header.SequenceId = MtID;#region 字段属性/属性/ public string MtMsgsetthis._MsgContent = value;byte t = Encoding.ASCII.GetBytes(value);亿阳超长信息发布软件V1.0 源代码60-16this._msgLengt = t.Length;public byte byteMsg = new byte140;public int MsgLevelsetthis._msgLevel = value;pub
49、lic string FeeMPsetthis._feeTerminalId = value;public string UserMPsetthis._destTerminalIds = value;public string SPIDsetthis._msgsrc = value;public string ServiceNumsetthis._srcId = value;/可以此处确定长号码public string ServiceIDsetthis._svcCode = value;亿阳超长信息发布软件V1.0 源代码60-17public string FeeTypesetthis._
50、feeType = value.PadLeft(2, '0');public string FeeCodesetthis._feeCode = value;public string ValIdTimesetthis._valIdTime = value;public string AtTimesetthis._atTime = value;public UInt64 MsgIDsetthis._MsgID = value;getreturn (this._MsgID);public string LinkIDsetthis._LinkID = value;亿阳超长信息发布软件
51、V1.0 源代码60-18/属性结束/ #endregionpublic byte toBytes() /返回字节数印象byte submitData = new byte800;int index = MSG.CMPP_MSG_Header.HeaderLength;#region 进入填充包的过程/当前包的填充指针index = index + 8;/msgid 跳过submitDataindex+ = (byte)this._msgTotal; submitDataindex+ = (byte)this._msgNumber; submitDataindex+ = (byte)this.
52、_isReportOrSMC; submitDataindex+ = (byte)this._msgLevel;byte svccode = Encoding.ASCII.GetBytes(this._svcCode);svccode.CopyTo(submitData, index);/拷贝到目标index = index + 10;/index 增加submitDataindex+ = (byte)this._feeUserType;byte feetid = Encoding.ASCII.GetBytes(this._feeTerminalId); feetid.CopyTo(submitData, index);index = index + 32;submitDataindex+ = (byte)this._feempType; submitDataindex+ = (byte)this._tpPid; submitDataindex+ = (byte)this._tpUDHI; submitDataindex+ = (byte)this._msgF
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 麋鹿课件完美教学课件
- 消防应急体系
- 3.1.1 铁及其性质 课件高一上学期化学(人教版2019必修第一册)
- 外汇期货课件教学课件
- 池塘边的小鸭教案反思
- 过生日说课稿
- 2025商场地产蛇年新春国潮年货节(蛇年行大集主题)活动策划方案-47P
- 智慧人工智能:开拓人工智能创新应用的方案
- 新能源汽车二手房交易合同模板
- 眼镜制造合作合同
- 语音厅策划方案
- 人教版五年级上册数学简便计算300题及答案
- 术中低体温预防小讲课课件
- 2024年家庭教育指导师考试(重点)题库及答案(含各题型)
- 阿里巴巴福利分析课件
- 陕西师范大学2022年730物理化学考研真题
- 广西汽车站案例分析报告
- 抖音认证承诺函
- 上呼吸道感染呼吸查房
- 火针疗法课件
- 化学品作业场所安全警示标志双氧水
评论
0/150
提交评论