The number of domain names authorized for an official account is limited. What if one official account needs to be bound with multiple domain names? At this time, you need to use the domain name transfer

Example of Realizing WeChat Authorized Domain Name Transfer

  • WeChat authorized callback domain name (transfer domain name): www.test.com
  • Need to authorize callback domain name 1: www.test1.com
  • Need to authorize callback domain name 2: www.test2.com

    Create three new files, index.php, test1.php, and test2.php in the directory of the transit domain name www.test.com


  • Write the authorization code in 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";
    }
  • Write in test1.php to obtain authorization information and jump to the business address (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';
    }
  • Write in test2.php to obtain authorization information and jump to the business address (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';
    }

    According to the above method, WeChat authorized domain name transfer can be realized. When visiting the www.test1.com site, you only need to visit www.test.com?type=test1 to visit the www.test2.com site. When you only need to visit www.test.com?type =test2 can


huaweichenai
673 声望114 粉丝