我使用云托管,搭建一个node,express的demo,上传,从头部获取用户openid,不存在
获取header的代码如下:
console.log(req.headers)
res.send(`this is from demo5`+ req.headers['X-WX-OPENID']);
打印的日志如下:
{"traceId":"d56d2663925f4d1f8bbdb8deffcf6b2f","httpPath":"/container-demo-test/5","level":"info","appName":"demo-test","childOf":"","source":"http","invoker":"","ua":"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 wechatdevtools/1.03.2011120 MicroMessenger/7.0.4 Language/zh_CN webview/","version":"demo-test-004","invokerIp":"","spanId":"a0220dbf42dcfe4e","requestId":"ZDU2ZDI2NjM5MjVmNGQxZjhiYmRiOGRlZmZjZjZiMmYsYTAyMjBkYmY0MmRjZmU0ZSxvbg==","service":"app","domain":"dev-jjrr1.service.tcloudbase.com","startTime":"1609901261645","event":"GET","timeCost":"16","statusCode":"200"}
https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/container/wxinfo.html
你好,受 node 影响,Header 中的值需要以小写获取:req.headers['x-wx-openid']。