2025-03-18 08:46:50 +08:00

43 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/python
#coding: utf-8
# +-------------------------------------------------------------------
# | system: django-vue-lyadmin
# +-------------------------------------------------------------------
# | Author: lybbn
# +-------------------------------------------------------------------
# | QQ: 1042594286
# +-------------------------------------------------------------------
# ------------------------------
# 云片网发短信api
# ------------------------------
# 官网文档地址https://www.yunpian.com/dev-doc
# ------------------------------
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__":
# 例如8111127a9701975c734b8aee81ee3521
yun_pian = YunPian("3e87d1xxxxxx7d4bxxxx1608f7c6da23exxxxx1")
yun_pian.send_sms("2021", "手机号码")