我试图在前端构建于 Angular 11 和后端 Node js 的应用程序上集成 2Checkout,我设法集成了 2Checkout 的 IPN(即时付款通知),但我收到一条通知:“”> <块引用>
我们的系统检测到您的网络钩子响应缓慢。
多次检查文档后,我发现我需要返回 <EPAYMENT>20050303123434|7bf97ed39681027d0c45aa45e3ea98f0</EPAYMENT>
但我仍然在仪表板上得到相同的响应,并且 2Checkout 无法验证
我的代码:
const bodyParse = parse(req.body);
let date = new Date();
let updatedDate =
date.getFullYear().toString() +
pad2(date.getMonth() + 1) +
pad2(date.getDate()) +
pad2(date.getHours()) +
pad2(date.getMinutes()) +
pad2(date.getSeconds());
let hashToReturn = hmac(
`${bodyParse['IPN_PID[]'].length}${bodyParse['IPN_PID[]']}${bodyParse['IPN_PNAME[]'].length}${bodyParse['IPN_PNAME']}${bodyParse['IPN_DATE'].length}${bodyParse['IPN_DATE']}${updatedDate.length}${updatedDate}`
);
console.log('hashToReturn', hashToReturn);
res.send(`Verified OK! <EPAYMENT>${updatedDate}|${hashToReturn}</>`)
function hmac(stringToHash: string) {
const secretKey = process.env.checkoutSecret;
const hmac = crypto.createHmac('MD5', secretKey);
return hmac.update(stringToHash).digest('hex');
}
我不知道我遗漏了什么或出了什么问题,我试图联系 2Checkout 支持,但他们只是回复了来自 PHP 的代码示例和文档中的部分。