Browse Source

开启验证码验证登录

master
wanghongjun 11 months ago
parent
commit
bcdc0f92da
  1. 2
      app/controller/wechat/Base.php
  2. 8
      app/controller/wechat/Login.php
  3. 8
      app/controller/wechat/Wechat.php
  4. 5
      app/service/user/LoginService.php
  5. 2
      route/wechatRoute.php

2
app/controller/wechat/Base.php

@ -17,7 +17,7 @@ use think\Response;
class Base extends BaseController {
private $debug = [];
protected $noNeedLogin = [];
protected $noNeedLogin = ['sendSms'];
protected $user = [];
public $user_id = '';

8
app/controller/wechat/Login.php

@ -66,10 +66,10 @@ class Login extends Base
try {
$post = $this->request->post();
validate($this->valid)->scene('phoneLogin')->check($post);
// $res = (new AuthCodeUtil(new Redis()))->verifyCode($post['mobile'],$post['smsCode']);
// if (!$res) {
// throw new \Exception('短信验证码错误');
// }
$res = (new AuthCodeUtil(new Redis()))->verifyCode($post['phone'],$post['smsCode']);
if (!$res) {
throw new \Exception('短信验证码错误');
}
$loginServer = new LoginService();
$user = $loginServer->userPhoneLogin($post['phone']);
$user['token'] = $this->signToken($user);

8
app/controller/wechat/Wechat.php

@ -82,10 +82,10 @@ class Wechat extends Base
//$defaultSnsCode = '439764';
try {
validate(WechatUserValidate::class)->scene('savePuCode')->check($param);
// $res = (new AuthCodeUtil(new Redis()))->verifyCode($param['mobile'],$param['snsCode']);
// if (!$res) {
// throw new ValidateException('短信验证码错误');
// }
$res = (new AuthCodeUtil(new Redis()))->verifyCode($param['mobile'],$param['snsCode']);
if (!$res) {
throw new ValidateException('短信验证码错误');
}
} catch (ValidateException $e) {
return $this->buildFailed(ReturnCode::INVALID, $e->getMessage());
}

5
app/service/user/LoginService.php

@ -111,7 +111,7 @@ class LoginService extends BaseService
$field = 'id,openid,phone,nickname,sex,headimgurl';
$user = WechatUser::where('phone', $phone)->where('delete_time', 0)->field($field)->find();
if ($openid != $user->openid) {
WechatUser::where('id', $user->id)->save(['openid' => $user->openid]);
WechatUser::where('id', $user->id)->save(['openid' => $user->openid, 'unionid' => $unionid]);
}
if ($user) {
return $this->userSuccess($user);
@ -136,7 +136,8 @@ class LoginService extends BaseService
if ($user) {
return $this->userSuccess($user);
} else {
throw new FuncException('手机号错误');
return $this->register($phone, '', '');
//throw new FuncException('手机号错误');
}
}

2
route/wechatRoute.php

@ -16,7 +16,7 @@ Route::group('wechat', function() {
Route::rule('Login/wx', 'wechat.Login/wx', 'get');
Route::rule('Wechat/index', 'wechat.Wechat/index', 'get');
Route::rule('Wechat/savePuCode', 'wechat.Wechat/savePuCode', 'post')->middleware(WechatAuth::class);
Route::rule('Wechat/sendSms', 'wechat.Wechat/sendSms', 'post')->middleware(WechatAuth::class);
Route::rule('Wechat/sendSms', 'wechat.Wechat/sendSms', 'post');
Route::rule('Wechat/updatePassword', 'wechat.Wechat/updatePassword', 'post')->middleware(WechatAuth::class);
Route::rule('Wechat/getJsSdkData', 'wechat.Wechat/getJsSdkData', 'post')->middleware(WechatAuth::class);

Loading…
Cancel
Save