"PYTHON" Blue 253 Cloud communication platform International SMS API interface Demo

Source: Internet
Author: User

#!/usr/local/bin/python
#- -Coding:utf-8--

author:jackytime:14-2-22 pm 11:48desc: Python code invocation example for SMS HTTP interface

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 ():
"""
Take account 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

def send_sms (text, phone):
"""
can send text messages with the interface
"""

If name = = 'main':
#手机号码, Format (area code + mobile number), for example: 8615800000000, where 86 is China's area code
Phone = "8615800000000"
Text = "253 Cloud Communication" Your verification code is 1234 "

#查账户余额print(get_user_balance())#调用智能匹配模版接口发短信print(send_sms(text, phone))

Ruby

Note: The following code is only for the convenience of customer testing and provide the sample code, the customer can according to their own needs to write the code for Learning and research interface only for use, but provides a reference

Require ' net/http '
Require ' URI '
Require ' JSON '

params = {
"Account" = "",
"Password" = "a.123456",

Mobile phone number, format (area code + mobile number), for example: 8615800000000, of which 86 is China's area code
"mobile" => "8615800000000",   

}.to_json

def send_data (Url,data)
url = uri.parse (URL)
req = net::http::P ost.new (url.path,{' content-type ' = ' Application/json '})
Req.body = Data
res = net::http.new (url.host,url.port). start{|http| http.request (req)}

puts res.body                                                                                                  

End

Send_data (' Http://intapi.253.com/send/json ', params)

"PYTHON" Blue 253 Cloud communication platform International SMS API interface Demo

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.