diff --git a/app/common/controller/UserController.php b/app/common/controller/UserController.php index b769cd3..bb8fd6a 100644 --- a/app/common/controller/UserController.php +++ b/app/common/controller/UserController.php @@ -164,7 +164,7 @@ class UserController extends BaseController public function miniappPhoneNumber(Request $request): Response { try { - $result = $this->service->miniappPhoneNumber($request->all()); + $result = $this->service->miniappPhoneNumber($request->all(),$request); return $this->success($result); } catch (\Throwable $th) { return $this->error($th->getMessage()); diff --git a/app/common/service/UserService.php b/app/common/service/UserService.php index 72f758f..71b5431 100644 --- a/app/common/service/UserService.php +++ b/app/common/service/UserService.php @@ -9,6 +9,7 @@ use app\common\model\User; use app\common\logic\UserLogic; use app\common\utils\Jwt; use support\exception\BusinessException; +use support\Request; class UserService { @@ -237,12 +238,11 @@ class UserService $logic = new UserLogic(); $wechatService = new WechatService(); $wxinfo = $wechatService->xcxOpenid($data['code']); - var_dump($wxinfo); // 用户信息 $user = User::firstOrCreate( ['openid' => $wxinfo['openid']], - ['nickname' => '微信用户_'.$wxinfo['openid'], 'name' => '', 'avatar' => getenv('MAIN_DOMAIN').'/avatar.png'] + ['nickname' => '微信用户_'.$wxinfo['openid'], 'unionid' => $wxinfo['unionid'], 'name' => '', 'avatar' => getenv('MAIN_DOMAIN').'/avatar.png'] ); @@ -258,13 +258,13 @@ class UserService /** * 获取手机号 */ - public function miniappPhoneNumber(array $data) + public function miniappPhoneNumber(array $data,Request $request) { // 手机号 $wechatService = new WechatService(); $wxinfo = $wechatService->xcxPhoneNumber($data['phone_code']); - $uinfo = User::where('id', $data['user_id'])->first(); + $uinfo = User::where('id', $request->user->uid)->first(); $uinfo->phone = $wxinfo['phone_info']['phoneNumber']; $uinfo->save();