This commit is contained in:
mkm 2024-06-22 17:21:25 +08:00
commit a9be9ec500
5 changed files with 51 additions and 3 deletions

View File

@ -17,8 +17,7 @@ class LoginController extends BaseApiController
*/
public function account()
{
$params=$this->request->post();
// $params = (new LoginAccountValidate())->post()->goCheck();
$params = (new LoginAccountValidate())->post()->goCheck();
$result = LoginLogic::login($params);
if (false === $result) {
return $this->fail(LoginLogic::getError());

View File

@ -18,6 +18,7 @@ use think\Exception;
*/
class UserController extends BaseApiController
{
public $notNeedLogin = ['login_sms'];
// #[
// ApiDoc\Title('获取小程序手机号'),
// ApiDoc\url('/api/user/user/getMobileByMnp'),
@ -143,6 +144,17 @@ class UserController extends BaseApiController
}
return $this->fail('发送失败');
}
public function login_sms()
{
$params = (new UserValidate())->post()->goCheck('login');
$res = (new UserLogic())->dealLoginSms($params['account']);
if ($res){
return $this->success('发送成功');
}
return $this->fail('发送失败');
}

View File

@ -188,6 +188,21 @@ class UserLogic extends BaseLogic
}
public function dealLoginSms($phone)
{
$code = generateRandomCode();
$template = getenv('SMS_LOGIN_TEMPLATE');
$check =(new SmsService())->client($phone,$template,$code);
if($check){
$remark = $phone.'_login';
Cache::set($remark,$code,5*60);
return true;
}else{
return false;
}
}

View File

@ -5,12 +5,15 @@ namespace app\api\validate;
use app\common\cache\UserAccountSafeCache;
use app\common\enum\LoginEnum;
use app\common\enum\notice\NoticeEnum;
use app\common\enum\PayEnum;
use app\common\enum\user\UserTerminalEnum;
use app\common\enum\YesNoEnum;
use app\common\service\ConfigService;
use app\common\service\sms\SmsDriver;
use app\common\validate\BaseValidate;
use app\common\model\user\User;
use support\Cache;
use think\Exception;
use Webman\Config;
/**
* 账号密码登录校验
@ -138,10 +141,20 @@ class LoginAccountValidate extends BaseValidate
*/
public function checkCode($code, $rule, $data)
{
$remark = $data['account'].'_login';
$code = Cache::get($remark);
if(empty($code)){
return '验证码不存在';
}
if (isset($data['code']) && $code != $data['code']) {
return '验证码错误';
}
return true;
// $smsDriver = new SmsDriver();
// $result = $smsDriver->verify($data['account'], $code, NoticeEnum::LOGIN_CAPTCHA);
// if ($result) {
// return true;
// return true;
// }
// return '验证码错误';
}

View File

@ -22,6 +22,7 @@ class UserValidate extends BaseValidate
'password' => 'require',
'rePassword' => 'require',
'type' => 'require',
'account' => 'require',
];
@ -30,11 +31,19 @@ class UserValidate extends BaseValidate
'store_id.require' => '门店id',
'mobile.require' => '手机',
'phone.require' => '手机',
'account.require' => '手机',
'password.require' => '密码',
'rePassword.require' => '确认密码',
'type' => '查询类型',
];
public function sceneLogin()
{
return $this->only(['account']);
}
public function sceneFund()
{
return $this->only(['type']);