温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

【Python】短信验证码平台查询账户余额demo---创蓝253云通讯平台案例

发布时间:2020-04-10 14:36:02 来源:网络 阅读:543 作者:创蓝253 栏目:编程语言

#!/usr/local/bin/python
#-- coding:utf-8 --

Author: jacky

Time: 14-2-22 下午11:48

Desc: 短信http接口的python代码调用示例

import httplib
import urllib
import json
#服务地址
host = "intapi.253.com"

#端口号
port = 80

#版本号
version = "v1.1"

#查账户信息的URI
balance_get_uri = "/balance/json"

#智能匹配模版短信接口的URI
sms_send_uri = "/send/json"

#创蓝账号
account = ""

#创蓝密码
password = ""

def get_user_balance():
"""
取账户余额
"""
params = {'account': account, 'password' : password}
params=json.dumps(params)

headers = {"Content-type": "application/json"}
conn = httplib.HTTPConnection(host, port=port)
conn.request('POST', balance_get_uri, params, headers)
response = conn.getresponse()
response_str = response.read()
conn.close()
return response_str

def send_sms(text, phone):
"""
能用接口发短信
"""

params = {'account': account, 'password' : password, 'msg': urllib.quote(text), 'mobile':phone, 'report' : 'false'}
params=json.dumps(params)

headers = {"Content-type": "application/json"}
conn = httplib.HTTPConnection(host, port=port, 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':
#手机号码,格式(区号+手机号码),例如:8615800000000,其中86为中国的区号
phone = "8615800000000"
text = "【253云通讯】您的验证码是1234"

#查账户余额
print(get_user_balance())
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI