function checkLogin() {
    var flag = false
    $.ajax({
        type: 'POST',
        url: "/index/isLogin",
        async: false,
        success: function (res) {
            if(res.code == 200){
                flag = true
            }else if(res.code == 10008){
                goLogin();
                flag = false
            }else if(res.code == 10029){
                //在另一设备登录，重新登录
                $(".userConfirmBox").show();
                flag = false;
            }
        },
        error: function (data) {

        }
    });
    return flag
}
function againLogin() {
    var flag = false
    $.ajax({
        type: 'POST',
        url: "/index/isLogin",
        async: false,
        success: function (res) {
            if(res.code == 200){
                flag = true
            }else if(res.code == 10008){
                flag = true
            }else if(res.code == 10029){
                //在另一设备登录，重新登录
                $(".userConfirmBox").show();
                flag = false;
            }
        },
        error: function (data) {

        }
    });
    return flag
}
$(document).on('click','.confirmClose',function (){
    $(".userConfirmBox").hide();
    window.location.href = serverHttp + "/index/index?from=H5";
})
$(document).on('click','.confirmLogin',function (){
    $(".userConfirmBox").hide();
    goLogin();
})

function goLogin(){
    var localurl = encodeURIComponent(window.location.href);
    if(is_weixn()){
        var redirect_uri = serverHttp+'/login/wxlogin?redirectUrl='+localurl;
        redirect_uri = encodeURIComponent(redirect_uri);
        location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa35f548647a3fa20&redirect_uri="+redirect_uri+"&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
    }else{
        var redirect_uri = serverHttp+'/login?from=H5&redirectUrl='+localurl;
        window.location.href = redirect_uri;
    }
}

function goHome() {
    window.location.href = serverHttp + "/index/index?from=H5";
}
function addSq () {
    window.location.href = serverHttp + "/user/addSq?from=H5";
}
//判断是否是微信打开
function is_weixn(){
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger") {
        return true;
    } else {
        return false;
    }
}
