在作微信開發的時候,會遇到這樣的場景:一個公衆號,會有多個業務:官網、論壇、商城等等php
網頁受權是隻能一個域名,那麼問題來了?這怎麼搞?api
答案就是: 作一箇中轉服務!微信
域名1: www.test.com微信開發
域名2: bbs.test.comapp
這時候,再解析一個二級域名:code.test.com 做爲中轉受權域名微信公衆平臺
並在微信公衆平臺後臺網頁受權域名地方填寫這個 中轉域名url
www.test.com 受權代碼改成:spa
header("location:http://code.test.com/code.php?ask_type=www");
bbs.test.com 受權代碼改成:code
header("location:http://code.test.com/code.php?ask_type=bbs");
code.test.com 域名新建三個文件blog
code_php 文件代碼:
if(isset($_GET['ask_type']) && !empty($_GET['ask_type'])){ $ask_type = $_GET['ask_type']; if($ask_type == 'bbs'){ $action = "bbs.php"; }elseif($ask_type == 'www'){ $action = "www.php"; } //發起受權 $appid = ""; $redirect_url = "http://code.test.com/".$action; $code_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=".urlencode($redirect_url)."&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"; header("location: ".$code_url); die; }else{ echo "nononono"; }
bbs.php文件代碼:
if(isset($_GET['code']) && !empty($_GET['code'])){ $code = $_GET['code']; $bbs = "http://bbs.test.com/"; header("location:".$bbs."?code=".$code); }else{ echo 'nonono'; }
www.php 文件代碼:
if(isset($_GET['code']) && !empty($_GET['code'])){ $code = $_GET['code']; $bbs = "http://www.test.com/"; header("location:".$bbs."?code=".$code); }else{ echo 'nonono'; }
目前是兩個業務域名。若是還有其餘業務,能夠按照上述例子新增!