Exemple #1
0
        echo "授权失败";
        error_log($json_obj["errcode"] . "|", 3, "auth_log.txt");
        //		header('Location:http://weilink.huaxi100.com/hxdsb/');
        exit;
    }
    //根据openid和access_token查询用户信息
    $access_token = $json_obj['access_token'];
    $refresh_token = $json_obj['refresh_token'];
    $expires_in = $json_obj['expires_in'];
    $openid = $json_obj['openid'];
    $get_user_info_url = 'https://api.weixin.qq.com/sns/userinfo?access_token=' . $access_token . '&openid=' . $openid . '&lang=zh_CN';
    $res = @file_get_contents($get_user_info_url);
    //解析json
    $user_obj = json_decode($res, true);
    if (!$user_obj && !is_array($user_obj)) {
        //		header('Location:http://weilink.huaxi100.com/hxdsb/hxsd/error.html');
        echo "获取信息失败";
        exit;
    }
    $openid = empty($openid) ? $user_obj['openid'] : $openid;
    $nickname = $user_obj['nickname'];
    $headimgurl = $user_obj['headimgurl'];
    $expires_time = $timestamp + $expires_in;
    $shake->insertOrUpdateUserinfo($openid, $config['appid'], $nickname, $headimgurl, $expires_time);
    setcookie(USER_COOKIE_ID, md5($openid . $config['appid']), $expires_time);
    header("Location:" . $config['index']);
}
exit;
?>