wanghousheng 8 months ago
parent a6279d5c06
commit 7d5dce8e5e
  1. 10
      app/api/service/passport/Login.php

@ -56,14 +56,14 @@ class Login extends BaseService
{
// 数据验证
$this->validate($data);
//新增小程序登录
//绑定openid
if (!empty($data['ucode'])) {
// 推荐人ID
$refereeId = 0;
if (!empty($data['refereeId'])) {
$refereeId = intval($data['refereeId']);
}
return $this->loginMinWx($data['ucode'], $refereeId);
return $this->loginMinWx($data['ucode'], $refereeId, $data['mobile']);
}
// 自动登录注册
$this->register($data);
@ -73,7 +73,7 @@ class Login extends BaseService
return $this->setSession();
}
private function loginMinWx($code, $refereeId): bool
private function loginMinWx($code, $refereeId, $mobile): bool
{
// 获取微信小程序登录态(session)
$wxSession = PartyService::getMpWxSession($code);
@ -91,11 +91,11 @@ class Login extends BaseService
// 用户信息不存在 => 注册新用户 或者 跳转到绑定手机号页
$setting = SettingModel::getItem(SettingEnum::REGISTER);
// 后台设置了需强制绑定手机号, 返回前端isBindMobile, 跳转到手机号验证页
if ($setting['isForceBindMpweixin']) {
if ($setting['isForceBindMpweixin'] && !$mobile) {
throwError('当前用户未绑定手机号', null, ['isBindMobile' => true]);
}
// 用户不存在: 创建一个新用户
$this->createUser('', true, [], (int)$refereeId);
$this->createUser($mobile, true, [], (int)$refereeId);
// 保存第三方用户信息
$this->createUserOauth($this->getUserId(), true);
// 记录登录态

Loading…
Cancel
Save