云片网发送短信验证码

1、注册json

 “开发认证”-->>“签名管理”-->>“模板管理”api

 还要添加iP白名单,测试就用本地ip,部署的时候必定要换成服务器的ip服务器

2、发送验证码app

apps下新建utils文件夹。再新建yunpian.py,代码以下:post

# apps/utils/yunpian.py

import requests
import json

class YunPian(object):

    def __init__(self, api_key):
        self.api_key = api_key
        self.single_send_url = "https://sms.yunpian.com/v2/sms/single_send.json"

    def send_sms(self, code, mobile):
        #须要传递的参数
        parmas = {
            "apikey": self.api_key,
            "mobile": mobile,
            "text": "【慕雪生鲜超市】您的验证码是{code}。如非本人操做,请忽略本短信".format(code=code)
        }

        response = requests.post(self.single_send_url, data=parmas)
        re_dict = json.loads(response.text)
        return re_dict

if __name__ == "__main__":
    #例如:9b11127a9701975c734b8aee81ee3526
    yun_pian = YunPian("2e87d1xxxxxx7d4bxxxx1608f7c6da23exxxxx2")
    yun_pian.send_sms("2018", "手机号码")
相关文章
相关标签/搜索