Implementing SMS PDU encoding using Python

Source: Internet
Author: User

Tag: Message code NIC number submit add BSP phone creat

A few days ago to start a 3G module, then daoteng a bit. Need to send mixed SMS in Chinese and English, so use PDU mode (do not know Google ^_^).

The biggest problem of course is splicing PDU code (Python is so powerful, maybe a module), sure enough to find a SMSPDU module (link: HTTPS://PYPI.PYTHON.ORG/PYPI/SMSPDU). But the test found that the generated coding and module documentation requirements are different, tears rush ... But you can still look at the source of the implementation of the way. The rest is to process it yourself. No wordy, on the code:

From SMSPDU import sms_submitdef format_message (Phone_number, message_content): TPDU = [] if Phone_number and Message_co    Ntent: #+8613010112500 is the SMS center number, can be queried by the AT command PDU = sms_submit.create (' +8613010112500 ', Phone_number, message_content)  #00: Set Use default SMS center number, 11: Normal GSM format, 00: Default send Number Tpdu.append (' 001100 ') #91: +8613000000000 format 81:13 billion format formataddress = Pdu.encodeaddress (). Replace (' 0b91 ', ' 0b81 ') tpdu.append (formataddress) #00: protocol ID, 00 for general GSM type, 18: encoding mode for UCS2; 01: Effective Time Tpdu.append (' 000801 ') #短信内容长度接短信内容unicode编码 tpdu.append ('%02x '% pdu.tp_udl) tpdu.append ('. Join (['%02 X '% ord (c) for C in Pdu.tp_ud])) return '. Join (TPDU)

  

The rest is sent through the AT command.

Here is the son of old thin family, if need to reprint please declare, I thank you for old thin.

Implementing SMS PDU encoding using Python

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.