⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmpp120.bas

📁 VB写的cmpp协议测试程序
💻 BAS
📖 第 1 页 / 共 2 页
字号:
Attribute VB_Name = "CMPP120"
Option Explicit '在模块级别中使用,强制显式声明模块中的所有变量。

'==API函数的声明==
'Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) As Boolean
'Public Declare Sub MD5 Lib "dllmd5.dll" (ByVal sChar As String, ByVal Ret16 As String, ByVal Ret32 As String)
Public Declare Sub MD5 Lib "D:\dllmd5.dll" (ByVal Souce As String, ByVal s16 As String, ByVal s32 As String, ByVal sLen As Long)

'==定义WinSock控件的State属性的设置值==
  Public Const sckOpen = 1 '打开
  Public Const sckListening = 2 '侦听
  Public Const sckConnectionPending = 3 '连接挂起
  Public Const sckResolvingHost = 4 '识别主机
  Public Const sckHostResolved = 5 '已识别主机
  Public Const sckConnecting = 6 '正在连接
  Public Const sckConnected = 7 '已连接
  Public Const sckClosing = 8 '同级人员正在关闭连接
  Public Const sckError = 9 '错误
'=============================
'==定义ISMG的Commamd_ID==
'-------------- 命令字名称  Command_ID值    说明-----------------
  Public CMPP_Connect(3) As Byte         '&H00000001 请求连接
  Public CMPP_Connect_REP(3) As Byte     '&H80000001 请求连接应答
  Public CMPP_Terminate(3) As Byte       '&H00000002 终止连接
  Public CMPP_Terminate_REP(3) As Byte   '&H80000002 终止连接应答
  Public CMPP_Submit(3) As Byte          '&H00000004 提交短信
  Public CMPP_Submit_REP(3) As Byte      '&H80000004 提交短信应答
  Public CMPP_Deliver(3) As Byte         '&H00000005 短信下发
  Public CMPP_Deliver_REP(3) As Byte     '&H80000005 下发短信应答
  Public CMPP_Query(3) As Byte           '&H00000006 发送短信状态查询
  Public CMPP_Query_REP(3) As Byte       '&H80000006 发送短信状态查询应答
  Public CMPP_Cancel(3) As Byte          '&H00000007 删除短信
  Public CMPP_Cancel_REP(3) As Byte      '&H80000007 删除短信应答
  Public CMPP_Active_Test(3) As Byte     '&H00000008 激活测试
  Public CMPP_Active_Test_REP(3) As Byte '&H80000008 激活测试应答
'----------------------------------------------------------------
'==变量定义==
'--信息流水号(10进制)--
Public XuHao As Double
Public CMD(3) As Byte
'--消息头格式--
  Public Type Message_Header
     Total_Length(3) As Byte  '4 消息总长度(含消息头及消息体)
     Command_ID(3) As Byte    '4 命令或响应类型
     Sequence_ID(3) As Byte   '4 消息流水号,顺序累加,步长为1,循环使用
  End Type
'---------------
'--消息体格式--
'1. CMPP_Connect   请求连接
  Public Type MSG_Connect
     Source_Addr As String * 6 ' 6   Octet String    SP_ID   926021/01001
     AuthenticatorSP As String * 16 ' 16  Octet String    SP认证码
     'AuthenticatorSP(15) As Byte ' 16  Octet String    SP认证码
     Version As Byte '1   Integer 双方协商的版本号
     Timestamp(3) As Byte '   4   Integer 时间戳的明文,由客户端产生,格式为MMDDHHMMSS,即月日时分秒,10位,右对齐
  End Type
