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))
    复制代码
  • 相关阅读:
    视频聊天相关技术介绍
    block相关归纳
    block的作用
    block教程
    向appstore提交app流程
    ios xmpp 发送语音图片解决方案
    python 三元运算、列表推倒式、字典推倒式、生成器生成式
    python 生成器
    python 迭代器(第二次总结)
    python 迭代器
  • 原文地址:https://www.cnblogs.com/magicking/p/8985593.html
Copyright © 2011-2022 走看看