getWeRunData 获取微信运动 不弹授权窗口
发布于 5 年前 作者 li83 3918 次浏览 来自 问答

onLoad: function(options) {

var that = this;

wx.login({

success: function(res) {

if (res.code) {

wx.request({

url: https://api.weixin.qq.com/sns/jscode2session?appid= + app.globalData.appid + ‘&secret=’ + app.globalData.secret + ‘&js_code=’ + res.code + ‘&grant_type=authorization_code’,

header: {

‘content-type’: ‘json’

},

success: function(res) {

var session_key = res.data.session_key;

app.globalData.openid = res.data.openid;

wx.getWeRunData({

success: function(res) {

var encryptedData = res.encryptedData;

var iv = res.iv;

//使用解密工具,链接地址:

//https://codeload.github.com/gwjjeff/cryptojs/zip/master

var pc = new WXBizDataCrypt(app.globalData.appid, session_key);

var runData = pc.decryptData(encryptedData, iv)

if (runData.stepInfoList) {

runData.stepInfoList = runData.stepInfoList.reverse()

runData.stepInfoList[0].data = util.formatDate(new Date(runData.stepInfoList[0].timestamp * 1000))

that.setData({

todayBu: runData.stepInfoList[0]

})

that.countInterval(runData.stepInfoList[0].step);

}

},

fail: function(res) {

wx.showModal({

title: ‘提示’,

content: ‘获取微信运动步数,需要开启计步权限’,

success: function(res) {

if (res.confirm) {

//跳转去设置

wx.openSetting({

success: function(res) {

that.onLoad()

}

})

} else {

wx.navigateTo({

url: ‘…/…/pages/index/index’,

})

}

}

})

}

})

}

})

}

}

})

},

在页面load事件里获取用户微信运动步数,开发工具运行和真机调试运行都能弹出获取用户授权的弹出窗,但是上传后的体验版就没有任何反应,请问谁遇到相同问题,帮忙解决一下,官方人员是不是能给解释一下问题出在哪里了,多谢多谢~

1 回复

勾选不校验合法域名,打开调试即可

但是需要注意的是https://api.weixin.qq.com在上线后不能使用的,必须在服务端调用


回到顶部