model_train_dm/backend/apps/common/utils/yunpian.py

31 lines
726 B
Python
Raw Normal View History

2026-07-27 17:51:49 +08:00
# -*- coding:utf-8 -*-
import json
import requests
class YunPian:
"""云片网短信验证"""
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, mobile, code):
params = {
"apikey": self.api_key,
"mobile": mobile,
"text": "云片网模板文件内容{code}".format(code=code),
}
response = requests.post(self.single_send_url, data=params)
return_dict = json.loads(response.text)
return return_dict
if __name__ == "__main__":
yunpian = YunPian("云片网的api_key")
yunpian.send_sms("手机号码", "验证码")