Use python to implement sms pdu encoding and python SMS pdu Encoding

Source: Internet
Author: User

Use python to implement sms pdu encoding and python SMS pdu Encoding

A few days ago, I started a 3G module, and then I went backwards. You need to send text messages in both Chinese and English, so the PDU mode is used (not familiar with google pai_^ ).

The biggest problem is of course splicing PDU encoding (python is so powerful, maybe there are modules), rather find a smspdu module (link: https://pypi.python.org/pypi/smspdu ). However, the test found that the generated encoding and module documentation have different requirements ...... But you can still look at the implementation of the source code. The rest is to process it by yourself. The Code is as follows:

From smspdu import SMS_SUBMITdef format_message (phone_number, message_content): tpdu = [] if phone_number and message_content: # + 8613010112500 indicates the SMS center number, you can use the AT command to query pdu = SMS_SUBMIT.create ('+ 100', phone_number, message_content) #00: Set to use the default SMS center number, 11: normal GSM format, 00: Default sending number tpdu. append ('200') #91: + 001100 format 81: 8613000000000 format formatAddress = pdu. encodeAddress (). replace ('0b91 ', '0b81') tpdu. append (formatAddress) #00: Protocol identifier. 00 indicates the common GSM type. 18: The encoding method is UCS2. 01: Valid time tpdu. append ('000000') # The length of the text message content is subject to the unicode encoding tpdu of the text message content. append ('% 02x' % pdu. tp_udl) tpdu. append (''. join (['% 02x' % ord (c) for c in pdu. tp_ud]) return ''. join (tpdu)

  

The rest is sent through the AT command.

This is the son of the old thin family. If you need to reprint it, please declare that I would like to thank you for your support.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.