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

#!/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
摘要由CSDN通过智能技术生成

#!/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))

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值