python-gsmmodem 介绍
Python实现的短信发送/接收库,支持多种型号的短信猫。主要功能有:
示例
短信接收和回复
#!/usr/bin/env python """\ Demo: handle incoming SMS messages by replying to them Simple demo app that listens for incoming SMS messages, displays the sender's number and the messages, then replies to the SMS by saying "thank you" """ from __future__ import print_function import logging PORT = '/dev/ttyUSB2' BAUdratE = 115200 PIN = None # SIM card PIN (if any) from gsmmodem.modem import GsmModem def handleSms(sms): print(u'== SMS message received ==\nFrom: {0}\nTime: {1}\nMessage:\n{2}\n'.format(sms.number, sms.time, sms.text)) print('Replying to SMS...') sms.reply(u'SMS received: "{0}{1}"'.format(sms.text[:20], '...' if len(sms.text) > 20 else '')) print('SMS sent.\n') def main(): print('Initializing modem...') # Uncomment the following line to see what the modem is doing: logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG) modem = GsmModem(PORT, BAUdratE, smsReceivedCallbackFunc=handleSms) modem.smsTextMode = False modem.connect(PIN) print('Waiting for SMS message...') try: modem.rxThread.join(2**31) # Specify a (huge) timeout so that it essentially blocks indefinitely, but still receives CTRL+C interrupt signal finally: modem.close(); if __name__ == '__main__': main()
python-gsmmodem 官网
https://github.com/faucamp/python-gsmmodem
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。