微信小程序 云调用获取微信步数
前提是:已经获得 微信授权 : https://www.cnblogs.com/fps2tao/p/12490986.html
/** * 获得运动步数 */ getWeRunData: function() { let that = this; console.log(111111); wx.getWeRunData({ success(res) { // 拿 encryptedData 到开发者后台解密开放数据 const encryptedData = res.encryptedData // 或拿 cloudID 通过云调用直接获取开放数据 const cloudID = res.cloudID console.log(cloudID); //云函数获取微信步数 wx.cloud.callFunction({ name: \'weRunData\', data: { weRunData: wx.cloud.CloudID(cloudID), // 这个 CloudID 值到云函数端会被替换 }, success: function (data1){ if (data1.errMsg.includes(\'ok\')) { let result = data1.result.event.weRunData.data; that.setData({ stepInfoList: result.stepInfoList}); //提交步数--开始 let stepInfoList = result.stepInfoList; that.sysWechatRunData(stepInfoList);//同步数据 that.runLlineCanva(stepInfoList);//步数曲线图绘制 } }, fail: res=>{ console.log(\'callFunction test result: \', res) }, complete: res => { console.log(\'callFunction test result: \', res) } }) } }); }
我的 云函数名为: weRunData
// 云函数入口文件 const cloud = require(\'wx-server-sdk\') cloud.init() // 云函数入口函数 exports.main = async (event, context) => { const wxContext = cloud.getWXContext() return { event, openid: wxContext.OPENID, appid: wxContext.APPID, unionid: wxContext.UNIONID, } }