日期:2013-05-07  浏览次数:20381 次

网上有很多利用COM口连接手机,利用手机MODEM,使用AT指令发送短信,介绍PDU编码的原理很多,写一个现成的类出来,给有需要的人参考和使用。

SMSPDUClass.cls

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 ServiceNumPD