|
发表于 2022-5-6 01:28:16
|
显示全部楼层
百度一下,python手机验证
- 1 # 接口类型:互亿无线触发短信接口,支持发送验证码短信、订单通知短信等。
- 2 # 账户注册:请通过该地址开通账户http://sms.ihuyi.com/register.html
- 3 # 注意事项:
- 4 # (1)调试期间,请用默认的模板进行测试,默认模板详见接口文档;
- 5 # (2)请使用APIID(查看APIID请登录用户中心->验证码短信->产品总览->APIID)及 APIkey来调用接口;
- 6 # (3)该代码仅供接入互亿无线短信接口参考使用,客户可根据实际需要自行编写;
- 7
- 8 # !/usr/local/bin/python
- 9 # -*- coding:utf-8 -*-
- 10 import http.client
- 11 import urllib
- 12
- 13 host = "106.ihuyi.com"
- 14 sms_send_uri = "/webservice/sms.php?method=Submit"
- 15
- 16 # 用户名是登录用户中心->验证码短信->产品总览->APIID
- 17 account = "xxxxxxx"
- 18 # 密码 查看密码请登录用户中心->验证码短信->产品总览->APIKEY
- 19 password = "xxxxxxxxxxxxxxxx"
- 20
- 21
- 22 def send_sms(text, mobile):
- 23 params = urllib.parse.urlencode(
- 24 {'account': account, 'password': password, 'content': text, 'mobile': mobile, 'format': 'json'})
- 25 headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
- 26 conn = http.client.HTTPConnection(host, port=80, timeout=30)
- 27 conn.request("POST", sms_send_uri, params, headers)
- 28 response = conn.getresponse()
- 29 response_str = response.read()
- 30 conn.close()
- 31 return response_str
- 32
- 33
- 34 if __name__ == '__main__':
- 35 # 手机号
- 36 mobile = "13111111111"
- 37 text = "您的验证码是:121254。请不要把验证码泄露给其他人。"
- 38
- 39 print(send_sms(text, mobile))
复制代码 |
|