阿里云短信接口调用

风格不统一 提交于 2019-12-01 12:14:09

阿里云国内短信调用接口

#!/usr/bin/env python
#coding=utf-8


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

accessKeyId = '企业的app_id'
accessSecret = '企业的秘钥'

client = AcsClient(accessKeyId, accessSecret, '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', '18611111111')
request.add_query_param('SignName', '北京木瓜互娱科技有限公司')
request.add_query_param('TemplateCode', 'SMS_162440786')
request.add_query_param('TemplateParam', "{'code':'111111111111'}")

response = client.do_action(request)
# python2:  print(response)
print(str(response, encoding = 'utf-8'))

结果调用成功:'code' : 'ok'

 

 

 

阿里云国际短信d

#!/usr/bin/env python
#coding=utf-8


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

accessKeyId = '企业的app_id'
accessSecret = '企业的accessSecret'

client = AcsClient(accessKeyId, accessSecret, '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', '18611111111')
request.add_query_param('SignName', '北京木瓜互娱科技有限公司')
request.add_query_param('TemplateCode', 'SMS_162199937')
request.add_query_param('TemplateParam', "{'code':'111111111111'}")

response = client.do_action(request)
# python2:  print(response)
print(str(response, encoding = 'utf-8'))

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!