如何验证JS

问题描述 投票:0回答:1

这就是他们要求这样做的方式。 如何为其编写JavaScript代码? enter image description here

Edit:2025。您可以在此处找到详细信息,并使用CashFree SDK为您执行此操作。

https://www.cashfree.com/docs/payments/online/webhooks/overview#sdk-verification-built-in-pappacrechist thanks向上头。我们正在努力改进Webhook文档。同时,验证Webhook的步骤为-

javascript node.js cryptography webhooks cashfree
1个回答
0
投票
从webhook端点获取有效载荷

签名 验证签名

这里的有效载荷是指

raw
    json主体,而不是BodyParser解析的东西。我将分享Express的代码。
  1. 获取有效载荷
  2. //Set up your server like this var express = require('express') var bodyParser = require('body-parser'); var crypto = require('crypto'); var app = express() //This part is to get the rawBody app.use( express.json({ limit: '5mb', verify: (req, res, buf) => { req.rawBody = buf.toString(); }, }) ); app.use(bodyParser.json()); //This is your endpoint app.post('/webhook', function(req, res) { console.log(req.rawBody); const ts = req.headers["x-webhook-timestamp"] const signature = req.headers["x-webhook-signature"] console.log("ts --> ", ts); console.log("expected sign --> ", signature); const genSignature = verify(ts, req.rawBody) if(signature === genSignature){ res.send('OK') } else { res.send("failed") } })
  3. verifying签名
  4. function verify(ts, rawBody){ const body = ts + rawBody const secretKey = "<your secret key>"; let genSignature = crypto.createHmac('sha256',secretKey).update(body).digest("base64"); return genSignature }


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.