python开发阿里大于短信

一、在阿里开发者中心https://dayu.aliyun.com/注册短信相关信息,具体步骤详见:

https://mp.csdn.net/postedit/88638980

二、python中代码部分

具体使用详见https://help.aliyun.com/document_detail/101874.html?spm=a2c4g.11186623.6.627.7c6c166aNQtRYg

1、安装阿里大于相关包

(1)、如果您使用Python 2.x,执行以下命令,安装阿里云SDK核心库:

pip install aliyun-python-sdk-core

如果您使用Python 3.x,执行以下命令,安装阿里云SDK核心库:

pip install aliyun-python-sdk-core-v3

(2)、以下是安装云服务器ECS的SDK示例:

pip install aliyun-python-sdk-ecs

以下是安装云服务器ECS的SDK示例:

pip install aliyun-python-sdk-ecs

 2、修改代码

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest


def sendSms():

    client = AcsClient('LTAINuG3d3rmYXZ4', 'g6gX7j2IlvL3BgVry8y9nX2wZYoMbU', 'cn-hangzhou')

    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('RegionId', 'cn-hangzhou')
    // 手机号码
    request.add_query_param('PhoneNumbers', '15388888888')
    // 填写标记名称,将以【哈哈】显示在短信信息里
    request.add_query_param('SignName', '哈哈')
    // 模板的信息,在页面申请的模板信息里面查看
    request.add_query_param('TemplateCode', 'SMS_********')
    // 发送的短信验证码123456,code是模板里${code}中的code,名称要相同
    request.add_query_param('TemplateParam', '{"code":"123456"}')

    response = client.do_action_with_exception(request)
    print(str(response, encoding='utf-8'))

if __name__ == "__main__":
    sendSms()

https://www.cnblogs.com/wuyan717/p/9318091.html

猜你喜欢

转载自blog.csdn.net/weixin_41996632/article/details/88667192