zoukankan      html  css  js  c++  java
  • 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)
  • 相关阅读:
    VMware 8安装Mac OS X 10.7 Lion正式版
    linq to sql sum
    拍照,去相册剪切图片
    Binding for WPF Styles
    JDK1.8简单配置环境变量两步曲
    hibernate系列之四
    idea中使用逆向工程三部曲
    hibernate系列之一
    hibernate系列之二
    《JSON笔记之二》封装JSONUtil
  • 原文地址:https://www.cnblogs.com/wanghaokun/p/10517516.html
Copyright © 2011-2022 走看看