微信服务号授权域名中转方案

微信授权域名现在只允许填写两个
我们可以在其中一个安全域名下,弄一个中转地址
比方说授权域名填写a.abc.com
我们在a.abc.com
弄一个a.abc.com/jump.php

class Jump{ private $app_id= 'abc'; private $app_secret = 'cba'; public function geturl(){ return $this->get_authorize_url('a.abc.com/givecode.php'); //中转回调地址 }public function get_authorize_url($redirect_uri = '', $state = ''){ $reurl = b.abc.com; //真正想要回调的地址 $redirect_uri = urlencode($redirect_uri); return "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$this->app_id}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_base&state={$reurl}#wechat_redirect"; }}$obj = new Jump(); $url = $obj->geturl(); Header("Location: $url");

然后在givecode.php
$code = $_GET['code']; $state = urldecode($_GET['state']); $token_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=&secret=&code={$code}&grant_type=authorization_code"; $token_data = https://www.it610.com/article/file_get_contents($token_url); $token_data = json_decode($token_data); if($token_data->openid){ $openid = $token_data->openid; $url = $state; setcookie("openid",$openid,time()+3600,'/','abc.com'); Header("Location: $url"); }

【微信服务号授权域名中转方案】最后在b.abc.com拿到openid
用户详细信息也大致同一个思路

    推荐阅读