当前位置:   article > 正文

python发送短信内容_通过Python发送短信

短信发送者 python

我正在使用以下代码连接到手机以发送短消息:import serial

import time

phone = serial.Serial()

phone.baudrate = 38400

phone.bytesize = 8

phone.stopbits = 1

phone.xonxoff = 0

phone.rtscts = 0

phone.timeout = 0

phone.port = 3 #try different ports here, if this doesn't work.

phone.parity=serial.PARITY_NONE

phone.open()

print phone.portstr

recipient = "+929409778"

message = "We did it!"

print ("I did come after it")

try:

time.sleep(0.5)

phone.write(b'ATZ\r')

time.sleep(0.5)

phone.write(b'AT+CMGF=1\r')

time.sleep(0.5)

phone.write(b'AT+CMGS="' + recipient.encode() + b'"\r')

time.sleep(0.5)

phone.write(message.encode() + b"\r")

print (message)

time.sleep(0.5)

phone.write(bytes([26]))

time.sleep(0.5)

phone.readall()

finally:

phone.close()

我可以连接电话,但无法发送消息。它没有给我一个错误,所以我不知道从哪里开始调试。在

我的代码有什么问题我没有看到吗?在

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/493811
推荐阅读
相关标签
  

闽ICP备14008679号