feat(sms): 集成腾讯云短信插件并打通双端短信验证码业务链路
- 插件管理:集成 qcloudsms 腾讯云短信发送插件,配置应用AppID/AppKey、短信签名及各业务模板ID(登录、修改密码、重置密码、支付密码、订单核销通知) - 业务封装:新增 SmsService 统一业务短信服务,实现防刷限流、冷却控制、短信验证码发送与防重放校验,支持完工订单自动下发客户核销码 - 接口层:恢复并升级 Sms 控制器,并在 Auth/MasterAuth/Security 控制器中支持手机验证码登录、找回登录密码及短信验证设置/修改支付密码 - 小程序端:用户端与师傅端登录页、账号安全中心、支付密码组件全面适配短信验证码交互,优化用户找回密码与支付密码安全操作流程 - 部署脚本:优化 deploy_all.py 打包剪枝逻辑,全局过滤深层 .git 目录并规范打包相对路径
这个提交包含在:
@@ -4,7 +4,9 @@ namespace app\api\controller;
|
||||
|
||||
use app\common\library\MasterSecurity;
|
||||
use app\common\library\MasterToken;
|
||||
use app\common\library\SmsService;
|
||||
use app\common\library\WxLogin;
|
||||
use fast\Random;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
@@ -12,7 +14,7 @@ use think\Db;
|
||||
*/
|
||||
class MasterAuth extends MasterBase
|
||||
{
|
||||
protected $noNeedLogin = ['login', 'wxPhoneLogin'];
|
||||
protected $noNeedLogin = ['login', 'wxPhoneLogin', 'sendResetPasswordSms', 'resetPasswordBySms'];
|
||||
|
||||
/**
|
||||
* 师傅手机号 + 密码登录(H5调试/账号密码通道)
|
||||
@@ -173,7 +175,129 @@ class MasterAuth extends MasterBase
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置或修改师傅登录密码(未设置时直接设置,已设置时需校验原密码)
|
||||
* 发送师傅端忘记登录密码短信验证码
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function sendResetPasswordSms()
|
||||
{
|
||||
try {
|
||||
$mobile = SmsService::normalizeMobile((string)$this->request->post('mobile', ''));
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->error($e->getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
$master = Db::name('master')->field('id,status')->where('mobile', $mobile)->find();
|
||||
if (!$master) {
|
||||
$this->error('该手机号尚未注册师傅账号');
|
||||
return;
|
||||
}
|
||||
if (isset($master['status']) && $master['status'] !== 'normal') {
|
||||
$this->error('师傅账号已被禁用');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$res = SmsService::sendVerifyCode($mobile, 'master_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;
|
||||
}
|
||||
|
||||
$master = Db::name('master')->field('id,status')->where('mobile', $mobile)->find();
|
||||
if (!$master) {
|
||||
$this->error('该手机号尚未注册师傅账号');
|
||||
return;
|
||||
}
|
||||
if (isset($master['status']) && $master['status'] !== 'normal') {
|
||||
$this->error('师傅账号已被禁用');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
SmsService::verifyCode($mobile, $smsCode, 'master_resetpwd', true);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
$mid = (int)$master['id'];
|
||||
$salt = Random::alnum();
|
||||
$encrypted = $this->masterAuth->getEncryptPassword($newPassword, $salt);
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
Db::name('master')->where('id', $mid)->update([
|
||||
'loginfailure' => 0,
|
||||
'password' => $encrypted,
|
||||
'salt' => $salt,
|
||||
'updatetime' => time(),
|
||||
]);
|
||||
MasterSecurity::ensure($mid);
|
||||
Db::name('master_security')->where('master_id', $mid)->update([
|
||||
'failed_attempts' => 0,
|
||||
'locked_until' => 0,
|
||||
]);
|
||||
MasterToken::clear($mid);
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
$this->error('密码重置失败,请稍后重试');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->success('登录密码重置成功,请使用新密码登录');
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送修改师傅登录密码短信验证码(给当前绑定手机号发送)
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function sendPasswordSms()
|
||||
{
|
||||
$mid = $this->masterId();
|
||||
$rawMobile = (string)Db::name('master')->where('id', $mid)->value('mobile');
|
||||
try {
|
||||
$mobile = SmsService::normalizeMobile($rawMobile);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->error('当前师傅账号尚未绑定有效手机号,无法发送短信验证码');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$res = SmsService::sendVerifyCode($mobile, 'master_changepwd', $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 changeLoginPassword()
|
||||
@@ -181,18 +305,29 @@ class MasterAuth extends MasterBase
|
||||
$mid = $this->masterId();
|
||||
$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位非空字符');
|
||||
}
|
||||
|
||||
$master = Db::name('master')->field('password')->where('id', $mid)->find();
|
||||
$master = Db::name('master')->field('password,mobile')->where('id', $mid)->find();
|
||||
if (!empty($master['password'])) {
|
||||
try {
|
||||
MasterSecurity::verify($mid, 'login', $old);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
if ($verifyMode === 'sms') {
|
||||
try {
|
||||
SmsService::verifyCode((string)($master['mobile'] ?? ''), $smsCode, 'master_changepwd', true);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$ignoreOld = true;
|
||||
} else {
|
||||
try {
|
||||
MasterSecurity::verify($mid, 'login', $old);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$ignoreOld = false;
|
||||
}
|
||||
$ignoreOld = false;
|
||||
} else {
|
||||
$ignoreOld = true;
|
||||
}
|
||||
@@ -233,7 +368,32 @@ class MasterAuth extends MasterBase
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改师傅支付密码(需校验原支付密码)
|
||||
* 发送修改/重置师傅支付密码短信验证码(给当前绑定手机号发送)
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function sendPaymentPasswordSms()
|
||||
{
|
||||
$mid = $this->masterId();
|
||||
$rawMobile = (string)Db::name('master')->where('id', $mid)->value('mobile');
|
||||
try {
|
||||
$mobile = SmsService::normalizeMobile($rawMobile);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->error('当前师傅账号尚未绑定有效手机号,无法发送短信验证码');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$res = SmsService::sendVerifyCode($mobile, 'master_paypwd', $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 changePaymentPassword()
|
||||
@@ -243,16 +403,35 @@ class MasterAuth extends MasterBase
|
||||
if (!preg_match('/^\d{6}$/', $new)) {
|
||||
$this->error('支付密码须为6位数字');
|
||||
}
|
||||
MasterSecurity::ensure($mid);
|
||||
$oldHash = (string)Db::name('master_security')->where('master_id', $mid)->value('payment_password_hash');
|
||||
try {
|
||||
MasterSecurity::verify($mid, 'payment', (string)$this->request->post('old_password', ''));
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
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('master')->where('id', $mid)->value('mobile');
|
||||
try {
|
||||
SmsService::verifyCode($mobile, $smsCode, 'master_paypwd', true);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
MasterSecurity::verify($mid, 'payment', (string)$this->request->post('old_password', ''));
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
$updated = Db::name('master_security')
|
||||
->where('master_id', $mid)
|
||||
->where('payment_password_hash', $oldHash)
|
||||
->update(['payment_password_hash' => password_hash($new, PASSWORD_DEFAULT)]);
|
||||
->update([
|
||||
'payment_password_hash' => password_hash($new, PASSWORD_DEFAULT),
|
||||
'payment_failed_attempts' => 0,
|
||||
'payment_locked_until' => 0,
|
||||
]);
|
||||
if (!$updated) {
|
||||
$this->error('支付密码已变更,请重新操作');
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户