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

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

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

请问这会是什么问题?

高洛峰
高洛峰

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

reply all(2)
黄舟

Problem solved
Reference
http://ju.outofmemory.cn/entry/169748
https://v2ex.com/t/170386
https://cnodejs. org/topic/5566952ad4ca459f5267ac59

Option 1:

app.use(bodyParser.urlencoded({
  type: function(req) {
    return /x-www-form-urlencoded/.test(req.headers['content-type']);
  },
  extended: true
}));

But I don’t understand what this type means. . .
Convert all content-types to x-www-form-urlencoded?
Isn’t this a problem?

Option 2:
Or this, easier to understand (pay attention to the order of 3 app.users)

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}))
黄舟

It’s usually a Content-Type problem

bing search keywords -> "Alipay notify_url Content-Type" third

https://v2ex.com/t/170386

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!