云函数实现登陆功能似乎有点问题?
发布于 4 年前 作者 xia44 5514 次浏览 来自 官方Issues

大家好,我这个小程序端函数似乎没有实现调用云函数端的程序,大家帮忙看下是哪的问题,谢谢

login() {

wx.cloud.callFunction({

name: "getopenid",

success(res) {

let openid = res.result.openid

let that = this;

//登陆获取用户信息

admin.get({

success: (res) => {

let user = res.data;

console.log(res.data);

for (let i = 0; i < user.length; i++) { //遍历数据库对象集合

if (openid !== user[i]._openid) {

wx.showToast({

title: '您的账号已被禁',

icon: 'none',

duration: 1500

})

} else {

wx.navigateTo({

url: '/pages/test/test', //这里是成功登录后跳转的页面

})

break

}

}

}

})

},

})

},

云函数端的程序为:

// 云函数入口文件

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,

}

}

1 回复

为什么查找用户不直接写在云函数里面,等待返回openID之后再查找用户既浪费时间又浪费云资源

回到顶部