【PHP】一個微信公眾號,多個網域名稱下授權使用的方法!CODE中轉

來源:互聯網
上載者:User
/*未授權網域名稱下的方法!調用為了擷取CODE*/

/**============================================================
* [get_cyb_code 從自己的主網域名稱下擷取CODE]
* @return [string] [code]
*/


public function get_cyb_code()
{
if(empty($_GET['code']))
{
$redirect_uri = urlencode($_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']);
header("location:http://授權網域名稱/wxcode.php?redirect_uri=".$redirect_uri);
}
else{
return $_GET['code'];
}
}

/*授權網域名稱下的方法*/

$code = get_oauth2_code();//調用網頁授權來擷取code
echo $code;
if(!empty($code)){
header("location:http://".$_REQUEST['redirect_uri']."?code=".$code);
}
//echo $_REQUEST['redirect_uri'];


//授權網域名稱下的,擷取CODE方法

/**============================================================
* [get_oauth2_code 取得網頁使用者授權介面中code參數]
* @return [string] [code]
*/
function get_oauth2_code()
{
if(empty($_GET['code']))
{
if(!APPID)
{
$this->show_msg('appid error!');
return;
}
$redirect_uri = urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']);
$para = array(
"appid" => APPID,
"redirect_uri" => $redirect_uri,
"response_type" => 'code',
"scope" => 'snsapi_base',
"state" => '123#wechat_redirect'
);
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=".$para['redirect_uri']."&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect";
header("location:".$url);
//echo $url;
}
else{
return $_GET['code'];
}
}


?>

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.