【Python】短信验证码平台查询账户余额demo---创蓝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())

原文地址:http://blog.51cto.com/13567544/2150142

时间: 2024-08-25 12:57:39

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

创蓝253云通讯平台---短信验证码接口说明

1协议说明 名称 说明 协议 HTTP POST 编码格式 UTF8 Content-Type application/json URL http://xxx/msg/send/json 或者 https://xxx/msg/send/json 完整地址请登录253云通讯自助通平台或者询问您的商务负责人获取 接口说明 此接口一次可提交不超过1000个手机号码. 2 请求包体 包体为json字符串,参数如下: { "account" : "N6000001", //用

【PYTHON】创蓝253云通讯平台国际短信API接口DEMO

#!/usr/local/bin/python#-- coding:utf-8 -- Author: jacky Time: 14-2-22 下午11:48 Desc: 短信http接口的python代码调用示例 import httplibimport urllibimport json#服务地址 host = "intapi.253.com" #端口号port = 80 #版本号version = "v1.1" #查账户信息的URIbalance_get_uri

【C(C++)】创蓝253云通讯平台国际短信API接口DEMO

#include <arpa/inet.h>#include <assert.h>#include <errno.h>#include <netinet/in.h>#include <signal.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <sys/types.h>#include <sys/socke

【shell】创蓝253云通讯平台国际短信API接口DEMO

#!/bin/sh account and password can be change to what you wanna! #author ChuangLan#修改为您的accountaccount=""#修改为您的pwpassword="a.123456"#手机号码,格式(区号+手机号码),例如:8615800000000,其中86为中国的区号mobile="8615800000000"#设置您要发送的内容msg="[253云通讯

【ASP】创蓝253云通讯平台国际短信API接口DEMO

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% Function Post(url,data) dim Https set Https=server.createobject("MSXML2.XMLHTTP") Https.open "POST",url,false Https.setRequestHeader "Content-Type",&qu

创蓝253云通讯paas平台Python短信接口demo

#!/usr/local/bin/python#-- coding:utf-8 -- Author: jacky Time: 14-2-22 下午11:48 Desc: 短信http接口的python代码调用示例 import httplibimport urllib #服务地址host = "sms.253.com" #端口号port = 80 #版本号version = "v1.1" #查账户信息的URIbalance_get_uri = "/msg/

创蓝253云通讯短信平台变量说明

253云通讯变量说明文档1 变量短信发送用户通过HTTP的POST方式提交短信发送请求.1.1 系统提交URL地址http://sms.253.com/msg/HttpVarSM1.2 参数定义序号 参数 说明1 account 用户账号2 pswd 用户密码3 msg 短信模板.其中的变量用"{$var}"来替代.例如:"{$var},你好!,请你于{$var}日参加活动",该短信中具有两个变量参数.编码为UTF-8格式.最多支持20个{$var}4 params

【ASP】创蓝253云通讯paas平台短信验证码接口调用demo

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%><%Function Post(url,data)dim Https set Https=server.createobject("MSXML2.XMLHTTP")Https.open "POST",url,falseHttps.setRequestHeader "Content-Type","ap

【PHP】创蓝253云通信平台国际短信接口调用demo案例

PHP接口请求类<?phpheader("Content-type:text/html; charset=UTF-8"); / 类名:ChuanglanSmsApi 功能:创蓝接口请求类 详细:构造创蓝短信接口请求,获取远程HTTP数据 版本:1.3 日期:2017-04-12 说明: 以下代码只是为了方便客户测试而提供的样例代码,客户可以根据自己网站的需要,按照技术文档自行编写,并非一定要使用该代码. 该代码仅供学习和研究创蓝接口使用,只是提供一个参考.*/ class Chu