python发送短信验证码
-
安装阿里云SDK核心库
pip install aliyun-python-sdk-core
如果既安装有python2,也安装有python3,想在python3下使用pip
python3 -m pip install aliyun-python-sdk-core
-
demo
# !/usr/bin/env python3 # -*- coding: utf-8 -*- # 安装阿里云SDK核心库 # pip install aliyun-python-sdk-core # 或者 # python3 -m pip install aliyun-python-sdk-core # import json from aliyunsdkcore.client import AcsClient from aliyunsdkcore.request import CommonRequest client = AcsClient('AccessKeyID', 'AccessKeySecret', 'default') request = CommonRequest() request.set_accept_format('json') request.set_domain('dysmsapi.aliyuncs.com') request.set_method('POST') request.set_protocol_type('https') # https | http request.set_version('2017-05-25') request.set_action_name('SendSms') request.add_query_param('PhoneNumbers', '131xxxxxxx') request.add_query_param('SignName', '签名') request.add_query_param('TemplateCode', '模板Code') request.add_query_param('TemplateParam', '{"code":"111321"}') response = client.do_action(request) # {"Message":"OK","RequestId":"FA082529-2359-4591-AE27-308025871E77","BizId":"603312452300049031^0","Code":"OK"} # python2: print(response) #print(str(response, encoding = 'utf-8')) print(response) #字符串转json对象(字典) # res = json.loads(res)