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

📄 smspduclass.cls

📁 手机短信开发
💻 CLS
📖 第 1 页 / 共 2 页
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "SMSPDUClass"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

'保持属性值的局部变量
Private mvarSMSCLen As Integer '局部复制
Private mvarSMSCType As String '局部复制
Private mvarSMSC As String '局部复制
Private mvarMsgHead As Integer  '局部复制
Private mvarTPMR As Integer '局部复制
Private mvarDestPhoneNumLen As Integer '局部复制
Private mvarDestPhoneNumType As String '局部复制
Private mvarDestPhoneNum As String '局部复制
Private mvarTPPID As Integer '局部复制
Private mvarTPDSC As Integer '局部复制
Private mvarTPVP As Integer '局部复制
Private mvarMSGLen As Integer '局部复制
Private mvarMSGContent As String '局部复制
Private mvarPDULen As Integer '局部复制
Private mvarPDU As String '局部复制
'要引发该事件,请遵循下列语法使用 RaiseEvent:
'RaiseEvent ValidResult[(arg1, arg2, ... , argn)]
Public Event ValidResult(ByVal ErrorCode As Integer, ByVal ErrorString As String)

Public Function genPDU(Optional ByVal SMSContent As String, _
                        Optional ByVal DestNo As String, _
                        Optional ByVal ServiceNo As String) As String

'mvarSMSCLen = 0
'mvarSMSCType = ""
'mvarSMSC = ""
'mvarMsgHead = 11
'mvarTPMR = 0
'mvarDestPhoneNumLen = 0
'mvarDestPhoneNumType = ""
'mvarDestPhoneNum = ""
'mvarTPPID = 0
'mvarTPDSC = 8
'mvarTPVP = 0
'mvarMSGLen = 0
'mvarMSGContent = ""
'mvarPDULen = 0
'mvarPDU = ""


    If Len(SMSContent) > 0 Then
        mvarMSGContent = SMSContent
    
    End If


    If Len(DestNo) > 0 Then
        mvarDestPhoneNum = DestNo
    
    End If
    
  
    
   
    If Len(ServiceNo) > 0 Then
        mvarSMSC = ServiceNo
        If Len(mvarSMSC) > 14 Then
            RaiseEvent ValidResult(7, "SMSC Error!")
            mvarSMSC = "+8613800769500"
        End If
        If Len(mvarSMSC) < 11 Then
            RaiseEvent ValidResult(7, "SMSC Error!")
            mvarSMSC = "+8613800769500"
        End If
        mvarSMSC = "+86" & Right(mvarSMSC, 11)
    
    End If


        
    
    If Len(mvarDestPhoneNum) = 0 Then
        genPDU = ""
        RaiseEvent ValidResult(3, "DestPhoneNumber is null!")
        
        Exit Function
    End If
    
    If mvarTPDSC <> 0 And mvarTPDSC <> 8 Then
        genPDU = ""
        RaiseEvent ValidResult(5, "TP-DCS Error!")
        
        Exit Function
    End If
    
    Dim ServiceNumPDU As String
    Dim DestPhoneNumPDU As String
    ServiceNumPDU = mvarSMSC
    DestPhoneNumPDU = mvarDestPhoneNum

' msg.DestPhoneNumType 被叫号码类型。有+86时候为"91",否则为"81"

    If Len(mvarSMSC) > 0 Then
        FormatPhoneNum ServiceNumPDU, mvarSMSCType
        mvarSMSCLen = Len(ServiceNumPDU & mvarSMSCType) / 2 '短信息中心地址长度。(短信息中心号码类型 + 短信息中心号码长度 /2 的十六进制表示)
    
    End If
    
    mvarDestPhoneNumLen = FormatPhoneNum(DestPhoneNumPDU, mvarDestPhoneNumType) ''被叫号码长度。被叫号码长度的十六进制表示。
'
    If Len(mvarMSGContent) > 70 Then
        mvarMSGContent = Left(mvarMSGContent, 70)


    End If
    
'    mvarMSGLen = Len(mvarMSGContent)
    
    Dim SMSText As String
    SMSText = mvarMSGContent
    

'
    SMSText = GB2Unicode(SMSText)   '把汉字符转化为UNICODE的HEX编码字符串
'

