949335988@qq.com
949335988@qq.com
  • 发布:2019-03-13 15:59
  • 更新:2019-10-21 04:02
  • 阅读:1118

小白求助,微信登录拉起微信一下就没了

分类:HTML5+

第一次能登录,后面一直不行,code也能获取到,authResult一直是null,是我这个流程不对?

        methods: {  
            wxLogin() {  
                var _this = this;  
                var weixinService = null;  
                plus.oauth.getServices(function(services) {  
                    console.log(JSON.stringify(services))  
                    if(services && services.length) {  
                        for(var i = 0, len = services.length; i < len; i++) {  
                            if(services[i].id === 'weixin') {  
                                weixinService = services[i];  
                                break;  
                            }  
                        }  
                        if(!weixinService) {  
                            console.log('没有微信登录授权服务');  
                            return;  
                        }  

                        weixinService.authorize(function(event) {  
                            _this.weixinCode = event.code;  
                            console.log(JSON.stringify(event))  
                            console.log(JSON.stringify(this))  
                            console.log(JSON.stringify(_this)) //用户换取 access_token 的 code  
                            console.log(weixinCode)  
                            console.log(_this.weixinCode)  
                            setTimeout(function(event) {  
                                console.log(event.authResult)  
                            }, 100)  
                            if(event.authResult) {  
                                _this.requestLogin();  
                            }  
                            setTimeout(function() {  
                                _this.sendWxCode();  
                            }, 1000)  
//                          setTimeout(function() {  
//                              _this.wxLogOut();  
//                          }, 2000)  
                        }, function(error) {  
                            console.log('authorize fail:' + JSON.stringify(error));  
                        }, {  

                            appid: '',  
                            appsecret: ' ',  
//                          scope: 'snsapi_userinfo',  
                            state:'authorize test'  
                            //开放平台的应用标识。暂时填个假的充数,仅做演示。  
                        });  
                    } else {  
                        console.log('无可用的登录授权服务');  
                    }  
                }, function(error) {  
                    console.log('getServices fail:' + JSON.stringify(error));  
                });  
                // #endif  
            },  
            requestLogin() {  
                // 这里请求服务端授权登录  
                weixinService.login(function(e) {  
                    console.log("登陆成功" + JSON.stringify(e))  
                }, function(e) {  
                    console.log("登录失败" + JSON.stringify(e))  
                }, {  
                    scope: 'snsapi_userinfo,snsapi_base',  
                    state: 'weChatLoginTest',  
                    appid: '',  
                    appsecret: '',  
                    redirect_uri: 'http%3a%2f%2f192.168.'  
                    //                  redirect_url:'redirect_url'  
                })  
            },  
            //          wxLogOut() {  
            //              weixinService.logout(function(event) {  
            //                  console.log('注销成功 ' + JSON.stringify(event))  
            //              }, function(error) {  
            //                  console.log('注销失败' + JSON.stringify(error));  
            //              });  
            //  
            //          },  
            sendWxCode() {  
                axios.post('"/login?code=" + weixinCode', {  
                    params: {  
                        code: _this.weixinCode  
                    }  
                }).then(function(response) {  
                    console.log(JSON.stringify(response))  
                }).catch(function(response) {  
                    console.log(JSON.stringify(response))  
                })  
            },  
            next1(){  
                this.$router.push({name:'Invitation'})  
            }  
        }

控制台信息:

正在建立手机连接...
正在同步手机端程序文件...
997 KB/s (5096 bytes in 0.004s)
正在启动HBuilder调试基座...
应用my-project已启动...
[{"id":"weixin","description":"微信","authResult":null,"userInfo":null}] at static/js/app.23793335ebd1ebe0c728.js:1
{"scope":"snsapi_userinfo","state":"authorize test","code":"77777777777777777777","lang":"zh_CN","country":"CN","target":{"id":"weixin","description":"微信","authResult":null,"userInfo":null}} at static/js/app.23793335ebd1ebe0c728.js:1
undefined at static/js/app.23793335ebd1ebe0c728.js:1
TypeError: Converting circular structure to JSON
46:48.427 4875 4875 I console : at NUnD.e.exports (file:///storage/emulated/0/Android/data/io.dcloud.H50F6E/apps/H5D421450/www/static/js/vendor.36b6219ffa9154811dec.js:107:97401)
46:48.427 4875 4875 I console : at i.authorize.appid (file:///storage/emulated/0/Android/data/io.dcloud.H50F6E/apps/H5D421450/www/static/js/app.23793335ebd1ebe0c728.js:1:185859)
47:35.381 8335 8359 I console : START JS FRAMEWORK 0.24.4, Build 2018-02-07 17:13. (Vue: 2.5.13-weex.5, Rax: 0.4.20)
47:36.231 8403 8432 I console : START JS FRAMEWORK 0.24.4, Build 2018-02-07 17:13. (Vue: 2.5.13-weex.5, Rax: 0.4.20)
361 at static/js/app.23793335ebd1ebe0c728.js:1
plusEventListenerReady at static/js/app.23793335ebd1ebe0c728.js:1
111 at static/js/app.23793335ebd1ebe0c728.js:1
[{"id":"weixin","description":"微信","authResult":null,"userInfo":null}] at static/js/app.23793335ebd1ebe0c728.js:1
{"scope":"snsapi_userinfo","state":"authorize test","code":"777777777","lang":"zh_CN","country":"CN","target":{"id":"weixin","description":"微信","authResult":null,"userInfo":null}} at static/js/app.23793335ebd1ebe0c728.js:1
undefined at static/js/app.23793335ebd1ebe0c728.js:1
TypeError: Converting circular structure to JSON
48:39.843 8798 8798 I console : at NUnD.e.exports (file:///storage/emulated/0/Android/data/io.dcloud.H50F6E250/apps/H5D421450/www/static/js/vendor.36b6219ffa9154811dec.js:107:97401)
48:39.843 8798 8798 I console : at i.authorize.appid (file:///storage/emulated/0/Android/data/io.dcloud.H50F6E250/apps/H5D421450/www/static/js/app.23793335ebd1ebe0c728.js:1:185859)

2019-03-13 15:59 负责人:无 分享
已邀请:
墨白

墨白 - 80后IT男

人不说了是小白么,不看就走啊,还留言装什么东西啊

1606726660@qq.com

1606726660@qq.com

你这代码 我看都不想看 复制这么多没用的上来

  • 949335988@qq.com (作者)

    我也不知道哪错了。。。我怕是流程错了就把这块儿都粘贴上来了。。。

    2019-03-13 16:23

845355396@qq.com

845355396@qq.com

解决了吗,遇到一样的问题

lbhzfzy

lbhzfzy

5+有注销的文档 账号退出的时候你注销以下微信登陆就行了

要回复问题请先登录注册