|
因为手机短消息的发送是以PDU串的形式发送出去的,中文字符以Unicode码来表示,所以在发送中文短消息之前必须首先将中文字符转换为Unicode码,下面的函数将实现这个功能。这个函数主要应用到VB自带的一个格式转换函数:ChrW()将中文转换为Unicode码。
Public Function chg(rmsg As String) As String Dim tep As String Dim temp As String Dim i As Integer Dim b As Integer tep = rmsg i = Len(tep) b = i / 4 If i = b * 4 Then b = b - 1 tep = Left(tep, b * 4) Else tep = Left(tep, b * 4) End If chg = "" For i = 1 To b temp = "&H" & Mid(tep, (i - 1) * 4 + 1, 4) chg = chg & ChrW(CInt(Val(temp))) Next i End Function 同上,为了发送以PDU模式发送短消息,必须将手机号码和对方手机号码也转换为PDU格式,下面的函数就是为了实现这种转换:
Public Function telc(num As String) As String Dim tl As Integer Dim ltem, rtem, ttem As String Dim ti As Integer ttem = "" tl = Len(num) If tl <> 11 And tl <> 13 Then MsgBox "wrong number." & tl Exit Function End If If tl = 11 Then tl = tl + 2 num = "86" & num End If For ti = 1 To tl Step 2 ltem = Mid(num, ti, 1) rtem = Mid(num, ti + 1, 1) If ti = tl Then rtem = "F" ttem = ttem & rtem & ltem Next ti telc = ttem End Function
手机号码有两种表示方法:11位和13位(带国家码86),一般手机发送时都是以13位形式表示的,所以以上的函数还有一个功能是自动将11位格式手机号码转换为13位形式,然后再转换为PDU串。
[1] [2] 下一页
|