- 当前 Bug 的表现(可附上截图)
- 预期表现
返回登录的session_key
- 复现路径
- 提供一个最简复现 Demo
小程序云端:
const cloud = require(‘wx-server-sdk’)
cloud.init({ env: ‘wxcloudtest-399ef4’ })
const axios = require(‘axios’)
// 云函数入口函数
exports.main = async (event, context) => {
const code = event.code
const para = {
appid: ‘wx38369e8c688673ed’,
secret: ‘351193b1b3930ef1e89f7d1cf9ebfc83’,
js_code: code,
grant_type: ‘authorization_code’
}
return new Promise((resolve, reject) => {
axios.get(`https://api.weixin.qq.com/sns/jscode2session`, {
params: para
})
.then(function (res) {
resolve(res)
})
.catch(function (error) {
return error
})
})
}
小程序端:
wx.login({
success(res) {
if (res.code) {
//发起网络请求
console.log(res.code)
wx.cloud.callFunction({
name: ‘sessionkey’,
data: { code: res.code },
success: res => {
console.log(res);
},
fail: err => {
console.error(’[云函数] [sessionkey] 调用失败’, err)
}
})
} else {
console.log(‘err’)
}
}
})