SMS send

xiaoxiao2021-03-05  23

Chinese converted into Unicode code functions because the transmission of mobile short messages is sent in the form of a PDU string, and the Chinese characters are represented by the Unicode code, so they must first convert the Chinese characters to Unicode codes before sending Chinese short messages. The following functions This feature will be implemented. This function is primarily applied to a format conversion function that comes with the VB: ChRW () converts Chinese into Unicode code.

Public Function CHG (RMSG As String) AS Stringdim Tep As Stringdim Temp As Stringdim I AS INTEGERDIM B AS INTEGERTEP = RMSGI = LEN (TEP) B = I / 4IF I = B * 4 THEN B = B - 1 TEP = Left (TEP , B * 4) ELSE TEP = Left (TEP, B * 4) end ifchg = "" for i = 1 to b Temp = "& H" & MID (TEP, (i - 1) * 4 1, 4) CHG = CHG & Chrw (CINT (Val (Temp)) Next Ind Function

2 SMS center mobile phone number PDU string conversion function is the same, in order to send a short message in PDU mode, the mobile phone number and the other party mobile number must also be converted to PDU format. The following functions are to achieve this conversion:

Public Function Telc (Num As String) AS STRINGDIM TL AS INTEGERDIM LTEM, RTEM, TTEM AS STRINGDIM TI AS INTEGERTTEM = "" TL = LEN (NUM) IF TL <> 11 and TL <> 13 THEN MSGBOX "WRONG NUMBER." & TL EXIT FUNCTIONEND IFIF TL = 11 THEN TL = TL 2 NUM = "86" & NUMEND IFOR 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 & Ltemnext Titelc = TTEMEND FUNCTION

The mobile phone number has two representations: 11 bits and 13 bits (with national code 86), the general mobile phone is expressed in 13-bit form, so the above functions have a function to automatically convert 11-bit format mobile phone number. For 13-bit form, then convert to a PDU string. 2 SMS send mobile phone SMS transmission mainly by means of VB's MSComm control, with a detailed introduction to the MSCOMM control, the previous technical introduction section. The sending of SMS is done by the AT CMGS instruction, and the PDU mode is transmitted, the function code is as follows:

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 Dimleth 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 (ASG)) PDU = Prex & PSMSC & MIDX & PNUM & SUFX & Leng & Pmsgsleep (1) Mobcomm.output = "AT CMGF = 0" VBCR MOBCOMM.output = "AT CMGS = "& STR (15 length) vbcrMobcomm.output = PDU & ChR $ (26) Sleep (1) sendsms = trueEnd function Because the mobile phone can only handle one thing, this function is only responsible for sending SMS, about SMS send Successfully or not, and the part of the reading SMS is set together. It is determined whether the SMS transmission success is mainly determined by the AT CMGS command to perform the subsequent return code (see the AT instruction section of the foregoing). In order to prevent the phone from mistakenly because it is too busy, there is a certain way to make the phone have sufficient time to process the send and receive and delete the operation. The SLEEP () function is designed for this, and the program will be suspended after sending and deleting the operation, so that the phone is too busy. SMS reception 2 Unicode code decoding function is compared with the send SMS transmission, the main job of the mobile phone SMS receives the opposite. SMS transmission needs to convert the SMS content to be sent to a Unicode code, while the SMS receives the received Unicode code to a Chinese character. The following functions will implement decoding. Like the encoding function sent by SMS, this also applies a VB built-in function ascw () function to convert Unicode code to Chinese:

Public Function Ascg (SMSG As String) AS STRINGDIM SI, SB AS INTEGERDIM STMP AS INTEGERDIM STEMP AS STRINGSB = 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 as ascg = ascg & strumpnext siascg = trim (ascg) end function

2 The SMS reception function is quite simple to receive the SMS, and only the following three lines of code are required. However, the technology it uses is never transmitted more than SMS, which mainly uses the Output property of the MSCOMM control and the AT CMGR command. Public Sub Readsms (Rnum As String) Mobcomm.output = "AT CMGF = 1" VBCRMOBCOMM.output = "AT CMGR =" & RNUM VBCREND SUB

转载请注明原文地址:https://www.9cbs.com/read-33033.html

New Post(0)