最近在用HWIOAuthBundle 作第三方QQ登陆 会出现bug;就追源码 发现存在一些问题; 估计HWIOAuthBundle没有及时更新;github上仍是两年前的;php
// HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\QQResourceOwner.php; /** * {@inheritDoc} */ public function getUserInformation(array $accessToken = null, array $extraParameters = array()) { /* * 这是原来的;他调用normalizeUrl 方法生成一个URL $url = $this->normalizeUrl($this->options['infos_url'], array( 'oauth_consumer_key' => $this->options['client_id'], 'access_token' => $accessToken['access_token'], 'openid' => $openid, 'format' => 'json', )); //在这他直接把生成好的URL(带参数的);咱们能够追到doGetUserInformationRequest的写法 return $this->httpRequest($url, http_build_query($parameters, '', '&')); http_build_query()问题就在这 当parameters为空时他返回的是空字符串不是null;咱们在看 httpRequest的方法判断 $method = null === $content ? HttpRequestInterface::METHOD_GET : HttpRequestInterface::METHOD_POST; 就可知道 $method应该是post;而qq互联官网getUserInfo 是须要get方式访问的; $response = $this->doGetUserInformationRequest($url); */ ..... }
正确的写法git
public function getUserInformation(array $accessToken = null, array $extraParameters = array()) { $openid = isset($extraParameters['openid']) ? $extraParameters['openid'] : $this->requestUserIdentifier($accessToken); $url = $this->options['infos_url']; $params = array( 'oauth_consumer_key' => $this->options['client_id'], 'access_token' => $accessToken['access_token'], 'openid' => $openid, 'format' => 'json', ); $response = $this->doGetUserInformationRequest($url, $params);
其实就是一个get,post 请求方法的改变github