一个公众号的域名受权数量是无限的,如果一个公众号须要绑定多个域名时怎么解决呢?这时候就须要用到域名直达

实现微信受权域名直达实例

  • 微信受权回调域名(直达域名):www.test.com
  • 须要受权回调域名1:www.test1.com
  • 须要受权回调域名2:www.test2.com

    在直达域名www.test.com目录下新建index.php,test1.php,test2.php三个文件


  • 在index.php中编写发动受权代码

    if(isset($_GET['type']) && !empty($_GET['type'])){  //发动受权  $appId = "微信APPID";  $redirectUrl =  $_SERVER['REQUEST_SCHEME'] . '://'.  $_SERVER['SERVER_NAME'] . '/' . $_GET['type'] . '.php';  $codeUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appId."&redirect_uri=".urlencode($redirectUrl)."&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";  header("location: ".$codeUrl);  die;}else{  echo "no";}
  • 在test1.php中编写获取受权信息并跳转业务地址(www.test1.com)

    if(isset($_GET['code']) && !empty($_GET['code'])){  $code = $_GET['code'];  $url = "http://www.test1.com/";  header("location:".$url."?code=".$code);}else{  echo 'no';}
  • 在test2.php中编写获取受权信息并跳转业务地址(www.test2.com)

    if(isset($_GET['code']) && !empty($_GET['code'])){  $code = $_GET['code'];  $url = "http://www.test2.com/";  header("location:".$url."?code=".$code);}else{  echo 'no';}

    依据如上形式就能够实现微信受权域名直达
    拜访 www.test1.com 站点时只需拜访 www.test.com?type=test1 即可
    拜访 www.test2.com 站点时只需拜访 www.test.com?type=test2 即可