先在前端通过wx.login获取res.code,然后发送到后端,在后端使用axios.post()
调用https://api.weixin.qq.com/sns...
const url = 'https://api.weixin.qq.com/sns/jscode2session';
const unionid = axios.post(url, {
appid: 'appid',
secret: 'secret',
js_code: obj,
grant_type: 'authorization_code',
});
最好不要,因为前端就是明文的。
你把 appid 和 secret 暴露出来了,有心之人就可以把你这 appid 和 secret 拿走了