node.js平台express.js框架更新expreess.js为4后(也改了一些代码)接到支付宝回调req.body是{}之前可以正常收到并解析
模拟支付宝数据本地向服务器发送post请求,也是能解出body的微信支付能够正常回调,只有支付宝不行
请问这会是什么问题?
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
問題解決了參考了http://ju.outofmemory.cn/entry/169748https://v2ex.com/t/170386https://cnodejs. org/topic/5566952ad4ca459f5267ac59
方案一:
app.use(bodyParser.urlencoded({ type: function(req) { return /x-www-form-urlencoded/.test(req.headers['content-type']); }, extended: true }));
不過不理解這個type是什麼意思。 。 。 把所有content-type都轉成x-www-form-urlencoded嗎? 這樣不會有問題嗎?
方案二:或是這樣,比較好理解(3個app.user注意順序)
app.use(function (req, res, next){ if (req.url === 'your_alipay_notify_url') { req.headers['content-type'] = 'application/x-www-form-urlencoded'; } next(); }); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended:true}))
一般是Content-Type問題
bing搜尋關鍵字 -> "支付寶 notify_url Content-Type" 第三個
https://v2ex.com/t/170386
問題解決了
參考了
http://ju.outofmemory.cn/entry/169748
https://v2ex.com/t/170386
https://cnodejs. org/topic/5566952ad4ca459f5267ac59
方案一:
不過不理解這個type是什麼意思。 。 。
把所有content-type都轉成x-www-form-urlencoded嗎?
這樣不會有問題嗎?
方案二:
或是這樣,比較好理解(3個app.user注意順序)
一般是Content-Type問題
bing搜尋關鍵字 -> "支付寶 notify_url Content-Type" 第三個
https://v2ex.com/t/170386