ホームページ  >  に質問  >  本文

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

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

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

请问这会是什么问题?

高洛峰高洛峰2721日前748

全員に返信(2)返信します

  • 黄舟

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

    问题解决了
    参考了
    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}))
    

    返事
    0
  • 黄舟

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

    一般是Content-Type问题

    bing搜索关键字 -> "支付宝 notify_url Content-Type" 第三个

    https://v2ex.com/t/170386

    返事
    0
  • キャンセル返事