云函数调用成功,但是信息没返回,报错-601005
- 当前 Bug 的表现(可附上截图)
<button class="login-btn" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">登 录</button> |
在客户端上使用,获取到的phoneNumber信息里面,咩有cloudId信息,然后导致,调用云函数的时候报错了。在开发工具调试的时候,是没有问题的。
- 预期表现
希望能在客户端正常获取到手机号
代码
wxml
<button class="login-btn" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">登 录</button> |
js
getPhoneNumber (e) { var that = this; console.log(e) if (!e.detail.errMsg || e.detail.errMsg != "getPhoneNumber:ok") { wx.showModal({ content: '不能获取手机号码', showCancel: false }) return; } wx.showLoading({ title: '获取手机号中...', }) wx.cloud.callFunction({ name: 'getUserCode', data: { phoneNumber: wx.cloud.CloudID(e.detail.cloudID), // 这个 CloudID 值到云函数端会被替换 obj: { shareInfo: wx.cloud.CloudID(e.detail.cloudID), // 非顶层字段的 CloudID 不会被替换,会原样字符串展示 } }, success: (res) => { console.log(res) if (res.errMsg === 'cloud.callFunction:ok') { wx.hideLoading() console.log('success') that.searchMember(res.result.event.phoneNumber.data.phoneNumber) // that.searchMember('18672726661') } } }) }, |
云函数里面
const cloud = require('wx-server-sdk')exports.main = (event, context) => { // 这里获取到的 openId、 appId 和 unionId 是可信的,注意 unionId 仅在满足 unionId 获取条件时返回 let { OPENID, APPID, UNIONID } = cloud.getWXContext() return { OPENID, APPID, UNIONID, event }} |
开发工具上截图
