时间:2021-07-01 10:21:17 帮助过:96人阅读
/**============================================================
* [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'];
}
}
?>