标签:rom 验证码 NPU print ext __name__ parse reason 申请
import json
import requests
from urllib import parse
# 创建一个接口的函数
def sebdsms(appkey, mobile, tpl_id, tpl_value):
‘‘‘
:param appkey: 申请的短信接口的key值
:param mobile: 接收短信的手机号码
:param tpl_id: 短信模板
:param tpl_value: 验证码信息
:return:
‘‘‘
# 1. 请求接口的url
url = ‘http://v.juhe.cn/sms/send‘
# 参数的传递
params = ‘mobile={}&tpl_id={}&tpl_value={}&key={}‘.format(mobile, tpl_id, parse.quote(tpl_value), appkey)
# 2. 请求接口平台
wp = requests.get(url, params=params).text
result = json.loads(wp)
if result:
error_code = result[‘error_code‘]
if error_code == 0:
# 短信发送成功
smsid = result[‘result‘][‘sid‘]
print(‘短信验证码的ID:{}‘.format(smsid))
else:
print(‘短信发送失败....{}‘.format(result[‘reason‘]))
else:
print(‘请求接口平台失败...‘)
def main():
# 短信的appkey值
appkey = ‘聚合数据申请的appkey值‘
# 端接收人的号码
poth = input(‘请输入你要发送的号码:‘)
mobile = poth
# 短信模板ID
tpl_id = ‘170620‘
# 验证码
code = input(‘请输入你想要发送的验证码:‘)
tpl_value = ‘#code#={}‘.format(code)
sebdsms(appkey, mobile, tpl_id, tpl_value)
if __name__ == ‘__main__‘:
main(http://www.my516.com)
---------------------
标签:rom 验证码 NPU print ext __name__ parse reason 申请
原文地址:https://www.cnblogs.com/hyhy904/p/11182993.html