feat : login
This commit is contained in:
@@ -24,10 +24,11 @@ class LoginRequest extends FormRequest
|
||||
return [
|
||||
'login_type' => 'required|string|in:wx_login,mobile_code',
|
||||
'js_code' => 'required_if:login_type,wx_login|string',
|
||||
'phone_code' => 'required_if:login_type,wx_login|string',
|
||||
];
|
||||
}
|
||||
|
||||
protected array $scenes = [
|
||||
'login' => ['login_type', 'js_code'],
|
||||
'login' => ['login_type', 'js_code', 'phone_code'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -79,11 +79,11 @@ abstract class LoginBaseService extends BaseService
|
||||
*/
|
||||
protected string $lockKey;
|
||||
|
||||
/**
|
||||
* 登录code login_type = wx_login 必填
|
||||
* @var string
|
||||
*/
|
||||
protected string $jsCode = '';
|
||||
// /**
|
||||
// * 登录code login_type = wx_login 必填
|
||||
// * @var string
|
||||
// */
|
||||
// protected string $jsCode = '';
|
||||
|
||||
/**
|
||||
* 手机号 login_type = mobile_code 必填
|
||||
|
||||
@@ -37,25 +37,45 @@ class WxFastLoginService extends LoginBaseService
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$this->jsCode = $this->request->input('js_code');
|
||||
$jsCode = $this->request->input('js_code');
|
||||
$phoneCode = $this->request->input('phone_code');
|
||||
|
||||
if (empty($this->jsCode)) throw new ErrException('登录参数错误');
|
||||
if (empty($jsCode) || empty($phoneCode)) throw new ErrException('登录参数错误');
|
||||
|
||||
$wxInfo = $this->jsCodeGetOpenId($this->jsCode);
|
||||
$wxInfo = $this->jsCodeGetOpenId($jsCode);
|
||||
$this->openId = $wxInfo['openid'];
|
||||
$this->unionId = $wxInfo['unionid'] ?? '';
|
||||
|
||||
$this->jsCodeGetPhoneNumber($phoneCode);
|
||||
$this->mobile = $wxPhone['phone_info']['purePhoneNumber'] ?? '';
|
||||
|
||||
$this->checkLock(self::LOGIN_TYPE);
|
||||
|
||||
$this->register();
|
||||
|
||||
$this->login();
|
||||
|
||||
$this->updateMobile();
|
||||
|
||||
$this->redis->delLock($this->lockKey);
|
||||
|
||||
return $this->getReturn();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function updateMobile(): void
|
||||
{
|
||||
if (empty($this->mobile)) return;
|
||||
|
||||
if ($this->userInfo->mobile == $this->mobile) return;
|
||||
|
||||
$this->userInfo->mobile = $this->mobile;
|
||||
|
||||
if (!$this->userInfo->save()) throw new ErrException('更新手机号失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册
|
||||
* @return void
|
||||
|
||||
Reference in New Issue
Block a user