Closed Huang-junsen closed 4 months ago
原 Google getUserInfo异常 $headers = ['Authorization : Bearer ' . $this->token['access_token']]; $data = $this->get(self::API_BASE . 'oauth2/v2/userinfo', '', $headers);
修复后
public function getUserInfo() { if($this->type == 'app'){//App登录 if(!isset($_REQUEST['code']) ){ throw new \Exception("Google APP登录 需要传输code参数! "); } } $this->getToken();
$headers = array( 'Authorization: Bearer ' . $this->token['access_token'], ); // 创建请求上下文 $context = stream_context_create(array( 'http' => array( 'header' => $headers, ), )); try { $data = file_get_contents(self::API_BASE . 'oauth2/v2/userinfo', false, $context); // 检查响应是否成功 if ($data !== false) { return json_decode($data, true); } else { throw new \Exception("请求失败 " . $data); } }catch (Exception $exception){ throw new \Exception("异常 " . $exception); } }
1.使用的其他get请求组件,组件升级后会解决这个问题,无需修改当前代码 2.在国内服务器由于请求google接口会出现此问题,使用国外、hk服务器正常
原 Google getUserInfo异常 $headers = ['Authorization : Bearer ' . $this->token['access_token']]; $data = $this->get(self::API_BASE . 'oauth2/v2/userinfo', '', $headers);
修复后
public function getUserInfo() { if($this->type == 'app'){//App登录 if(!isset($_REQUEST['code']) ){ throw new \Exception("Google APP登录 需要传输code参数! "); } } $this->getToken();