标签:head name ack /usr start urllib one strong 格式
#!/usr/local/bin/pythonimport 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())
#调用智能匹配模版接口发短信
print(send_sms(text, phone))
RUBY
require ‘net/http‘
require ‘uri‘
require ‘json‘
params = {
"account" => "",
"password" => "a.123456",
"mobile" => "8615800000000",
"msg" =>URI::escape("【253云通讯】您好,您的验证码是999999")
}.to_json
def send_data(url,data)
url = URI.parse(url)
req = Net::HTTP::Post.new(url.path,{‘Content-Type‘ => ‘application/json‘})
req.body = data
res = Net::HTTP.new(url.host,url.port).start{|http| http.request(req)}
puts res.body
end
send_data(‘http://intapi.253.com/send/json‘,params)
【PYTHON】创蓝253云通讯平台国际短信API接口DEMO
标签:head name ack /usr start urllib one strong 格式
原文地址:http://blog.51cto.com/13750674/2134074