$this->config->get('client_id'), 'secret' => $this->config->get('client_secret'), // 下面为可选项 // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名 'response_type' => 'array', 'log' => [ 'level' => 'debug', 'file' => storage_path('logs/wechat-mini.log'), ], ]); $result = $app->auth->session($code); if ($result) { if (data_get($result, 'errcode')) { throw new BizException(data_get($result, 'errmsg')); } //缓存微信小程序会话密钥(48小时) Cache::put($result['openid'], $result['session_key'], 48 * 60 * 60); return $this->mapUserToObject([ 'openid'=>$result['openid'], // 'unionid'=>$result['unionid'], ]); } else { throw new BizException('解析失败'); } } protected function getAuthUrl(): string { return ''; } protected function getTokenUrl(): string { return ''; } protected function getUserByToken(string $token): array { return []; } protected function mapUserToObject(array $user): User { return new User([ 'id' => $user['openid'] ?? null, 'name' => $user['nickname'] ?? null, 'nickname' => $user['nickname'] ?? null, 'avatar' => $user['headimgurl'] ?? null, 'email' => null, ]); } }