'2. CMPP_Connect_REP     请求连接应答
  Public Type MSG_Connect_REP
     Status As Byte ' 1   Integer 状态0:正确1:消息结构错 2:非法SP_ID 3:SP认证错 4:版本太高  5~ :其他错误
     AuthenticatorISMG As String * 16 '   16  Octet String    ISMG认证码 ,SP认证出错时,此项为空
     Version As Byte ' 1   Integer 服务器支持的最高版本号
  End Type
  '------------------------------------------
  '用于鉴别ICP。其值通过单向MD5 hash计算得出,表示如下:
  'AuthenticatorICP =MD5(Source_Addr+9 字节的0 +shared secret+timestamp)
  'Shared secret 由中国移动与ICP事先商定,timestamp格式为:MMDDHHMMSS,即月日时分秒,10位。
  '用于鉴别ISMG。其值通过单向MD5 hash计算得出,表示如下:
  'AuthenticatorISMG =MD5(Status+AuthenticatorICP+shared secret)
  'Shared secret 由中国移动与ICP事先商定,AuthenticatorICP为ICP发送给ISMG的上一条消息CMPP_Request_Connect中的值。
  '------------------------------------------
'3. CMPP_Terminate       终止连接
      '消息体为空
'4. CMPP_Terminate_Rep          终止连接响应
      '消息体为空
'5.CMPP_Submit                     发送短信
  Public Type MSG_Submit
     Msg_id(7) As Byte '  8   Integer 信息标识,由SP侧短信网关本身产生生成MsgID的算法如下:采用64位(8字节)的整数:(1)时间(从月精确到分)   64――41位(bit)(2)SMC(短讯中心)号码 40――17位(bit)如 13800100500,只填写最后86位00100500(3)序列号  16――1位(bit)顺序累加,步长为1,循环使用.各分段如不能填满,左补零,右对齐
     Pk_total As Byte  '  1   Integer 相同Msg_id的消息总条数,从1开始
     Pk_number As Byte '   1   Integer 相同Msg_id的消息序号,从1开始
     Registered_Delivery As Byte ' 1   Integer 是否要求返回状态确认报告(0--不需要,1--需要,2--产生SMC话单)
     Msg_level As Byte   '1   Integer 信息级别
     Service_id As String * 10 '10  Octet String    业务类型
     Fee_UserType As Byte ' 1   Integer 计费用户类型字段,0:对目的终端MSISDN计费;1:对源终端MSISDN计费;2:对SP计费;3:表示本字段无效,对谁计费参见Fee_terminal_id字段。
     Fee_terminal_id As String * 21 '  Integer 被计费用户的号码(如本字节填空,则表示本字段无效,对谁计费参见Fee_UserType字段。本字段与Fee_UserType字段互斥)
     TP_pid As Byte  '1   Integer GSM协议类型。详细是解释请参考GSM03.40中的9.2.3.9
     TP_udhi As Byte '1   Integer GSM协议类型。详细是解释请参考GSM03.40中的9.2.3.23,仅使用1位,右对齐
     Msg_Fmt As Byte '1   Integer 信息格式  0:ASCII串  3:短信写卡操作  4:二进制信息  8:UCS2编码15:含GB汉字  。。。。。。
     Msg_src As Byte '6   Octet String    信息内容来源(SP_ID)
     FeeType As String * 2 '   Octet String    资费类别
     FeeCode As String * 6 '   Octet String    资费代码(以分为单位)
     Valid_Time As String * 17 '  Octet String    存活有效期,格式遵循SMPP3.3协议
     At_Time As String * 17 '  Octet String    定时发送时间,格式遵循SMPP3.3协议
     Src_terminal_id As String * 21 '  Octet String    源终端MSISDN号码(没有可以为空)
     DestUsr_tl As Byte '  1   Integer 接收消息的用户数量(小于100个用户)
     Dest_terminal_id As String '    21*DestUsr_tl   Octet String    接收业务的MSISDN号码
     Msg_Length As Byte '  1   Integer 消息长度(Msg_Fmt值为0时:<160个字节;其它<=140个字节)
     Msg_Content As String 'Msg_length  Octet String    消息内容
     Reserve As String * 8 '   Octet String    保留
  End Type
