收藏
回答

线上版本用户第一次登录时小程序getUserInfo调用接口 报错

问题模块
API和组件
wx.showLoading({ title: '加载中' })
 var that = this
 var wxLogin = wxApi.wxLogin()
 wxLogin().then(res => {
   var url = config.getOpenidUrl;//https://api.weixin.qq.com/sns/jscode2session
   var params = {
     appid: app.globalData.appid,
     secret: app.globalData.secret,
     js_code: res.code,
     grant_type: "authorization_code"
     //code: res.code
   }
   return wxRequest.getRequest(url, params)
 }).
   then(res => {
     console.log(res)
     app.globalData.openid = res.data.openid
     wx.setStorageSync('openid', app.globalData.openid)
    //var wxGetUserInfo = wxApi.wxGetUserInfo()
     return wx.getUserInfo({
       success: function (res) {
         console.log(res)
         app.globalData.userInfo = res.userInfo
         wx.setStorageSync('userInfo', app.globalData.userInfo)
 
         var params = {
           appid: app.globalData.appid,
           openid: app.globalData.openid,
           nickname: res.userInfo.nickName,
           sex: res.userInfo.gender,
           language: res.userInfo.language,
           province: res.userInfo.province,
           country: res.userInfo.country,
           headimgurl: res.userInfo.avatarUrl
         }
         var url = app.globalData.ip + config.register;//插入用户信息到数据库
         return wxRequest.postRequest(url, params)
       }
 
     })


最后一次编辑于  2017-05-11
回答关注问题邀请回答
收藏