`

Python3调用阿里短信api发送短信

阅读更多

阿里提供的短信通道api给的参考是Python2.X版的,然而对于Python3.x版本,也同样适用

 

阿里接口调用文档:https://market.aliyun.com/products/57002003/cmapi011900.html#item-1

 

 

Python3代码示例如下:

import urllib.request
import urllib3
from urllib import parse

def getClient():
    urllib3.disable_warnings()
    http = urllib3.PoolManager()
    return http
querys={
    'ParamString':{"name":"肖先生"},    #消息体参数
    'RecNum':'18515555555,13917777777',   #手机号码,用逗号隔开
    'SignName':'Python科技',     # 短信签名名称
    'TemplateCode':'SMS_33465621'  #短信模板编号
}
querys=parse.urlencode(querys)
host = 'http://sms.market.alicloudapi.com'
path = '/singleSendSms'
method = 'GET'
appcode = '2d1d*****49484eb*****cdf24974f1945'
bodys = {}
url = host + path + '?' + querys
req = urllib.request.Request(url)
header={'Authorization':'APPCODE '+appcode}
req=getClient().request('GET', url, headers=header)

 这里没有写上回调发送状态,如果需要可以补充上去

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics