收藏
回答

云托管,怎么获取openid?

我使用云托管,搭建一个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

回答关注问题邀请回答
收藏

1 个回答

  • Shannon
    Shannon
    2021-01-07

    你好,受 node 影响,Header 中的值需要以小写获取:req.headers['x-wx-openid']。

    2021-01-07
    有用 2
    回复
登录 后发表内容
问题标签