前端发送code到后端
wx.login({
success: (res) => {
const usercode=res.code
myrequest({url:'/getopenid',data: {usercode:usercode},method: 'POST'}).then(res1=>{
console.log(res1)
})
后端正常接收
[Object: null prototype] {
usercode: '0e3p9p1w3uYLA03L3k4w3wiXaF3p9p1J'
}
后端代码
exports.getopenid=async (req,res)=>{
const code=req.body
console.log(code)
var params = {
grant_type:'authorization_code',
appid: '正确在详情里复制',
//secret 更新时间20230504
secret: '已经于20230504重置并更新',
js_code:code
}
params=JSON.stringify(params)
axios({
method:'GET',
url:'https://api.weixin.qq.com/sns/jscode2session'+params
}).then(res2=>{
res.send(res2.data)
})
}
前端收到的返回信息
- {data: {…}, header: {…}, statusCode: 200, cookies: Array(0), errMsg: "request:ok"}
- cookies: []
- data: {errcode: 40066, errmsg: "invalid url, rid: 6453aca1-0ab89620-2cd6e1ce"}
- errMsg: "request:ok"
- header: {X-Powered-By: "Express", Access-Control-Allow-Origin: "*", Content-Type: "application/json; charset=utf-8", Content-Length: "73", ETag: "W/"49-BmpGmYt4SlV421N/g74TFXpWHNA"", …}
- statusCode: 200
- __proto__: Object
请求大师指点,不想开云
https://developers.weixin.qq.com/community/develop/article/doc/00026e46924a30eddbce713d651413看看这个是否可以帮助到你