Home  >  Article  >  Backend Development  >  Introduction to the method of sending text messages in Python (with code)

Introduction to the method of sending text messages in Python (with code)

不言
不言forward
2019-03-09 14:15:385892browse

This article brings you an introduction to the method of sending text messages in Python (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

#First register with Huyi Wireless, then copy the apiid and apikey in the upper right corner of the text messaging interface and replace the account and password in the code
#APIID: 1

#APIKEY: a9
#Interface type: Huyi wireless trigger SMS interface, supports sending verification code SMS, order notification SMS, etc.
# Account registration: Please open an account through this address http://sms.ihuyi.com/register.html
# Notes:
# (1) During debugging, please use the default template for testing , please refer to the interface document for the default template;
# (2) Please use the APIID (to view the APIID, please log in to the user center->Verification code SMS->Product Overview->APIID) and APIkey to call the interface;
#(3) This code is only for reference when accessing the Huyi wireless SMS interface. Customers can write it themselves according to actual needs;

#!/usr/local/bin/python
#-
- coding:utf-8 -
-
import http.client
import urllib
host  = “106.ihuyi.com”
sms_send_uri = “/webservice/sms.php?method=Submit”
#用户名是登录用户中心->验证码短信->产品总览->APIID
account  = “1”
#密码 查看密码请登录用户中心->验证码短信->产品总览->APIKEY
password = “a9”
def send_sms(text, mobile):
params = urllib.parse.urlencode({‘account’: account, ‘password’ : password, ‘content’: text, ‘mobile’:mobile,‘format’:‘json’ })
headers = {“Content-type”: “application/x-www-form-urlencoded”, “Accept”: “text/plain”}
conn = http.client.HTTPConnection(host, port=80, timeout=30)
conn.request(“POST”, sms_send_uri, params, headers)
response = conn.getresponse()
response_str = response.read()
conn.close()
return response_str

if name == 'main':

mobile = "1879431006*"
text = "您的验证码是:110110。请不要把验证码泄露给其他人。"

print(send_sms(text, mobile))

The above is the detailed content of Introduction to the method of sending text messages in Python (with code). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete