Home > Article > Backend Development > SMS API interface calling example based on aggregated data-Python version
Apply for opening the SMS API through self-service https://www.juhe.cn/docs/api/id/54 and obtain the interface request Key. (Currently the interface only supports enterprise users)
After applying, submit the SMS template in the personal center. The official website has provided a number of commonly used templates, which can be quickly applied for.
Please refer to the official interface document: <strong class="keylink">Http</strong>s://www.juhe.cn/docs/api/id/54
#!/usr/bin/Python # -*- coding: utf-8 -*- import urllib, urllib2, sys, JSON reload(sys) sys.setdefaultencoding('utf-8') url = 'http://v.juhe.cn/sms/send' params = { "mobile": "13429667914",# 接收短信的用户手机号码 "tpl_id": "12341234",# 您申请的短信模板ID,根据实际情况修改 "tpl_value": "#code#=1235231",# 您设置的模板变量,根据实际情况修改,如无变量可留空 "key": "您申请的ApiKey",# 您申请的短信API接口请求Key } querys = urllib.urlencode(params) request = urllib2.Request(url, data=querys) response = urllib2.urlopen(request) content = response.read() if (content): try: result = json.loads(content) error_code = result['error_code'] if (error_code == 0): message_id = result['result']['sid'] print("请求成功,短信ID:%s" % message_id) else: print("请求失败:%s %s" % (result['error_code'], result['reason'])) except Exception as e: print("解析结果异常:%s" % e) else: # 可能网络异常等问题,无法获取返回内容,请求异常 print("请求异常")
The above is the detailed content of SMS API interface calling example based on aggregated data-Python version. For more information, please follow other related articles on the PHP Chinese website!