解决使用easywechat的网页授权不能使用公共授权

getweixincode: https://github.com/HADB/GetWeixinCode

easywechat: https://www.easywechat.com/docs/3.x/zh-CN/oauth 3.x版本 非master

 

 

 

 

1:修改easywecaht包中的

overtrue/socialite/src/Providers/AbstractProvider.php 文件里面的 redirect 方法为:

  public function redirect($redirectUrl = null,$address = null)
    {
        $state = null;

        if (!is_null($redirectUrl)) {
            $this->redirectUrl = $redirectUrl;
        }
        if ($this->usesState()) {
            $state = $this->makeState();
        }

        return new RedirectResponse($this->getAuthUrl($state,$address));
    }

 

2:修改easywecaht 包中的

overtrue/socialite/src/Providers/WeChatProvider.php 文件里面的getAuthUrl方法

为:

 protected function getAuthUrl($state,$address="")
    {
        $path = 'oauth2/authorize';
        if (in_array('snsapi_login', $this->scopes)) {
            $path = 'qrconnect';
        }
        $url = "https://open.weixin.qq.com/connect/";
        if($address)
        {
            $url = $address;
        }else{
            $url .= $path;
        }
        return $this->buildAuthUrlFromBase($url, $state);
    }

 

3:至此修改完成,调用如下:

public function oauth()

{

$app = new Application(WxConfig::get());

$oauth = $app->oauth;

$result = $oauth->redirect("http://ly.fet6.cn/index/wx/callback","http://shop.fet6.cn/wechat_auth.html");

// thinkphp5 : $result->send; larvel : reutrn $result;

$result->send();

}

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(解决使用easywechat的网页授权不能使用公共授权)