kboss/b/pub/sms_send_code.dspy
2025-07-16 14:27:17 +08:00

27 lines
1.2 KiB
Plaintext

async def sms_send_code(ns={}):
"""发送短信"""
db = DBPools()
async with db.sqlorContext('kboss') as sor:
vcode_sql = "select * from sms_record where mobile = '%s' and send_type = '用户注册登录验证' order by send_time desc limit 1;" % ns.get('mobile')
vcode_li = await sor.sqlExe(vcode_sql, {})
if vcode_li:
date_str = vcode_li[0]['send_time']
target_datetime = datetime.datetime.strptime(date_str, '%Y-%m-%d %H:%M:%S')
delta = datetime.datetime.now() - target_datetime
# 限制每分钟发送一次
if delta.total_seconds() < 60:
return {
'status': False,
'msg': '发送失败, 频繁发送短信',
'time': int(delta.total_seconds())
}
if ns.get('mobile'):
code = await generate_vcode()
print('code: ', code)
nss = await send_vcode(ns.get('mobile'), '用户注册登录验证', {'code': code.get('vcode')})
return nss
else:
return {'status': False, 'msg': '没有该用户或手机号错误'}
ret = await sms_send_code(params_kw)
return ret