收藏
回答

微信获取运动步数,有时候返回为0

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx.getWeRunData 微信iOS客户端 8.0.24 2.25.0
uni.showLoading({
					title: "同步中...",
					mask: true
				})
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						let code = loginRes.code;
						myRequest({
							url: "/wxminiprogram/miniAuth",
							method: "POST",
							urltype:2,
							data: {
								code: code
							}
						})
						.then(res => {
							console.log(res);
							uni.setStorageSync('authToken', {
								token: res.data.data.authToken
							});
							uni.setStorageSync('openid', {
								openid: res.data.data.openid
							});
							uni.setStorageSync('userid', {
								userid: res.data.data.id
							});
							uni.authorize({
								scope: 'scope.werun',
								success() {
									wx.getWeRunData({
										success(res) {
											console.log(res)
											// 拿 encryptedData 到开发者后台解密开放数据
											const encryptedData = res.encryptedData
											const iv = res.iv
											generalRequest({
													url: "/wxminiprogram/getWeRunData",
													method: "POST",
													urltype:"test",
													data: {
														encryptedData: encryptedData,
														iv: iv,
														openid: uni.getStorageSync('openid').openid
													}


												})
												.then((res) => {
													console.log(res)
													let list = res.data.data.stepInfoList
													_this.werun_number = list[list.length - 1].step
													
													generalRequest({
														url: "/carboncoindetail/save",
														method: "POST",
														urltype:"test",
														data: {
															behaviorType: 2,
															userId: uni.getStorageSync('userid').userid,
															step: list[list.length - 1].step
															// step:3001
														}
													})
													.then((res) => {
														uni.hideLoading()
														console.log("步数获取碳积分", res)
														if (res.data.code == 0) {
															_this.tanjifen = res.data.data
															_this.getBushuInfo()
															
															
														} else {
															uni.showToast({
																"title": res.data.msg,
																"icon": "none",
																"duration": 3000
															})
														}
													
													})
													.catch(err => {
														uni.hideLoading()
														throw Error(err)
													})
													
												})
												.catch(err => {
													uni.hideLoading()
													throw Error(err)
												})


										},
										fail(err) {
											uni.hideLoading()
											console.log(err.errMsg)
										}
									})
								}
							})
						})
						.catch(err => {
							throw Error(err)
						})
						//2.将用户登录code传递到后台置换用户SessionKey、OpenId等信息
					},
					fail: function(err) {
						console.log(err)
					},
				});
回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容