当前位置: 首页 > 工具软件 > PHP OAuth API > 使用案例 >

weixin oauth api 使用

车诚
2023-12-01
<?php
    <?php
Session_start();


/*
 * 微信端限制
 */
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$local_url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$user_agent = $_SERVER ['HTTP_USER_AGENT'];
if (strpos ( $user_agent, 'MicroMessenger' ) === false) {
    echo "<h4>请用微信扫一扫二维码打开</h4>";
    echo "<img src='http://qr.liantu.com/api.php?text={$local_url}'/>";
    exit();
}else{
    if($_GET['openid']){
        $_SESSION['openid']=$_GET['openid'];
        unset($_GET['openid']);
        foreach ($_GET as $k=> $v) {
            $get_url.="&".$k."=".$v;
        }
        if($get_url){
             $real_url=$local_url."&".urlencode($get_url);
        }else{
             $real_url=$local_url."?".urlencode($get_url);
        }
       
        header ( "Location:" . $real_url );
    }else{
        if(!$_SESSION['openid']){
            $local_urls=urlencode($local_url);
            $sit_oauth2="http://api.4vtk.com/oauth2.php?back_url=".$local_urls;
            header ( "Location:" . $sit_oauth2 );
        }

    }
}





?>
 
?>

 

转载于:https://www.cnblogs.com/yutaoyao/p/4308151.html

 类似资料: