wx.setStorageSync 真机测试与开发工具正常,体验版失效。
发布于 4 年前 作者 taogong 12167 次浏览 来自 官方Issues
 wx.login({
        success (res) {
          if (res.code) {
            // console.log(res)
             //声明CODE,获取小程序传过来的CODE 
            const code = res.code; 
            //配置appid 
            const appid = ""; 
            //配置appscret 
            const secret = "";
            wx.request({
              url: 'https://api.weixin.qq.com/sns/jscode2session',
              method: 'GET',
              data: {
                appid: appid,
                js_code: res.code,
                secret: secret,
                grant_type: 'authorization_code',
              },
              header: {
                'content-type''application/json' // 默认值
              },
              success(res) {
                console.log(res)
                var openId = res.data.openid;
                var sessionKey = res.data.session_key;
                // sessionKey + openid存储到本地
                console.log(openId)
                Notify({ type'danger', message: openId});
                if(openId){
                  wx.setStorageSync('openId', openId);
                  wx.setStorageSync('sessionKey', sessionKey);
                  global.globalData.openId = openId
                  global.globalData.sessionKey = sessionKey
                }
              }
            })
          } else {
            console.log('登录失败!' + res.errMsg)
            Notify({ type'danger', message: res.errMsg});
          }
        }
      })
1 回复
https://api.weixin.qq.com/sns/jscode2session
这个接口不是给服务端调的吗,你前端调干嘛,体验版应该校验出非合法域名进不了这个方法的

回到顶部