PHP調用創藍253國際短信驗證碼
阿新 • • 發佈:2018-05-15
PHP 創藍253 短信驗證碼 國際短信 #!/usr/local/bin/python
#-- coding:utf-8 --
#-- 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
創藍253雲通訊平臺---國際短信接口調用demo
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))
PHP調用創藍253國際短信驗證碼