symfony2 HWIOAuthBundle QQ登陸問題

現行版本 HWIOAuthBundle QQ 登陸會出現問題

最近在用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

相關文章
相關標籤/搜索