Express JS 和 CoinPayments:无法获取 IPN 通知请求的请求正文
Express JS and CoinPayments: coudn't get the request body of IPN notification request
所以这是我的问题,我使用 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();
}
我总是得到一个空的req.body
------------------------------ipn--------------------------------------
body {}
------------------------------ipn--------------------------------------
Invalid request at router.post.txn_id.txn_id
有谁知道为什么,我该如何解决?
It is implemented by making a standard HTTP POST
(application/x-www-form-urlencoded) call over a https:// or http://
URL to a script or CGI program on your server.
在您的 Express 服务器中,您可能需要添加中间件来解析 urlencoded 格式的请求:
app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
所以这是我的问题,我使用 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();
}
我总是得到一个空的req.body
------------------------------ipn--------------------------------------
body {}
------------------------------ipn--------------------------------------
Invalid request at router.post.txn_id.txn_id
有谁知道为什么,我该如何解决?
It is implemented by making a standard HTTP POST (application/x-www-form-urlencoded) call over a https:// or http:// URL to a script or CGI program on your server.
在您的 Express 服务器中,您可能需要添加中间件来解析 urlencoded 格式的请求:
app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded