zoukankan      html  css  js  c++  java
  • python3短信接口使用

     

    复制代码
    import http.client
    from urllib import parse
    
    host  = "106.ihuyi.com"
    sms_send_uri = "/webservice/sms.php?method=Submit"
    
    #用户名是登录用户中心->验证码短信->产品总览->APIID
    account  = APIID           # 登陆自己的账号获取
    #密码 查看密码请登录用户中心->验证码短信->产品总览->APIKEY
    password = APIKEY          # 登陆自己的账户获取
    
    def send_sms(text, mobile):
        params = parse.urlencode({'account': account, 'password' : password, 'content': text, 'mobile':mobile,'format':'json' })
        headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
        conn = http.client.HTTPConnection(host, port=80, timeout=30)
        conn.request("POST", sms_send_uri, params, headers)
        response = conn.getresponse()
        response_str = response.read()
        conn.close()
        return response_str
    
    if __name__ == '__main__':
    
        mobile = "173****7825"          # 要发送验证码的手机号
        text = "您的验证码是:"+ mobile[7:] +"。请不要把验证码泄露给其他人。"     
      # 短信内容的模板必须和后台定义的一样,可以吧随机生成的验证码通过眸中和方式返回前端页面 print(send_sms(text, mobile))
    复制代码
  • 相关阅读:
    Programming Contest Ranking(题解)
    Alphabet Cookies
    hpu 1267 Cafeteria (01背包)
    Triangles 正多边形分割锐角三角形
    ACdream 1067:Triangles
    hdu 1253 胜利大逃亡 (代码详解)解题报告
    最短路
    POJ- 1511 Invitation Cards
    E
    HDU
  • 原文地址:https://www.cnblogs.com/magicking/p/8985593.html
Copyright © 2011-2022 走看看