账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    微信小程序在app.js中异步获取的openid怎么在index.js中调用
    • 2017-10-11 00:00
    • 10
    27
    0
    getUserInfo: function (cb) {
            var that = this
            if (this.globalData.userInfo) {
                typeof cb == "function" && cb(this.globalData.userInfo)
            } else {
                //调用登录接口
                wx.login({
                    success: function (res) {
                        var code = res.code
                        var appid = 'wx66e4ec7b580c2658'
                        var secret = 'd96fa2a84185d0eb2d782a38533fd850'
                        if (res.code) {
                            // 获取微信运动的数据
                            wx.getWeRunData({
                                success(res) {
                                    var encryptedData = res.encryptedData
                                    var iv = res.iv
                                    // 获取用户信息
                                    wx.getUserInfo({
                                        success: function (res) {
                                            that.globalData.userInfo = res.userInfo
                                            typeof cb == "function" && cb(that.globalData.userInfo)
                                            var data = {
                                                appid: appid,
                                                secret: secret,
                                                code: code,
                                                encryptedData: encryptedData,
                                                iv: iv,
                                                grant_type: 'authorization_code'
                                            }
                                            console.log(data)
                                            wx.request({
                                                //获取openid接口
                                                url: 'http://192.168.0.189/net_sindcorp_anniutingwenzhen/web/sports/identify',
                                                data: data,
                                                method: 'GET',
                                                success: function (res) {
                                                    console.log(res)
                                                    that.globalData.openid = res.data.openid
                                                    // that.globalData.firstLogin = res.data.firstLogin
                                                    that.globalData.stepInfoList = res.data.stepInfoList
                                                    that.globalData.identification = res.data.identification
                                                  
                                                }
                                            })
                                        }
                                    })
                                }
                            })
                        }
                    },
                })
            }
        },
        globalData: {
            userInfo: null,
            openid: null,
            stepInfoList: null,
            identification: null
        }

    直接在index.js中
    app.getUserInfo(function (userInfo) {})中写app.globalData.xxxx
    是不一定能取到的 值没返回来 这个回调怎么写 或者怎么解决呢

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • 借来月光 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部