微信小程序云开发获取微信运动开放数据

微信运动属于敏感数据,如果直接调用wx.getWeRunData接口的话获取到的数据是加密后的,所以用云开发的话,步骤如下:

1. 开通云开发后,新建一个Node.js云函数:

2. 获取开放数据必须得用户授权登录,因此要先调用wx.login接口,建好云函数后,获取微信运动数据的完整代码如下:

Page({
  data: {
    step:null
  },
  onLoad: function (options) {
    var that = this;
    wx.login({
      success:function(resLonin){
        console.log(resLonin)
        console.log(resLonin.code)
        wx.getWeRunData({
          success:function(resRun){
            console.log("微信运动密文:")
            console.log(resRun)
            wx.cloud.callFunction({
              name:'weRun',//云函数的文件名
              data:{
                weRunData: wx.cloud.CloudID(resRun.cloudID),
                obj:{
                  shareInfo: wx.cloud.CloudID(resRun.cloudID)
                }
              },
              success: function (res) {
                console.log("云函数接收到的数据:")
                console.log(res)
                let step = res.result.event.weRunData.data.stepInfoList[30].step
                that.setData({
                  step:step
                })
                console.log("得到的今日步数:",that.data.step)
              }
            })
          }
        })
      }
    })
  },
})

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值