Send a short message via mobile phone on the PC (continuation)

zhaozj2021-02-16  47

After writing << On the PC, send a short message through the mobile phone >> (http://www.9cbs.net/develop/Article/17/17690.shtm), it is planned to write the sending of Chinese short information, but graduation The paper is really tight, has been delayed, and there are several netizens who have sent me a few days, and the netizens who pay attention to this topic are also more, and the 9CBS mail journal will also include my article. I have included. I feel very pleased, and I feel that I should complete my unfinished work as soon as possible, or I am too sorry.

Using the Text mode to send and receive the text message code, it is very easy to implement, but the biggest shortcoming is that it is not a bit beautiful. However, the PDU mode can solve this problem, the PDU mode not only supports Chinese text messages, but also send English text messages. It is perfect. PDU mode Send message can be used: 7-bit, 8-bit and ucs2 encoding. 7-bit encoding is used to send a normal ASCII character, 8-bit encoding is usually used to send data messages, ucs2 Encoding is used to send Unicode characters. We have to achieve the sending of Chinese SMS, so choose UCS2, ie Chinese Unicode Code.

First introduce two functions in VB: ChRW () and ASCW (). For chr () and ASC () functions, you must be familiar, and for chRW () and ASCW () may compare a bit. Chrw function returns to include Unicode's String, if there is no support for Unicode's platform, its function is the same as the CHR function; the ASCW function returns the Unicode character code. If the platform does not support Unicode, the same is the same as the ASC function. For these two functions, we will give an example:? ASCW ("Short") 30701? Chrw (26482) 杲

It can be seen that these two functions can implement the conversion between Chinese and Unicode codes, which is very convenient for our coding decoding. After we get a Chinese Unicode code, you can prepare a PDU string.

We learned about the composition of the PDU string, we saw such a PDU string (I used to debug the procedure): 089168311030140517170D91680015977ED 4F4002C8BF756DE590D002E. We break down to:

08 SMSC address information (91683110301405f0 total eight byte) 91 SMSC address format (TON / NPI) 683110301405F0 SMSC address (8613010341500 Nanjing SMS service center number) 11 Basic parameters (TP-MTI / VFP) (send, received 84) 00 MR message Reference0D target SIM card number length (683159717456F4 by the number of Arabic numerals meter) 91 Ibid 683159717456F4 other phone SIM card number (8613057575064) 00 ordinary GSM type, point the way 08 UCS2 coding period 00 16 user information length (5982679C6536523077ED4FE1002C8BF756DE590D002E The length of 22 is byte) 5982679C653652307ED4FE1002C8BF756DE590D002E ("If you receive a SMS, please reply." Unicode code)

After the PDU code, we have already understood, we can start coding, the red part above is what we want to encode.

First, see SMSC address: 683110301405F0 and 8613010341500F (SMSC last fill f constitute 14 bits), we can find that only the parity bits can be invisible. Similarly: 683159717456F4 and 8613057575064 are also the same processing.

For the user information length, we can get the LEN function in VB, such as "Hello", we use Len ("Hello") to get 2, then 2 * 2 = 4 is the user information length 04 (here you want to convert To 16 Encontinence, and two). For Unicode, we can get out of its Unicode code by an ASCW () function.

The specific implementation code sent by SMS is given below (relevant knowledge can be seen before): if mscomm1.portopen = false kilnsm1.portopen = true length = LEN ("If you receive a SMS, please reply.") * 2 MSCOMM1 .Output = "aT CMGF = 0" vbCr 'mode messages sent Pdu MSComm1.Output = "aT CMGS =" & Str (15 length) vbCr MSComm1.Output = "0891683110301405F011000D91683159717456F4000800165982679C6536523077ED4FE1002C8BF756DE590D002E" & Chr $ (26) Start = Timer Pause = 1 While Timer

Here, the sending of the SMS is basically completed, and the reception of SMS is simpler, mainly decoding, is the application of the chrw () function. After writing this article, it will be loosened, it is a good intention, thank you. Everyone's attention.

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

New Post(0)