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

不言
Release: 2019-03-09 14:15:38
forward
5974 people have browsed it

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
Copy after login
host  = “106.ihuyi.com”
sms_send_uri = “/webservice/sms.php?method=Submit”
Copy after login
#用户名是登录用户中心->验证码短信->产品总览->APIID
account  = “1”
#密码 查看密码请登录用户中心->验证码短信->产品总览->APIKEY
password = “a9”
Copy after login
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
Copy after login

if name == 'main':

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

print(send_sms(text, mobile))
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template