Пример #1
0
<?php

session_start();
$wxkey = "wxaaaa05a5393b2c14";
$wxsec = "demosec16e97c00e1c3c5c7bba039289";
header('Content-Type: application/javascript; charset=utf-8');
$user = "";
if (isset($_GET["return"]) && isset($_GET["code"])) {
    //微信返回。得到openid等信息。
    $return = base64_decode($_GET["return"]);
    require_once "jssdk.php";
    $jssdk = new JSSDK($wxkey, $wxsec);
    $user = json_decode($jssdk->getOpenId($_GET["code"]));
    if (isset($user->openid)) {
        if (isset($_GET["state"]) && $_GET["state"] == "userinfo") {
            $user = json_decode($jssdk->getUserInfo($user));
        } else {
            $user = array("openid" => $user->openid, "unionid" => $user->unionid);
        }
    }
    $_SESSION["YUY_user"] = $user;
    #$return.=base64_encode(json_encode($user));
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: " . $return);
    exit;
}
echo 'YUY= window.hasOwnProperty("YUY")?window["YUY"]:{};';
echo 'YUY.user=YUY.hasOwnProperty("user")?YUY["user"]:{};';
//如果cookie里面已经有了。那么直接输出就是了。
if (isset($_SESSION["YUY_user"])) {
    if (stristr($_SERVER['HTTP_USER_AGENT'], "micromessenger") && isset($_GET["allUserInfo"])) {