"PHP" a WeChat public number, multi-domain license to use the method! Code Relay

Source: Internet
Author: User
/* method under Unauthorized domain name! Called in order to get code*/

/**============================================================
* [Get_cyb_code get code from its own primary domain]
* @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://authorized domain name/wxcode.php?redirect_uri=". $redirect _uri);
}
else{
Return $_get[' code ';
}
}

/* method under Authorized domain name */

$code = Get_oauth2_code ();//Invoke Web page authorization to get code
Echo $code;
if (!empty ($code)) {
Header ("location:http://". $_request[' Redirect_uri '). "? Code= ". $code);
}
echo $_request[' Redirect_uri '];


Under authorized domain name, get the code method

/**============================================================
* [Get_oauth2_code Obtain the Web user authorization interface in the code parameter]
* @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 ';
}
}


?>

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.