search

Home  >  Q&A  >  body text

node.js - 支付宝异步通知notify_url接收不到参数

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

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

请问这会是什么问题?

高洛峰高洛峰2770 days ago802

reply all(2)I'll reply

  • 黄舟

    黄舟2017-04-17 13:12:05

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

    reply
    0
  • 黄舟

    黄舟2017-04-17 13:12:05

    It’s usually a Content-Type problem

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

    https://v2ex.com/t/170386

    reply
    0
  • Cancelreply