## CSDN博客

### 手机短信发送

²        中文转换成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串转换函数

 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

²        手机短信的发送

 Const prex = "0891" Const midx = "11000D91" Const sufx = "000800" Public Function Sendsms(csca As String, num As String, msg As String) As _Boolean     Dim pdu, psmsc, pnum, pmsg As String     Dim leng As String     Dim length As Integer     length = Len(msg)     length = 2 * length     leng = Hex(length)     If length < 16 Then leng = "0" & leng     psmsc = Trim(telc(csca))     pnum = Trim(telc(num))     pmsg = Trim(ascg(msg))     pdu = prex & psmsc & midx & pnum & sufx & leng & pmsg sleep(1)     mobcomm.Output = "AT+CMGF=0" + vbCr     mobcomm.Output = "AT+CMGS=" & Str(15 + length) + vbCr mobcomm.Output = pdu & Chr\$(26) sleep(1)     Sendsms = True End Function

### 手机短信的接收

²        Unicode码解码函数

 Public Function ascg(smsg As String) As String Dim si, sb As Integer Dim stmp As Integer Dim stemp As String sb = Len(smsg) ascg = "" For si = 1 To sb     stmp = AscW(Mid(smsg, si, 1))     If Abs(stmp) < 127 Then         stemp = "00" & Hex(stmp)     Else         stemp = Hex(stmp)     End If     ascg = ascg & stemp Next si ascg = Trim(ascg) End Function

²        手机短信接收函数

 Public Sub readsms(rnum As String) mobcomm.Output = "AT+CMGF=1" + vbCr mobcomm.Output = "AT+CMGR=" & rnum + vbCr End Sub

0 0