阿里云短信验证码API接口

阿里云短信验证码接口网站:https://market.aliyun.com/products/57124001/cmapi00037170.html?spm=5176.2020520132.101.20.1e047218HnYIPU#sku=yuncode3117000001

请求参数:

阿里云短信验证码API接口

随机四位数验证码源码

import urllib, sys import ssl import urllib.request as urllib2 import random def messageAPI(phone): host = \'https://dfsns.market.alicloudapi.com\' path = \'/data/send_sms\' method = \'POST\' appcode = \'这里填你的code,购买后会有\' querys = \'\' bodys = {} url = host + path # 随机生成四位数验证码 code=random.randint(1000,9999) bodys[\'content\'] = \'\'\'code:{},expire_at:5\'\'\'.format(code) bodys[\'phone_number\'] = phone bodys[\'template_id\'] = \'\'\'TPL_0001\'\'\' post_data = urllib.parse.urlencode(bodys).encode("utf-8") request = urllib2.Request(url, post_data) request.add_header(\'Authorization\', \'APPCODE \' + appcode) # //根据API的要求,定义相对应的Content-Type request.add_header(\'Content-Type\', \'application/x-www-form-urlencoded; charset=UTF-8\') ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE response = urllib2.urlopen(request, context=ctx) content = response.read() if (content): print("发送手机号为:{},验证码为:{}".format(phone,code)) return phone,code

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzyfjz.html