'
    mvarMSGLen = Len(SMSText) \ 2
    
    If Len(mvarSMSC) = 0 Then
        mvarSMSCLen = 0
        mvarPDU = Int2HexStr(mvarSMSCLen) & Int2HexStr(mvarMsgHead) & Int2HexStr(mvarTPMR) & Int2HexStr(mvarDestPhoneNumLen) & mvarDestPhoneNumType & DestPhoneNumPDU & _
                    Int2HexStr(mvarTPPID) & Int2HexStr(mvarTPDSC) & Int2HexStr(mvarTPVP) & Int2HexStr(mvarMSGLen) & SMSText

        mvarPDULen = Len(mvarPDU) / 2 - 1


    Else
        mvarPDU = Int2HexStr(mvarSMSCLen) & mvarSMSCType & ServiceNumPDU & Int2HexStr(mvarMsgHead) & Int2HexStr(mvarTPMR) & Int2HexStr(mvarDestPhoneNumLen) & mvarDestPhoneNumType & DestPhoneNumPDU & _
                    Int2HexStr(mvarTPPID) & Int2HexStr(mvarTPDSC) & Int2HexStr(mvarTPVP) & Int2HexStr(mvarMSGLen) & SMSText

        
        mvarPDULen = Len(mvarPDU) / 2 - 9   'PDU字符串长度
    End If

    genPDU = mvarPDU
    
End Function

'Public Property Let PDU(ByVal vData As String)
''向属性指派值时使用,位于赋值语句的左边。
''Syntax: X.PDU = 5
'    mvarPDU = vData
'End Property


Public Property Get PDU() As String
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.PDU

    Call genPDU
    
    PDU = mvarPDU
End Property



'Public Property Let PDULen(ByVal vData As Integer)
''向属性指派值时使用,位于赋值语句的左边。
''Syntax: X.PDULen = 5
'    mvarPDULen = vData
'End Property


Public Property Get PDULen() As Integer
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.PDULen
    PDULen = mvarPDULen
End Property



Public Property Let MSGContent(ByVal vData As String)
'向属性指派值时使用,位于赋值语句的左边。
'Syntax: X.MSGContent = 5
    mvarMSGContent = vData
    mvarMSGLen = Len(vData) * 2
    
End Property


Public Property Get MSGContent() As String
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.MSGContent
    MSGContent = mvarMSGContent
End Property



'Public Property Let MSGLen(ByVal vData As String)
''向属性指派值时使用,位于赋值语句的左边。
''Syntax: X.MSGLen = 5
'    mvarMSGLen = vData
'End Property


Public Property Get MSGLen() As Integer
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.MSGLen
    MSGLen = mvarMSGLen
End Property



Public Property Let TPVP(ByVal vData As Integer)
'向属性指派值时使用,位于赋值语句的左边。
'Syntax: X.TPVP = 5
    If vData >= 0 And vData < 256 Then
        mvarTPVP = vData
    
    Else
        RaiseEvent ValidResult(6, "TP-VP Error!")
    End If
End Property


Public Property Get TPVP() As Integer
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.TPVP
    TPVP = mvarTPVP
End Property



Public Property Let TPDCS(ByVal vData As Integer)
'向属性指派值时使用,位于赋值语句的左边。
'Syntax: X.TPDSC = 5
    If vData >= 0 And vData < 256 Then
        mvarTPDSC = vData
    Else
        RaiseEvent ValidResult(5, "TP-DCS Error!")
    End If
End Property


Public Property Get TPDCS() As Integer
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.TPDSC
    TPDCS = mvarTPDSC
End Property



Public Property Let TPPID(ByVal vData As Integer)
'向属性指派值时使用,位于赋值语句的左边。
'Syntax: X.TPPID = 5
    If vData >= 0 And vData < 256 Then
        mvarTPPID = vData
    Else
        RaiseEvent ValidResult(4, "TP-PID Error!")
    End If
End Property


Public Property Get TPPID() As Integer
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.TPPID
    TPPID = mvarTPPID
End Property



Public Property Let DestPhoneNum(ByVal vData As String)
'向属性指派值时使用,位于赋值语句的左边。
'Syntax: X.DestPhoneNum = 5
    If Len(vData) = 0 Then
        RaiseEvent ValidResult(3, "DestPhoneNumber is null!")
    Else
        mvarDestPhoneNum = vData
        mvarDestPhoneNumLen = FormatPhoneNum(vData, mvarDestPhoneNumType)
    End If
End Property





Public Property Get DestPhoneNum() As String
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.DestPhoneNum

        DestPhoneNum = mvarDestPhoneNum

End Property



'Public Property Let DestPhoneNumType(ByVal vData As String)
''向属性指派值时使用,位于赋值语句的左边。

⌨️ 快捷键说明

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