Express JS和CoinPayments:无法获取IPN通知请求的请求正文



所以这是我的问题,我使用Express JS,我正在使用coinPayments设置支付,所有操作都是npm coinPayments,但我无法使用IPN 获得任何实体

router.post(
`/notify`,
(req, res, next) => {
res.send('ok');
console.log('------------------------------ipn--------------------------------------');
console.log('body', req.body);
console.log('------------------------------ipn--------------------------------------');
if (
!req.get(`HMAC`) ||
!req.body.ipn_mode ||
req.body.ipn_mode !== `hmac` ||
MERCHANT_ID !== req.body.merchant
) {
return next(new Error(`Invalid request`));
}
let isValid;
let error;
try {
isValid = verify(req.get(`HMAC`), IPN_SECRET, req.body);
} catch (e) {
error = e;
}
if (error && error) {
return next(error);
}
if (!isValid) {
return next(new Error(`Hmac calculation does not match`));
}
return next();
}

我总是收到一个空的需求正文

------------------------------ipn--------------------------------------
body {}
------------------------------ipn--------------------------------------
Invalid request at router.post.txn_id.txn_id

有人知道为什么吗?我该怎么解决?

来自coinpayment文档

它是通过制作标准HTTP POST来实现的(application/x-www-form-urlencoded(通过https://或http://服务器上脚本或CGI程序的URL。

在Express服务器中,您可能需要添加中间件来解析url编码格式的请求:

app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded

最新更新