import ssl,json,random
from qcloudsms_py import SmsMultiSender, SmsSingleSender
from qcloudsms_py.httpclient import HTTPError
configInfo = json.load(open('config.json',encoding='utf-8'))
sms_appid = configInfo['sms']['appid']
sms_appkey = configInfo['sms']['appkey']
sms_sms_sign = configInfo['sms']['sms_sign']
#短信验证
def send_verify(phone):
appid = sms_appid # 自己应用ID
appkey = sms_appkey # 自己应用Key
sign = sms_sms_sign # 自己腾讯云创建签名时填写的签名内容(使用公众号的话这个值一般是公众号全称或简称)
sender = SmsSingleSender(appid, appkey)
template_id = "877799"
infoList = {}
str = ""
#六位随机数
for i in range(6):
ch = chr(random.randrange(ord('0'), ord('9') + 1))
str += ch
try:
response = sender.send_with_param(86, phone, template_id, [str], sign=sign)
infoList["code"] = 0
infoList['data'] = response
infoList['p_code'] = str
infoList['msg'] = "短信发送成功"
except Exception as e:
response = {'result': 1000, 'errmsg': "网络异常发送失败"}
infoList["code"] = 200
infoList['data'] = response
infoList['msg'] = "短信发送失败"
infoList['error'] = e.args
print(infoList)
return infoList
#群发短信
def mass_texting(phone_list, template_id, param_list):
appid = sms_appid # 自己应用ID
appkey = sms_appkey # 自己应用Key
sms_sign = sms_sms_sign # 自己腾讯云创建签名时填写的签名内容(使用公众号的话这个值一般是公众号全称或简称)
sender = SmsSingleSender(appid, appkey)
try:
response = sender.send_with_param(86, phone_list, template_id, param_list, sign=sms_sign)
except HTTPError as e:
response = {'result': 1000, 'errmsg': "网络异常发送失败"}
return response
06-29
1676
03-19
4454
02-20
797
10-28