美文网首页
python 阿里云短信发送

python 阿里云短信发送

作者: 朱佩奇被占用 | 来源:发表于2020-08-05 13:17 被阅读0次

简单的阿里云短信推送
前提需要在阿里云短信服务中注册短信模板,通过审核,完成后记下签名名字,随后便可以引用一下代码进行编写调试

def _send_sms_ali(mobiles, tpl_code, tpl_params):
    client = AcsClient('AccessKey', 'Access Key Secret', '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', mobiles)
    request.add_query_param('SignName', "签名")
    request.add_query_param('TemplateCode', tpl_code)
    request.add_query_param('TemplateParam', tpl_params)

    response = client.do_action_with_exception(request)
    # python2:  print(response)
    print(str(response, encoding='utf-8'))
    response=str(response, encoding='utf-8')
    response=json.loads(response)
    if response['Message'] == 'OK':
        return True
    else:
        return False

相关文章

网友评论

      本文标题:python 阿里云短信发送

      本文链接:https://www.haomeiwen.com/subject/zrjsrktx.html