feat(sms): 集成腾讯云短信插件并打通双端短信验证码业务链路
- 插件管理:集成 qcloudsms 腾讯云短信发送插件,配置应用AppID/AppKey、短信签名及各业务模板ID(登录、修改密码、重置密码、支付密码、订单核销通知) - 业务封装:新增 SmsService 统一业务短信服务,实现防刷限流、冷却控制、短信验证码发送与防重放校验,支持完工订单自动下发客户核销码 - 接口层:恢复并升级 Sms 控制器,并在 Auth/MasterAuth/Security 控制器中支持手机验证码登录、找回登录密码及短信验证设置/修改支付密码 - 小程序端:用户端与师傅端登录页、账号安全中心、支付密码组件全面适配短信验证码交互,优化用户找回密码与支付密码安全操作流程 - 部署脚本:优化 deploy_all.py 打包剪枝逻辑,全局过滤深层 .git 目录并规范打包相对路径
这个提交包含在:
@@ -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('登录密码重置成功,请使用新密码登录');
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的信息(含角色与师傅状态)
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,7 @@ use app\common\library\FinishImageUrls;
|
||||
use app\common\library\OrderStatus;
|
||||
use app\common\library\OrderQualification;
|
||||
use app\common\library\PaymentService;
|
||||
use app\common\library\SmsService;
|
||||
use app\common\library\TiandituService;
|
||||
use app\common\library\TencentVerifyService;
|
||||
use app\common\library\WxPayV3Service;
|
||||
@@ -1088,12 +1089,20 @@ class Master extends MasterBase
|
||||
$order = $this->ownOrder((int)$this->request->post('order_id'));
|
||||
$images = FinishImageUrls::normalize((array)$this->request->post('images/a', []));
|
||||
$damage = trim((string)$this->request->post('damage_remark', ''));
|
||||
$code = trim((string)($order['verify_code'] ?? ''));
|
||||
if ($code === '') {
|
||||
$code = str_pad((string)mt_rand(0, 999999), 6, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$this->transit($order, OrderStatus::PENDING_VERIFY, '师傅完工,等待客户验收', [
|
||||
$transitExtra = [
|
||||
'finish_time' => time(),
|
||||
], 'master', (int)$order['master_id']);
|
||||
];
|
||||
if ((string)($order['verify_code'] ?? '') === '') {
|
||||
$transitExtra['verify_code'] = $code;
|
||||
}
|
||||
$order = $this->transit($order, OrderStatus::PENDING_VERIFY, '师傅完工,等待客户验收', $transitExtra, 'master', (int)$order['master_id']);
|
||||
|
||||
foreach ($images as $url) {
|
||||
if (!$url) {
|
||||
@@ -1116,9 +1125,15 @@ class Master extends MasterBase
|
||||
$this->error('提交失败:' . $e->getMessage());
|
||||
}
|
||||
|
||||
$code = (string)$order['verify_code'];
|
||||
$this->notify('user', (int)$order['user_id'], '师傅已完工,待您验收', '验收码:' . $code . ',请核对后确认完成', 'order', (int)$order['id']);
|
||||
$this->success('已提交完工,等待客户验收');
|
||||
$smsResult = SmsService::sendOrderVerifyCode($order);
|
||||
$tip = $smsResult['sent']
|
||||
? '已提交完工,验收核销码已通过短信与消息通知客户'
|
||||
: '已提交完工,等待客户验收';
|
||||
$this->success($tip, [
|
||||
'sms_sent' => (bool)$smsResult['sent'],
|
||||
'sms_mobile_mask' => (string)$smsResult['mobile_mask'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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('支付密码已变更,请重新操作');
|
||||
}
|
||||
|
||||
@@ -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('支付密码修改成功');
|
||||
}
|
||||
|
||||
@@ -3,9 +3,12 @@
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\common\library\MasterAuth;
|
||||
use app\common\library\SmsService;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 手机短信接口(短信验证码通道已下线)
|
||||
* 手机短信接口
|
||||
*/
|
||||
class Sms extends Api
|
||||
{
|
||||
@@ -13,20 +16,101 @@ class Sms extends Api
|
||||
protected $noNeedRight = '*';
|
||||
|
||||
/**
|
||||
* 发送验证码(已移除)
|
||||
* 发送短信验证码
|
||||
* @ApiMethod (POST)
|
||||
* @ApiParams (name="mobile", type="string", required=true, description="手机号")
|
||||
* @ApiParams (name="event", type="string", required=true, description="事件名称")
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
$this->error('短信验证码通道已移除,请使用手机号密码或微信一键登录');
|
||||
$rawMobile = (string)$this->request->post('mobile', '');
|
||||
$event = trim((string)$this->request->post('event', ''));
|
||||
if ($event === '') {
|
||||
$event = 'user_resetpwd';
|
||||
}
|
||||
|
||||
try {
|
||||
$mobile = SmsService::normalizeMobile($rawMobile);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$this->error($e->getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!in_array($event, SmsService::ALLOWED_EVENTS, true)) {
|
||||
$this->error('不支持的短信验证码类型');
|
||||
return;
|
||||
}
|
||||
|
||||
if (in_array($event, ['changepwd', 'user_changepwd', 'paypwd', 'user_paypwd'], true)) {
|
||||
if (!$this->auth->isLogin()) {
|
||||
$this->error(__('Please login first'), null, 401);
|
||||
return;
|
||||
}
|
||||
$user = $this->auth->getUser();
|
||||
if (!$user || (string)$user['mobile'] !== $mobile) {
|
||||
$this->error('仅支持向当前账号绑定的手机号发送验证码');
|
||||
return;
|
||||
}
|
||||
} elseif (in_array($event, ['master_changepwd', 'master_paypwd'], true)) {
|
||||
$token = $this->request->server('HTTP_TOKEN', $this->request->request('token', ''));
|
||||
$masterAuth = MasterAuth::instance();
|
||||
if (!$token || !$masterAuth->init($token)) {
|
||||
$this->error(__('Please login first'), null, 401);
|
||||
return;
|
||||
}
|
||||
$master = $masterAuth->getMaster();
|
||||
if (!$master || (string)$master['mobile'] !== $mobile) {
|
||||
$this->error('仅支持向当前师傅账号绑定的手机号发送验证码');
|
||||
return;
|
||||
}
|
||||
} elseif (in_array($event, ['resetpwd', 'user_resetpwd'], true)) {
|
||||
$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;
|
||||
}
|
||||
} elseif ($event === 'master_resetpwd') {
|
||||
$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, $event, $this->request->ip());
|
||||
$this->success('验证码已发送,请注意查收', $res);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测验证码(已移除)
|
||||
* 检测短信验证码(不消耗验证码,仅预校验)
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$this->error('短信验证码通道已移除,请使用手机号密码或微信一键登录');
|
||||
$rawMobile = (string)$this->request->post('mobile', '');
|
||||
$event = trim((string)$this->request->post('event', ''));
|
||||
$captcha = trim((string)$this->request->post('captcha', $this->request->post('sms_code', '')));
|
||||
if ($event === '') {
|
||||
$event = 'user_resetpwd';
|
||||
}
|
||||
|
||||
try {
|
||||
SmsService::verifyCode($rawMobile, $captcha, $event, false);
|
||||
$this->success('验证码正确');
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户