easywechat 用户授权绑定多个域名

2018-10-19 09:08:51 阅读:12 编辑

微信公众号本身只支持绑定一个域名

vendor\overtrue\Laravel-wechat\src\Middleware\OAuthAuthenticate.php

return $this->wechat->OAuth->scopes ($scopes)->redirect ($request->fullUrl ());

修改成

$url =$request->fullUrl ();
            $App_url = env ("App_URL");
            if (strpos ($url,$App_url) ==  false){  //no exist
                $pos = strpos ($url,".com");
                $url = str_replace (substr ($url,0, $pos).".com",$App_url,$url);
            }
            return $this->wechat->OAuth->scopes ($scopes)->redirect ($url);
原理:env ("App_URL") 为微信公众号绑定的域名。把不是该域名替换成该域名。