feat(sms): 集成腾讯云短信插件并打通双端短信验证码业务链路
- 插件管理:集成 qcloudsms 腾讯云短信发送插件,配置应用AppID/AppKey、短信签名及各业务模板ID(登录、修改密码、重置密码、支付密码、订单核销通知) - 业务封装:新增 SmsService 统一业务短信服务,实现防刷限流、冷却控制、短信验证码发送与防重放校验,支持完工订单自动下发客户核销码 - 接口层:恢复并升级 Sms 控制器,并在 Auth/MasterAuth/Security 控制器中支持手机验证码登录、找回登录密码及短信验证设置/修改支付密码 - 小程序端:用户端与师傅端登录页、账号安全中心、支付密码组件全面适配短信验证码交互,优化用户找回密码与支付密码安全操作流程 - 部署脚本:优化 deploy_all.py 打包剪枝逻辑,全局过滤深层 .git 目录并规范打包相对路径
这个提交包含在:
@@ -2,6 +2,7 @@
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\library\AccountSecurity;
|
||||
use app\common\library\SmsService;
|
||||
use app\common\library\WxLogin;
|
||||
use app\common\library\TencentVerifyService;
|
||||
use app\common\library\EnterpriseLicenseImage;
|
||||
@@ -14,27 +15,70 @@ class Security extends Base
|
||||
$user = Db::name('user')->field('password,mobile')->where('id', $this->uid())->find();
|
||||
$security = Db::name('user_security')->where('user_id', $this->uid())->find();
|
||||
$cert = Db::name('user_enterprise_cert')->where('user_id', $this->uid())->find();
|
||||
$rawMobile = trim((string)($user['mobile'] ?? ''));
|
||||
$maskedMobile = strlen($rawMobile) === 11
|
||||
? (substr($rawMobile, 0, 3) . '****' . substr($rawMobile, -4))
|
||||
: $rawMobile;
|
||||
$this->success('', [
|
||||
'has_login_password' => !empty($user['password']),
|
||||
'has_payment_password' => $security && $security['payment_password_hash'] !== '',
|
||||
'mobile' => $maskedMobile,
|
||||
'enterprise_cert' => $cert ?: null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送修改登录密码短信验证码(给当前登录账号绑定的手机号发送)
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function sendPasswordSms()
|
||||
{
|
||||
$uid = $this->uid();
|
||||
$rawMobile = (string)Db::name('user')->where('id', $uid)->value('mobile');
|
||||
try {
|
||||
$mobile = SmsService::normalizeMobile($rawMobile);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->error('当前账号尚未绑定有效手机号,无法发送短信验证码');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$res = SmsService::sendVerifyCode($mobile, 'user_changepwd', $this->request->ip());
|
||||
$this->success('验证码已发送至绑定手机', array_merge($res, [
|
||||
'mobile' => substr_replace($mobile, '****', 3, 4),
|
||||
]));
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function changeLoginPassword()
|
||||
{
|
||||
$uid = $this->uid();
|
||||
$new = (string)$this->request->post('new_password', '');
|
||||
$old = (string)$this->request->post('old_password', '');
|
||||
$smsCode = trim((string)$this->request->post('sms_code', ''));
|
||||
$verifyMode = trim((string)$this->request->post('verify_mode', $smsCode !== '' ? 'sms' : 'old_password'));
|
||||
if (!preg_match('/^\S{6,30}$/', $new)) $this->error('登录密码须为6至30位非空字符');
|
||||
$user = Db::name('user')->field('password')->where('id', $uid)->find();
|
||||
$user = Db::name('user')->field('password,mobile')->where('id', $uid)->find();
|
||||
if (!empty($user['password'])) {
|
||||
try { AccountSecurity::verify($uid, 'login', $old); } catch (\Throwable $e) { $this->error($e->getMessage()); }
|
||||
$ignoreOld = false;
|
||||
if ($verifyMode === 'sms') {
|
||||
try {
|
||||
SmsService::verifyCode((string)($user['mobile'] ?? ''), $smsCode, 'user_changepwd', true);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$ignoreOld = true;
|
||||
} else {
|
||||
try { AccountSecurity::verify($uid, 'login', $old); } catch (\Throwable $e) { $this->error($e->getMessage()); }
|
||||
$ignoreOld = false;
|
||||
}
|
||||
} else {
|
||||
$ignoreOld = true;
|
||||
}
|
||||
if (!$this->auth->changepwd($new, $old, $ignoreOld)) $this->error($this->auth->getError() ?: '设置失败');
|
||||
AccountSecurity::ensure($uid);
|
||||
Db::name('user_security')->where('user_id', $uid)->update(['failed_attempts' => 0, 'locked_until' => 0]);
|
||||
\app\common\library\Token::clear($uid);
|
||||
$this->success('登录密码已更新,请重新登录');
|
||||
}
|
||||
@@ -50,15 +94,59 @@ class Security extends Base
|
||||
$this->success('支付密码设置成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送修改/重置支付密码短信验证码(给当前登录账号绑定的手机号发送)
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function sendPaymentPasswordSms()
|
||||
{
|
||||
$uid = $this->uid();
|
||||
$rawMobile = (string)Db::name('user')->where('id', $uid)->value('mobile');
|
||||
try {
|
||||
$mobile = SmsService::normalizeMobile($rawMobile);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->error('当前账号尚未绑定有效手机号,无法发送短信验证码');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$res = SmsService::sendVerifyCode($mobile, 'user_paypwd', $this->request->ip());
|
||||
$this->success('验证码已发送至绑定手机', array_merge($res, [
|
||||
'mobile' => substr_replace($mobile, '****', 3, 4),
|
||||
]));
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function changePaymentPassword()
|
||||
{
|
||||
$uid = $this->uid();
|
||||
$new = (string)$this->request->post('new_password', '');
|
||||
if (!preg_match('/^\d{6}$/', $new)) $this->error('支付密码须为6位数字');
|
||||
AccountSecurity::ensure($uid);
|
||||
$oldHash = (string)Db::name('user_security')->where('user_id', $uid)->value('payment_password_hash');
|
||||
try { AccountSecurity::verify($uid, 'payment', (string)$this->request->post('old_password', '')); }
|
||||
catch (\Throwable $e) { $this->error($e->getMessage()); }
|
||||
$updated = Db::name('user_security')->where('user_id', $uid)->where('payment_password_hash', $oldHash)->update(['payment_password_hash' => password_hash($new, PASSWORD_DEFAULT)]);
|
||||
if ($oldHash === '') {
|
||||
$this->error('尚未设置支付密码,请先设置支付密码');
|
||||
}
|
||||
$smsCode = trim((string)$this->request->post('sms_code', ''));
|
||||
$verifyMode = trim((string)$this->request->post('verify_mode', $smsCode !== '' ? 'sms' : 'old_password'));
|
||||
if ($verifyMode === 'sms') {
|
||||
$mobile = (string)Db::name('user')->where('id', $uid)->value('mobile');
|
||||
try {
|
||||
SmsService::verifyCode($mobile, $smsCode, 'user_paypwd', true);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
} else {
|
||||
try { AccountSecurity::verify($uid, 'payment', (string)$this->request->post('old_password', '')); }
|
||||
catch (\Throwable $e) { $this->error($e->getMessage()); }
|
||||
}
|
||||
$updated = Db::name('user_security')->where('user_id', $uid)->where('payment_password_hash', $oldHash)->update([
|
||||
'payment_password_hash' => password_hash($new, PASSWORD_DEFAULT),
|
||||
'payment_failed_attempts' => 0,
|
||||
'payment_locked_until' => 0,
|
||||
]);
|
||||
if (!$updated) $this->error('支付密码已变更,请重新操作');
|
||||
$this->success('支付密码修改成功');
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户