问题模块 | 框架类型 | 问题类型 | 终端类型 | AppID | 基础库版本 |
---|---|---|---|---|---|
云开发 | 小游戏 | 需求 | 工具 | https://api.weixin.qq.com/sns/jscode2session | 最新 |
云函数request到https://api.weixin.qq.com/sns/jscode2session这个接口,返回都是null
是否不能通过云函数来获取openID呢?
网友回复
? GeoffreyQiao ?:
貌似你哪怕请求一个空的云函数,哪怕下面这样的,比方说这个云函数名是“getOpenId”
exports.main = async (event) => { return event.userInfo.openId } |
你在客户端请求云函数
wx.cloud.init() Page({ //...其他内容 onShow(){ wx.cloud.callFunction({ name: 'getOpenId' , success: res => console.log(res.result) }) } }) |
你客户端本地的控制台打印结果就是当前用户的openId啊。