微信公众号H5页面授权报40163 code重复使用错误

浏览:730 发布日期:2019/06/04 分类:求助交流
<script type="text/javascript">
        var now_url = window.location.href; //获取当前链接地址
        // alert(now_url);
            // $('#spinner').hide();
        // alert(now_url);
        var redirect_uri = encodeURIComponent(now_url);//urlEncode编码路径
        var AppId   = "wx99babc4e8270d8aa";//公众号appid
        var wechat_url   = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+AppId+"&redirect_uri="+redirect_uri+"&response_type=code&scope=snsapi_userinfo#wechat_redirect";
        var code    = getUrlparam('code');

        if(code == null || code === '' || code == undefined){
            window.location.href = wechat_url;//修改当前链接地址为微信登录授权地址
        }

        // 手机端判断各个平台浏览器及操作系统平台
        function checkPlatform(code) {
            var sale_id = getUrlparam('sale_id');
            //网页授权获取code
            if(/android/i.test(navigator.userAgent)) {
                $.ajax({
                    type: "POST",
                    url: "https://www.xiaodongai.com/xiaodongai/kongtian/wechat.php?s=/App/web_openid",
                    data: {
                        uid    : 5,
                        code   : code,
                        sale_id: sale_id,
                    },
                    success: function(data) {
                        var jsObject = eval('('+data+')');
                        if(jsObject.key == 1) {
                            window.open("https://www.xiaodongai.com/xiaodongai/kongtian/Uploads/app/healthlittle.apk");
                            // window.open("https://itunes.apple.com/cn/app/id1451065441?mt=8");
                        } else {
                            var err = '错误码'+jsObject.key+',未知错误,请联系客服或销售,400-1199-218'
                            // alert(2)
                            alert(err)
                        }
                    }
                });
                // window.open("https://itunes.apple.com/cn/app/id1451065441?mt=8")
            }
            
            if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                $.ajax({
                    type: "POST",
                    url: "https://www.xiaodongai.com/xiaodongai/kongtian/wechat.php?s=/App/web_openid",
                    data: {
                        uid    : 4,
                        code   : code,
                        sale_id: sale_id,
                    },
                    // dataType: "json",
                    success: function(data) {
                        var jsObject = eval('('+data+')');

                        if(jsObject.key == 1) {
                            // alert(data)
                            // window.open("https://itunes.apple.com/cn/app/id1451065441?mt=8");
                            window.location.href = "https://itunes.apple.com/cn/app/id1451065441?mt=8";
                        } else {
                            var err = '错误码'+jsObject.key+',未知错误,请联系客服或销售,400-1199-218'
                            // alert(2)
                            alert(err)
                        }
                    }
                });
                // alert('IOS版本正在测试中..........')

            }
        }
                    
        var oBtn = document.getElementById('btn');
        oBtn.onclick = function() {
            if(code == null || code === ''){
                window.location.href = wechat_url;//判断是否同意授权否则修改当前链接地址为微信登录授权地址
            }else{
                // $('#spinner').show();
                checkPlatform(code);
            }
        };

        function getUrlparam(name){
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r   = window.location.search.substr(1).match(reg);
            if(r != null) return unescape(r[2]);
            return null;
        }
    </script>
最佳答案
评论( 相关
后面还有条评论,点击查看>>