当前位置:编程学习 > VB >>

VB 短信pdu生成代码

Option Explicit

 

Public Function DecodeUnicode(ByVal UnicodeString As String) As String
    Dim strUnicode As String
    Dim objDll As New myVBDll
   
On Error GoTo ErrorUnicode
   
    strUnicode = UnicodeString
    DecodeUnicode = objDll.Unicode2GB(strUnicode)
   
    Set objDll = Nothing
   
    Exit Function

ErrorUnicode:
    Set objDll = Nothing
    MsgBox "Error:" & Err & "." & vbCrLf & Err.Description
End Function

 

由于位置上略有处理,实际号码应为: 8613805515500( 字母 F 意指长度减 1),
这是作者所在地 GSM 短信息中心的号码。 ( 号码处理方法为 , 如果为 +86 开始 , 将 + 号去掉 ,
然后判断是否为偶数 , 不是在末尾补 F, 然后将奇数位和偶数位互换 )

Public Function FormatPhoneNum(ByRef phoneNum As String, ByRef tonNpiFlag As String) As Integer
    Dim i As Integer
    Dim iAsc As Integer
    Dim strChar As String
   
        If Len(phoneNum) = 14 Then
            If Left(phoneNum, 3) = "+86" Then
                phoneNum = Right(phoneNum, 11)
            Else
                If Len(phoneNum) <> 11 Then
                    FormatSMSC = 0
                    Exit Function
                End If
            End If
        End If
        If Len(phoneNum) <= 0 Then
            FormatPhoneNum = 0
            Exit Function
        End If
             If Left(phoneNum, 3) = "+86" Then
                phoneNum = Right(phoneNum, 13)
                tonNpiFlag = "91"
            Else
                If Len(phoneNum) <> 11 Then
                    FormatSMSC = 0
                    Exit Function
                End If
                tonNpiFlag = "81"
            End If
           
     
       
        For i = 1 To Len(phoneNum)
            strChar = Mid(phoneNum, i, 1)
            iAsc = Asc(strChar)
            If iAsc > 57 Or iAsc < 48 Then
                FormatPhoneNum = 0
                Exit Function
            End If
        Next i
        If Len(phoneNum) Mod 2 <> 0 Then
            phoneNum = phoneNum & "F"
        End If
       
        Dim strTmp2, strTmp1 As String
        strTmp1 = ""
        For i = 1 To Len(phoneNum) Step 2
            strTmp2 = Mid(phoneNum, i, 2)
            strTmp1 = strTmp1 & Right(strTmp2, 1) & Left(strTmp2, 1)
        Next i
        phoneNum = strTmp1
        Debug.Print phoneNum
    FormatPhoneNum = Len(phoneNum) - 1
End Function

功能: 生成PDU串
输入: 短信息内容、目标手机号码、[可选的短信服务中心号码]
输出: 生成的PDU串
返回: 整个字串的长度


Public Function GenPDU(ByVal SMSText As String, _
                        ByVal DestNo As String, _
                        Optional ByVal ServiceNo As String) As SMSPDUStruct

   
    Dim Msg As SMSPDUStruct
   
   
    If Len(DestNo) = 0 Then
        genPDU = 0
        Exit Function
    End If
   
    If ServiceNo = "" Then
        ServiceNo = "+8613800755500"
    End If

        If Len(SMSText) > 70 Then
            SMSText = Left(SMSText, 70)


        End If

    Msg.SMSC = ServiceNo
    Msg.DestPhoneNum = DestNo
   
    FormatPhoneNum Msg.SMSC, Msg.SMSCType
    Msg.SMSCLen = Int2HexStr(Len(Msg.SMSC & Msg.SMSCType) / 2)  短信息中心地址长度。(短信息中心号码类型 + 短信息中心号码长度 /2 的十六进制表示)
   
    msg.DestPhoneNumType 被叫号码类型。有+86时候为"91",否则为"81"
    Msg.DestPhoneNumLen = Int2HexStr(FormatPhoneNum(Msg.DestPhoneNum, Msg.DestPhoneNumType))    被叫号码长度。被叫号码长度的十六进制表示。
   
   
   
    Dim iLen As Integer
    
    SMSText = GB2Unicode(SMSText)   把汉字符转化为UNICODE的HEX编码字符串
   
    strChar = Hex(iLen)
    If Len(strChar) < 2 Then strChar = "0" & strChar
    strTmp = strChar & SMSText
    If flash = True Then
        SMSText = "0001" & SMSText
&nb

补充:软件开发 , Vb ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,