PYTHON HTTP

#!/usr/local/bin/python


#-*- coding:utf-8 -*-

import httplib
import urllib
 
#服务地址
host = "www.jianzhou.sh.cn"
 
#端口号
port = 80
 

 
#短信接口的URI
send_uri = "/JianzhouSMSWSServer/http/sendBatchMessage"
 
#账号
account  = "xxxx"
 
#密码
psw = "xxxx"
 
 
def send_sms(text, phone):
    """
    能用接口发短信
    """
    params = urllib.urlencode({'account': account, 'password' : psw, 'msgText': text, 'destmobile':phone})
    headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
    conn = httplib.HTTPConnection(host, port=port, timeout=30)
    conn.request("POST", send_uri, params, headers)
    response = conn.getresponse()
    response_str = response.read()
    conn.close()
    return response_str
 
if __name__ == '__main__':
 
    phone = "139xxxxxxxx"
    text = "【建周科技】您的验证码是1234"

 
    #调接口发短信
    print(send_sms(text, phone))