feat(sms): 集成腾讯云短信插件并打通双端短信验证码业务链路

- 插件管理:集成 qcloudsms 腾讯云短信发送插件,配置应用AppID/AppKey、短信签名及各业务模板ID(登录、修改密码、重置密码、支付密码、订单核销通知)
- 业务封装:新增 SmsService 统一业务短信服务,实现防刷限流、冷却控制、短信验证码发送与防重放校验,支持完工订单自动下发客户核销码
- 接口层:恢复并升级 Sms 控制器,并在 Auth/MasterAuth/Security 控制器中支持手机验证码登录、找回登录密码及短信验证设置/修改支付密码
- 小程序端:用户端与师傅端登录页、账号安全中心、支付密码组件全面适配短信验证码交互,优化用户找回密码与支付密码安全操作流程
- 部署脚本:优化 deploy_all.py 打包剪枝逻辑,全局过滤深层 .git 目录并规范打包相对路径
这个提交包含在:
2026-11-26 15:54:15 +08:00
父节点 3baa02771a
当前提交 c664d0a5de
共有 34 个文件被更改,包括 4023 次插入 和 160 次删除

查看文件

@@ -16,7 +16,7 @@ class Sms
* 验证码有效时长
* @var int
*/
protected static $expire = 120;
protected static $expire = 300;
/**
* 最大允许检测的次数
@@ -24,6 +24,39 @@ class Sms
*/
protected static $maxCheckNums = 10;
/**
* 最近一次发送失败原因
* @var mixed
*/
protected static $lastError = '';
/**
* 获取最近一次发送失败原因
* @return mixed
*/
public static function getLastError()
{
return self::$lastError;
}
/**
* 从短信插件提取错误信息
*/
protected static function captureAddonError()
{
self::$lastError = '';
try {
if (function_exists('get_addon_instance')) {
$addon = get_addon_instance('qcloudsms');
if ($addon && method_exists($addon, 'getError')) {
self::$lastError = $addon->getError();
}
}
} catch (\Throwable $e) {
self::$lastError = $e->getMessage();
}
}
/**
* 获取最后一次手机发送的数据
*
@@ -50,12 +83,14 @@ class Sms
*/
public static function send($mobile, $code = null, $event = 'default')
{
self::$lastError = '';
$code = is_null($code) ? Random::numeric(config('fastadmin.sms_captcha_length') ?: 6) : $code;
$time = time();
$ip = request()->ip();
$sms = \app\common\model\Sms::create(['event' => $event, 'mobile' => $mobile, 'code' => $code, 'ip' => $ip, 'createtime' => $time]);
$result = Hook::listen('sms_send', $sms, null, true);
if (!$result) {
self::captureAddonError();
$sms->delete();
return false;
}
@@ -65,19 +100,27 @@ class Sms
/**
* 发送通知
*
* @param mixed $mobile 手机号,多个以,分隔
* @param string $msg 消息内容
* @param string $template 消息模板
* @param mixed $mobile 手机号,多个以,分隔
* @param string $msg 消息内容
* @param string $template 消息模板
* @param array $templateParams 模板参数列表
* @return boolean
*/
public static function notice($mobile, $msg = '', $template = null)
public static function notice($mobile, $msg = '', $template = null, array $templateParams = [])
{
self::$lastError = '';
$params = [
'mobile' => $mobile,
'msg' => $msg,
'template' => $template
'template' => $template,
];
if (!empty($templateParams)) {
$params['params'] = array_values($templateParams);
}
$result = Hook::listen('sms_notice', $params, null, true);
if (!$result) {
self::captureAddonError();
}
return (bool)$result;
}
@@ -137,7 +180,7 @@ class Sms
->setInc('times');
// 验证码不匹配
if ($code != $sms['code']) {
if (!hash_equals((string)$sms['code'], (string)$code)) {
Db::commit(); // 提交次数增加
return false;
}