雲片網發送短信驗證碼

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", "手機號碼")
相關文章
相關標籤/搜索