修复:用户登录后获取昵称头像失败
This commit is contained in:
parent
3b53a25976
commit
41a0d0c418
|
|
@ -106,16 +106,14 @@ class WechatUserRepository extends BaseRepository
|
||||||
$routineInfo['city'] = $routine['city'] ?? '';//城市
|
$routineInfo['city'] = $routine['city'] ?? '';//城市
|
||||||
$routineInfo['province'] = $routine['province'] ?? '';//省份
|
$routineInfo['province'] = $routine['province'] ?? '';//省份
|
||||||
$routineInfo['country'] = $routine['country'] ?? '';//国家
|
$routineInfo['country'] = $routine['country'] ?? '';//国家
|
||||||
$routineInfo['headimgurl'] = $routine['avatarUrl'] !== $def ?: '';//头像
|
$routineInfo['headimgurl'] = $routine['avatarUrl'] !== $def ? $routine['avatarUrl'] : '';//头像
|
||||||
$routineInfo['routine_openid'] = $routineOpenid;//openid
|
$routineInfo['routine_openid'] = $routineOpenid;//openid
|
||||||
$routineInfo['session_key'] = $routine['session_key'] ?? '';//会话密匙
|
$routineInfo['session_key'] = $routine['session_key'] ?? '';//会话密匙
|
||||||
$routineInfo['unionid'] = $routine['unionId'];//用户在开放平台的唯一标识符
|
$routineInfo['unionid'] = $routine['unionId'];//用户在开放平台的唯一标识符
|
||||||
$routineInfo['user_type'] = 'routine';//用户类型
|
$routineInfo['user_type'] = 'routine';//用户类型
|
||||||
$wechatUser = null;
|
$wechatUser = null;
|
||||||
if ($routineInfo['unionid'])
|
if ($routineInfo['unionid']) $wechatUser = $this->dao->unionIdByWechatUser($routineInfo['unionid']);
|
||||||
$wechatUser = $this->dao->unionIdByWechatUser($routineInfo['unionid']);
|
if (!$wechatUser) $wechatUser = $this->dao->routineIdByWechatUser($routineOpenid);
|
||||||
if (!$wechatUser)
|
|
||||||
$wechatUser = $this->dao->routineIdByWechatUser($routineOpenid);
|
|
||||||
return Db::transaction(function () use ($createUser, $routineInfo, $wechatUser) {
|
return Db::transaction(function () use ($createUser, $routineInfo, $wechatUser) {
|
||||||
if ($wechatUser) {
|
if ($wechatUser) {
|
||||||
$routineInfo['nickname'] = $wechatUser['nickname'];
|
$routineInfo['nickname'] = $wechatUser['nickname'];
|
||||||
|
|
|
||||||
|
|
@ -429,14 +429,12 @@ class Auth extends BaseController
|
||||||
|
|
||||||
private function authInfo($auth, $createUser = false)
|
private function authInfo($auth, $createUser = false)
|
||||||
{
|
{
|
||||||
if (!in_array($auth['type'] ?? '', ['wechat', 'routine', 'apple', 'app_wechat']) || !isset($auth['auth']))
|
if (!in_array($auth['type'] ?? '', ['wechat', 'routine', 'apple', 'app_wechat']) || !isset($auth['auth'])) throw new ValidateException('授权信息类型有误');
|
||||||
throw new ValidateException('授权信息类型有误');
|
|
||||||
$data = $auth['auth'];
|
$data = $auth['auth'];
|
||||||
if ($auth['type'] === 'routine') {
|
if ($auth['type'] === 'routine') {
|
||||||
$code = $data['code'] ?? '';
|
$code = $data['code'] ?? '';
|
||||||
$userInfoCong = Cache::get('eb_api_code_' . $code);
|
$userInfoCong = Cache::get('eb_api_code_' . $code);
|
||||||
if (!$code && !$userInfoCong)
|
if (!$code && !$userInfoCong) throw new ValidateException('授权失败,参数有误');
|
||||||
throw new ValidateException('授权失败,参数有误');
|
|
||||||
$miniProgramService = MiniProgramService::create();
|
$miniProgramService = MiniProgramService::create();
|
||||||
if ($code && !$userInfoCong) {
|
if ($code && !$userInfoCong) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -458,13 +456,17 @@ class Auth extends BaseController
|
||||||
$userInfo['unionId'] = $userInfoCong['unionid'] ?? $userInfo['unionId'] ?? '';
|
$userInfo['unionId'] = $userInfoCong['unionid'] ?? $userInfo['unionId'] ?? '';
|
||||||
if (!$userInfo['openId']) throw new ValidateException('openid获取失败');
|
if (!$userInfo['openId']) throw new ValidateException('openid获取失败');
|
||||||
|
|
||||||
|
$userInfo['nickName'] = $auth['auth']['new_nickname'] ?? $userInfo['nickName'];
|
||||||
|
$userInfo['avatarUrl'] = $auth['auth']['new_avatar'] ?? $userInfo['avatarUrl'];
|
||||||
|
|
||||||
/** @var WechatUserRepository $make */
|
/** @var WechatUserRepository $make */
|
||||||
$make = app()->make(WechatUserRepository::class);
|
$make = app()->make(WechatUserRepository::class);
|
||||||
$user = $make->syncRoutineUser($userInfo['openId'], $userInfo, $createUser);
|
$user = $make->syncRoutineUser($userInfo['openId'], $userInfo, $createUser);
|
||||||
if (!$user)
|
if (!$user) throw new ValidateException('授权失败');
|
||||||
throw new ValidateException('授权失败');
|
|
||||||
return $user;
|
return $user;
|
||||||
} else if ($auth['type'] === 'wechat') {
|
}
|
||||||
|
else if ($auth['type'] === 'wechat') {
|
||||||
$request = $this->request;
|
$request = $this->request;
|
||||||
$oauth = WechatService::create()->getApplication()->oauth;
|
$oauth = WechatService::create()->getApplication()->oauth;
|
||||||
$oauth->setRequest(new Request($data, $data, [], [], [], $request->server(), $request->getContent()));
|
$oauth->setRequest(new Request($data, $data, [], [], [], $request->server(), $request->getContent()));
|
||||||
|
|
@ -483,7 +485,8 @@ class Auth extends BaseController
|
||||||
if (!$user)
|
if (!$user)
|
||||||
throw new ValidateException('授权失败[003]');
|
throw new ValidateException('授权失败[003]');
|
||||||
return $user;
|
return $user;
|
||||||
} else if ($auth['type'] === 'app_wechat') {
|
}
|
||||||
|
else if ($auth['type'] === 'app_wechat') {
|
||||||
$oauth = WechatService::create()->getApplication()->oauth;
|
$oauth = WechatService::create()->getApplication()->oauth;
|
||||||
try {
|
try {
|
||||||
$wechatInfo = $oauth->user(new AccessToken(['access_token'=>$data['code'],'openid'=>$data['openid']]))->getOriginal();
|
$wechatInfo = $oauth->user(new AccessToken(['access_token'=>$data['code'],'openid'=>$data['openid']]))->getOriginal();
|
||||||
|
|
@ -494,7 +497,8 @@ class Auth extends BaseController
|
||||||
if (!$user)
|
if (!$user)
|
||||||
throw new ValidateException('授权失败');
|
throw new ValidateException('授权失败');
|
||||||
return $user;
|
return $user;
|
||||||
} else if ($auth['type'] === 'apple') {
|
}
|
||||||
|
else if ($auth['type'] === 'apple') {
|
||||||
$identityToken = $data['userInfo']['identityToken'];
|
$identityToken = $data['userInfo']['identityToken'];
|
||||||
$tks = explode('.', $identityToken);
|
$tks = explode('.', $identityToken);
|
||||||
if (count($tks) != 3) {
|
if (count($tks) != 3) {
|
||||||
|
|
@ -516,12 +520,11 @@ class Auth extends BaseController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function authLogin()
|
public function authLogin(){
|
||||||
{
|
|
||||||
$auth = $this->request->param('auth');
|
$auth = $this->request->param('auth');
|
||||||
$users = $this->authInfo($auth, systemConfig('is_phone_login') !== '1');
|
$users = $this->authInfo($auth, systemConfig('is_phone_login') !== '1');
|
||||||
if (!$users)
|
|
||||||
return app('json')->fail('授权失败');
|
if (!$users) return app('json')->fail('授权失败');
|
||||||
$authInfo = $users[0];
|
$authInfo = $users[0];
|
||||||
$userRepository = app()->make(UserRepository::class);
|
$userRepository = app()->make(UserRepository::class);
|
||||||
$user = $users[1] ?? $userRepository->wechatUserIdBytUser($authInfo['wechat_user_id']);
|
$user = $users[1] ?? $userRepository->wechatUserIdBytUser($authInfo['wechat_user_id']);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue