微信公众号项目,获取openid的坑

openid在java端,三级二跳程序中存储在了cookie中,

在前端页面,需要首先获取cookie中的openid,否则打不开页面

//获取cookie中的信息
        function get_cookie(Name) {
            var search = Name + "=";//查询检索的值
            var returnvalue = "";//返回值
            if (document.cookie.length > 0) {
                sd = document.cookie.indexOf(search);
                if (sd!= -1) {
                    sd += search.length;
                    end = document.cookie.indexOf(";", sd);
                    if (end == -1)
                        end = document.cookie.length;
                    //unescape() 函数可对通过 escape() 编码的字符串进行解码。
                    returnvalue=unescape(document.cookie.substring(sd, end))
                }
            }
            return returnvalue;
        }
        var openid = get_cookie("openid");
        localStorage.setItem("openid",openid);

特别注意:如果公众号中配置的页面是vue页面,那么要在入口文件index.html中,首先获取openid,如果没有获取到openid,那么公众号里面的页面,都进不去,都是空白页

猜你喜欢

转载自blog.csdn.net/yangdl6/article/details/90144104