示例#1
0
文件: init.php 项目: GYWang1983/fruit
function goto_login($clear_cookie = FALSE)
{
    global $_LANG, $_CFG;
    if (is_wechat_browser()) {
        // 微信登录
        $callback = $_CFG['site_url'] . $_SERVER['REQUEST_URI'];
        $user = weixin_oauth($callback);
    }
    if (empty($user)) {
        if ($clear_cookie) {
            setcookie($_COOKIE['ECSCP']['admin_id'], '', 1);
            setcookie($_COOKIE['ECSCP']['admin_pass'], '', 1);
        }
        if (!empty($_REQUEST['is_ajax'])) {
            make_json_error($_LANG['priv_error']);
        } else {
            ecs_header("Location: privilege.php?act=login\n");
        }
        exit;
    }
}
示例#2
0
文件: init.php 项目: GYWang1983/fruit
/* 判断是否支持 Gzip 模式 */
if (!defined('INIT_NO_SMARTY') && gzip_enabled()) {
    ob_start('ob_gzhandler');
} else {
    ob_start();
}
if (is_wechat_browser() && strpos($_CFG['site_url'], 'test.') === false) {
    if (empty($_SESSION['user_id'])) {
        include_once ROOT_PATH . 'include/lib_passport.php';
        include_once ROOT_PATH . 'weixin/login.php';
        $uri = str_replace('/mobile/', '/', $_SERVER['REQUEST_URI']);
        if (substr($uri, -1) == '/') {
            $uri .= 'index.php';
        }
        $callback = $_CFG['site_url'] . $uri;
        weixin_oauth($callback);
    } elseif (empty($_SESSION['openid'])) {
        $openid = $db->getOne("SELECT wxid FROM wxch_user WHERE uid={$_SESSION['user_id']}");
        $_SESSION['openid'] = $openid;
    }
}
/* 检查是否是微信浏览器访问 */
function is_wechat_browser()
{
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    if (strpos($user_agent, 'MicroMessenger') === false) {
        //echo '非微信浏览器禁止浏览';
        return false;
    } else {
        //echo '微信浏览器,允许访问';
        //preg_match('/.*?(MicroMessenger\/([0-9.]+))\s*/', $user_agent, $matches);
示例#3
0
$wechat = new WechatApi();
// 检查是否存在昵称和头像
$sql = "SELECT * FROM wxch_user WHERE uid = " . intval($_SESSION['user_id']);
$wx_user = $db->getRow($sql);
if (!empty($wx_user) && empty($wx_user['headimgurl'])) {
    if ($act == 'my') {
        // 尝试通过微信API获取昵称和头像
        $wx_user = $wechat->get_user_info($wx_user['wxid']);
        if (!empty($wx_user) && $wx_user['subscribe'] == 1) {
            // 更新微信用户数据
            $db->autoExecute('wxch_user', array('subscribe' => $wx_user['subscribe'], 'nickname' => $wx_user['nickname'], 'sex' => $wx_user['sex'], 'city' => $wx_user['city'], 'country' => $wx_user['country'], 'province' => $wx_user['province'], 'language' => $wx_user['language'], 'headimgurl' => $wx_user['headimgurl'], 'subscribe_time' => $wx_user['subscribe_time'], 'dateline' => time()), 'UPDATE', 'uid = ' . $_SESSION['user_id']);
        }
    } elseif ($act == 'other') {
        $uri = str_replace('/mobile/', '/', $_SERVER['REQUEST_URI']);
        $callback = $_CFG['site_url'] . $uri;
        weixin_oauth($callback, 'INFO');
    }
}
if ($act == 'my') {
    $user_bargain_id = check_user_bargain($bargain_id, $_SESSION['user_id']);
    if (empty($user_bargain_id)) {
        if ($wx_user['subscribe'] == 1) {
            // 检查砍价活动状态
            $sql = "SELECT * FROM " . $ecs->table('bargain_goods') . " WHERE id = {$bargain_id}";
            $bargain = $db->getRow($sql);
            if (empty($bargain)) {
                show_message('砍价活动不存在', '返回首页', 'index.php', 'error');
            }
            if ($bargain['status'] == 4) {
                show_message('水果已经抢光了,去看看其他活动吧', '返回首页', 'index.php', 'error');
            }