node.js - 支付宝异步通知notify_url接收不到参数
高洛峰
高洛峰 2017-04-17 13:10:05
0
2
750

node.js平台express.js框架
更新expreess.js为4后(也改了一些代码)
接到支付宝回调req.body是{}
之前可以正常收到并解析

模拟支付宝数据本地向服务器发送post请求,也是能解出body的
微信支付能够正常回调,只有支付宝不行

请问这会是什么问题?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回覆(2)
黄舟

問題解決了
參考了
http://ju.outofmemory.cn/entry/169748
https://v2ex.com/t/170386
https://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

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!