weixin oauth api 使用

<?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