微信开发:已经授权的用户二次登陆静默验证openid

	function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
        var code = getQueryString("code");

            if(!code) {
                var url = encodeURIComponent(window.location.href);
                location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx5d4fb5f6e0c802fb&redirect_uri=" + url + "&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
                code = getQueryString("code");
            }
            if(code)getUser(code);

        //静默获取openid,
        function getUser(code){
            var html = '';
            
            $.ajax({
                url:"data/get_openid.php?code="+code,
                success:function(data){
 
                
                    html = `
                        
  • "background-color:#fff;">

    昵称:

    ${data.nickname}
  • "background-color:#fff;">

    城市:

    ${data.city}
  • `; headerImg = ` class="header_span">"${data.headerImgUrl}" alt=""/> `; $("#userInfoUL").html(html); }, error:function(res){ } });//end of ajax }

    你可能感兴趣的:(微信开发)