標籤:head name ack /usr start urllib one strong 格式
#!/usr/local/bin/python
#-
- coding:utf-8 --
Author: jackyTime: 14-2-22 下午11:48Desc: 簡訊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())#調用智能匹配模版介面發簡訊print(send_sms(text, phone))
RUBY
說明:以下代碼只是為了方便客戶測試而提供的範例程式碼,客戶可以根據自己的需要另行編寫該代碼僅供學習和研究介面使用,只是提供了一個參考
require ‘net/http‘
require ‘uri‘
require ‘json‘
params = {
"account" => "",
"password" => "a.123456",
手機號碼,格式(區號+手機號碼),例如:8615800000000,其中86為中國的區號
"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