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 次删除

查看文件

@@ -2,6 +2,10 @@
namespace app\api\controller;
use app\common\library\AccountSecurity;
use app\common\library\SmsService;
use app\common\library\Token;
use fast\Random;
use think\Db;
use think\Validate;
@@ -10,7 +14,7 @@ use think\Validate;
*/
class Auth extends Base
{
protected $noNeedLogin = ['login', 'wxlogin', 'wxPhoneLogin'];
protected $noNeedLogin = ['login', 'wxlogin', 'wxPhoneLogin', 'sendResetPasswordSms', 'resetPasswordBySms'];
/**
* 手机号 + 密码登录(仅支持账号密码或微信一键登录,短信验证码通道已移除)
@@ -73,6 +77,104 @@ class Auth extends Base
]);
}
/**
* 发送忘记登录密码短信验证码(H5/未登录找回密码)
* @ApiMethod (POST)
*/
public function sendResetPasswordSms()
{
try {
$mobile = SmsService::normalizeMobile((string)$this->request->post('mobile', ''));
} catch (\InvalidArgumentException $e) {
$this->error($e->getMessage());
return;
}
$user = Db::name('user')->field('id,status')->where('mobile', $mobile)->find();
if (!$user) {
$this->error('该手机号尚未注册账号');
return;
}
if (isset($user['status']) && $user['status'] !== 'normal') {
$this->error('账号已被禁用');
return;
}
try {
$res = SmsService::sendVerifyCode($mobile, 'user_resetpwd', $this->request->ip());
$this->success('验证码已发送,请注意查收', array_merge($res, [
'mobile' => substr_replace($mobile, '****', 3, 4),
]));
} catch (\Throwable $e) {
$this->error($e->getMessage());
}
}
/**
* 通过短信验证码重置登录密码(忘记密码)
* @ApiMethod (POST)
*/
public function resetPasswordBySms()
{
try {
$mobile = SmsService::normalizeMobile((string)$this->request->post('mobile', ''));
} catch (\InvalidArgumentException $e) {
$this->error($e->getMessage());
return;
}
$smsCode = trim((string)$this->request->post('sms_code', $this->request->post('captcha', '')));
$newPassword = (string)$this->request->post('new_password', '');
if (!preg_match('/^\S{6,30}$/', $newPassword)) {
$this->error('登录密码须为6至30位非空字符');
return;
}
$user = Db::name('user')->field('id,status')->where('mobile', $mobile)->find();
if (!$user) {
$this->error('该手机号尚未注册账号');
return;
}
if (isset($user['status']) && $user['status'] !== 'normal') {
$this->error('账号已被禁用');
return;
}
try {
SmsService::verifyCode($mobile, $smsCode, 'user_resetpwd', true);
} catch (\Throwable $e) {
$this->error($e->getMessage());
return;
}
$uid = (int)$user['id'];
$salt = Random::alnum();
$encrypted = $this->auth->getEncryptPassword($newPassword, $salt);
Db::startTrans();
try {
Db::name('user')->where('id', $uid)->update([
'password' => $encrypted,
'salt' => $salt,
'loginfailure' => 0,
'updatetime' => time(),
]);
AccountSecurity::ensure($uid);
Db::name('user_security')->where('user_id', $uid)->update([
'failed_attempts' => 0,
'locked_until' => 0,
]);
Token::clear($uid);
Db::commit();
} catch (\Throwable $e) {
Db::rollback();
$this->error('密码重置失败,请稍后重试');
return;
}
$this->success('登录密码重置成功,请使用新密码登录');
}
/**
* 我的信息(含角色与师傅状态)
*/