发送手机验证码

一、

# 榛子云短信 http://smsow.zhenzikj.com/
# 13085384230 112116
#  AppId  AppSecret
# 107045  f1020eb4-a1b1-43ac-9b99-e55b0ebb69b3
# 进入官网下载相关SDK:zhenzismsclient.py

# 1.安装
# 1)安装requests模块,SDK需要依赖该模块。安装方法:
# pip install requests
#
# 2)安装SDK,下载后的SDK只包含一个zhenzismsclient.py文件,直接导入到工程中即可使用。


import requests
import json
from requests.packages.urllib3.exceptions import InsecureRequestWarning


class ZhenziSmsClient(object):
    def __init__(self, apiUrl, appId, appSecret):
        self.apiUrl = apiUrl
        self.appId = appId
        self.appSecret = appSecret

    def send(self, params):
        data = params
        data['appId'] = self.appId
        data['appSecret'] = self.appSecret
        if ('templateParams' in data):
            data['templateParams'] = json.dumps(data['templateParams'])
        requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
        response = requests.post(self.apiUrl + '/sms/v2/send.do', data=data, verify=False)
        result = str(response.content, 'utf-8')
        return result

    def balance(self):
        data = {
            'appId': self.appId,
            'appSecret': self.appSecret
        }
        requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
        response = requests.post(self.apiUrl + '/account/balance.do', data=data, verify=False)
        result = str(response.content, 'utf-8')
        return result

    def findSmsByMessageId(self, messageId):
        data = {
            'appId': self.appId,
            'appSecret': self.appSecret,
            'messageId': messageId
        }
        requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
        response = requests.post(self.apiUrl + '/smslog/findSmsByMessageId.do', data=data, verify=False)
        result = str(response.content, 'utf-8')
        return result


# -------------------------
# -下面代码是自己写的
apiUrl = 'https://sms_developer.zhenzikj.com'
# apiUrl = 'https://sms.zhenzikj.com'
# apiUrl为请求地址,个人开发者使用https://sms_developer.zhenzikj.com,企业开发者使用https://sms.zhenzikj.com
appId = '107045'
appSecret = 'f1020eb4-a1b1-43ac-9b99-e55b0ebb69b3'
client = ZhenziSmsClient(apiUrl, appId, appSecret)

params = {}
params['number'] = '15559609300'
params['templateId'] = '2111'  # 短信模板ID,登录用户中心,在"短信管理->短信模板"中创建,并查看
params['templateParams'] = ['9988', '5分钟']  # 要发送的内容,由自己生成,9988是验证码,5分钟是失效时间,服务器会套用模板
print(client.send(params))

 

上一篇:成语答题小程序如何搭建


下一篇:[Windows 8 App]2014跨年晚会 上架啰!!