云调用获取unionid,获取不到了吗?
云调用获取unionid 小程序端代码片段
wx.cloud.callFunction({
name: "user_manage",
data: {
data: detail.userInfo,
weRunData:wx.cloud.CloudID? wx.cloud.CloudID(res.detail.cloudID):"",
req_type: "up_data_msg"
}
})
其中res 为getuserinfo的返回值
云函数代码片段
/**
* 更新用户资料
*/
async function updataUserMsg(wxContext, userData, event) {
const result = {}
const userList = await db.collection("user").where({
_openid: wxContext.OPENID
}).get()
console.log("weRunData==",event.weRunData)
const time = new Date().getTime()
if (userList.data.length > 0) //用户存在 更新时间
{
await db.collection("user").where({
_openid: wxContext.OPENID
}).update({
data: {
last_login_time: time,
unionid: event.weRunData ? event.weRunData.data.unionId : wxContext.UNIONID,
city: userData.city,
sex: userData.gender == 1 ? "男" : (userData.gender == 2 ? "女" : "未知"),
avatar: userData.avatarUrl,
nick_name: userData.nickName,
}
})
result.code = 200
result.msg = "更新成功"
} else {
result.code = 201
result.msg = "用户不存在"
}
return result
}
打印wxRundata
{
"cloudID":"35_r0I6rxrjeMSxhqvT__FB1JIsuhKfHFCHyR2HyTtWPyWJG-LOFYKRymeIjQ4",
"data":{
"avatarUrl":"https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83epK5e6uOc4xGVtshaBn5UzjYvLOIXgOtaoLCsUKicCsqh0aIScNsDMQkCdsYo8ibKzHSSQ6Bibq4U4Zw/132",
"city":"许昌",
"country":"中国",
"gender":1,
"language":"zh_CN",
"nickName":"Charb",
"openId":"orHAM5Gi_hOcw1C6jF8utzAMf1Ak",
"province":"河南",
"watermark":{
"appid":"wxef7acc039df725dd",
"timestamp":1594365592
}
}
}
没有unionid,弱弱的问一下,这个unionid现在不返回了吗?