Python 调取短信验证码平台---创蓝253云通讯平台

0
Python C/C++ Go 2958 次浏览

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

 

 

请尽量让自己的答案能够对别人有帮助

7个答案

默认排序 按投票排序
0

Sleek work you have here. smart homes uk   smart homes uk

0

北京开发者中心 http://010kfzzx.wikidot.com/
广州开发者中心 http://020kfzzx.wikidot.com/
上海开发者中心 http://021kfzzx.wikidot.com/
成都开发者中心 http://028kfzzx.wikidot.com/
西安开发者中心 http://029kfzzx.wikidot.com/
天津开发者中心 http://022kfzzx.wikidot.com/
重庆开发者中心 http://023kfzzx.wikidot.com/
沈阳开发者中心 http://024kfzzx.wikidot.com/
南京开发者中心 http://025kfzzx.wikidot.com/
武汉开发者中心 http://027kfzzx.wikidot.com/
昆明开发者中心 http://0871kfzzx.wikidot.com/
东莞开发者中心 http://0769kfzzx.wikidot.com/
深圳开发者中心 http://0755kfzzx.wikidot.com/
惠州开发者中心 http://0752kfzzx.wikidot.com/
连云港开发者中心 http://0518kfzzx.wikidot.com/

0


I have never seen a provider goes to the extremes that these guys do to help you get on board smoothly and help you get up and running quickly. Krunker

0

Hello, I would like to thank you for sharing this interesting information. As for me, it's quite correct that PYTHON makes such kind of verification. I had some experience related to it and I like it. It helped me in my https://ratewritingservices.com/review/mid-terms-com-review.html sample project.

0

Python is one language well suited to a beginner, and it is also widely used professionally, so a good choice. There are lots of tutorials and helpful Python and programming communities, use them.  Programming is simply based on logic. If you have the great sense of logic, you can start with virtually any language, along with.Net, Java etc. ... Students can still choose PYTHON as their first language, even without any programming background. It is because PYTHON has consistent and simple syntax and the vast library.  Visit this essay writing site.

 

0
Python is one language well suited to a beginner, and it is also widely used professionally, so a good choice. There are lots of tutorials and helpful Python and programming communities, use them.
0

Python can be really confusing at times. It reminds me of playing miniclip8.