'6.CMPP_Submit_REP           发送短信响应(出错要求SP全部重发Msg_Id信息)
  Public Type MSG_Submit_REP
     Msg_id(7) As Byte '   8   Integer 消息标识(参见第5条CMPP_Submit定义)
     Result As Byte '  1   Integer 结果0:正确1:消息结构错 2:命令字错 3:消息序号重复4:消息长度错5:资费代码错6:超过最大信息长7:业务代码错8:流量控制错9~ :其他错误
  End Type
'7.CMPP_Query        发送短信状态查询(查询Time属性指定的日期的统计信息)
  Public Type MSG_Query
     Time As String * 8 '    8   Octet String    时间(精确至日)
     Query_Type As Byte '  1   Integer 查询类别0:总数查询1:按业务代码查询
     Query_Code As String * 10 '  10  Octet String    查询码 (业务类型)
     Reserve As String * 8 '8   Octet String    保留
  End Type
'8.CMPP_Query_REP            短信状态查询结果
  Public Type MSG_Query_REP
     Time As String * 8 '    8   Octet String    时间(精确至日)
     Query_Type As Byte '  1   Integer 查询类别0:总数查询1:按业务代码查询
     Query_Code As String * 10 '  10  Octet String    查询码
     MT_TLMsg(3) As Byte '     4   Integer 从SP接收信息总数
     MT_Tlusr(3) As Byte '    4   Integer 从SP接收用户总数
     MT_Scs(3) As Byte ' 4   Integer 成功转发数量
     MT_WT(3) As Byte '   4   Integer 待转发数量
     MT_FL(3) As Byte '   4   Integer 转发失败数量
     MO_Scs(3) As Byte '  4   Integer 向SP成功送达数量
     MO_WT(3) As Byte '  4   Integer 向SP待送达数量
     MO_FL(3) As Byte '   4   Integer 向SP送达失败数量
  End Type
'9. CMPP_Deliver
  Public Type MSG_Deliver1
     Msg_id(7) As Byte '   8   Integer 消息标识(参见第5条CMPP_Submit定义)
     Destnation_id As String * 21 '   21  Octet String    SP的接入代码,一般4--6位
     Service_id As String * 10 '  10  Octet String    业务类型
     TP_pid As Byte '  1   Integer GSM协议类型。详细是解释请参考GSM03.40中的9.2.3.9
     TP_udhi As Byte ' 1   Integer GSM协议类型。详细是解释请参考GSM03.40中的9.2.3.23,仅使用1位,右对齐
     Msg_Fmt As Byte ' 1   Integer 信息格式  0:ASCII串  3:短信写卡操作  4:二进制信息  8:UCS2编码15:含GB汉字  。。。。。。
     Srcterminal_id As String * 21 '  21  Octet String    源终端MSISDN号码
     Registered_Delivery As Byte '1   Integer 是否为应答信息,0----非应答信息,1----状态报告
     Msg_Length As Byte '  1   Integer 消息长度
     Msg_Content As String 'Msg_length  Octet String    消息内容
     Reserve As String * 8 '8   Octet String    保留项
  End Type
'当CMPP_Deliver为对CMPP_Submit的应答信息时(即状态报告),信息内容字段格式定义如下:
  Public Type MSG_Deliver2
     Msg_id(7) As Byte '  8   Integer 消息标识(参见第5条CMPP_Submit定义)
     Stat As String * 7 '    7   Octet String    短信的应答结果,含义与SMPP3.3协议补充要求中stat字段定义相同
     Submit_time As String * 10 ' 10  Octet String    YYMMDDHHMM(YY为年的后两位00-99,MM:01-12,DD:01-31,HH:00-23,MM:00-59)
     Done_time As String * 10 '   10  Octet String    YYMMDDHHMM
     Dest_terminal_id As String * 21 '    21  Octet String    目的终端MSISDN号码

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -