C114门户论坛百科APPEN| 举报 切换到宽版

亚星游戏官网

 找回密码
 注册

只需一步,快速开始

短信验证,便捷登录

搜索
查看: 4906|回复: 0

[xDSL] 短信验证码接口调用demo [复制链接]

军衔等级:

亚星游戏官网-yaxin222  新兵

注册:2018-2-1
发表于 2018-3-7 16:44:36 |显示全部楼层
基于创蓝253云通讯平台的短信接口demo:


#!/usr/local/bin/python
#-*- coding:utf-8 -*-
# Author: jacky
# Time: 14-2-22 下午11:48
# Desc: 短信http接口的python代码调用示例
import httplib
import urllib

#服务地址
host = "sms.253.com"

#端口号
port = 80

#版本号
version = "v1.1"

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

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

#创蓝253账号
un  = "xxxx"

#创蓝密码
pw = "xxxx"

def get_user_balance():
    """
    取账户余额
    """
    conn = httplib.HTTPConnection(host, port=port)
    conn.request('GET', balance_get_uri + "?un=" + un +"&pw=" + pw)
    response = conn.getresponse()
    response_str = response.read()
    conn.close()
    return response_str

def send_sms(text, phone):
    """
    能用接口发短信
    """
    params = urllib.urlencode({'un': un, 'pw' : pw, 'msg': text,'phone':phone, 'rd' : '1'})
    headers = {"Content-type":"application/x-www-form-urlencoded", "Accept":"text/plain"}
    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__':

    phone = "188xxxxxxxx"
    text = "【创蓝253云通讯】您的验证码是1234"

    #查账户余额
    print(get_user_balance())

    #调用智能匹配模版接口发短信
    print(send_sms(text, phone))



举报本楼

您需要登录后才可以回帖 登录 | 注册 |

手机版|C114 ( 沪ICP备12002291号-1 )|联系大家 |网站地图  

GMT+8, 2024-11-26 09:30 , Processed in 0.166377 second(s), 15 queries , Gzip On.

Copyright © 1999-2023 C114 All Rights Reserved

Discuz Licensed

回顶部
XML 地图 | Sitemap 地图