Stripe payments StripeSignatureVerificationError:未找到与负载的预期签名匹配的签名 我正在本地主机上测试Webhook,方法是侦听事件并将其从Stripe CLI转发到本地主机。我使用的是endpoint secret(在“stripe-listen”命令之后提供的stripe cli)。 仍然有签名验证错误!!

Stripe payments StripeSignatureVerificationError:未找到与负载的预期签名匹配的签名 我正在本地主机上测试Webhook,方法是侦听事件并将其从Stripe CLI转发到本地主机。我使用的是endpoint secret(在“stripe-listen”命令之后提供的stripe cli)。 仍然有签名验证错误!!,stripe-payments,webhooks,Stripe Payments,Webhooks,您是否设置了其他bodyParser中间件?您需要确保webhook路由只使用原始主体解析器,如下例所示:app.use((req,res,next)=>{if(req.originalUrl=='/stripe-webhook'){next();}else{express.json()(req,res,next)}); router.post( "/", bodyParser.raw({ type: "application/json" }),

您是否设置了其他
bodyParser
中间件?您需要确保webhook路由只使用原始主体解析器,如下例所示:app.use((req,res,next)=>{if(req.originalUrl=='/stripe-webhook'){next();}else{express.json()(req,res,next)});
router.post(
  "/",
  bodyParser.raw({ type: "application/json" }),
  async (req, res) => {
    // Retrieve the event by verifying the signature using the raw body and secret.
    let event;
    const signature = req.headers["stripe-signature"]
    const endPointSecret = "whsec_***"
    console.log(signature)
    console.log(req.body)
    try {
      event = stripe.webhooks.constructEvent(
        req.body,
        signature,
        endPointSecret
      );
    } catch (err) {
      console.log(err);
      return res.sendStatus(400);
    }
    // Extract the object from the event.
    const dataObject = event.data.object;
    console.log(dataObject)
    res.sendStatus(200)
  }
);
I am testing Webhook on localhost by listening and forwarding event from

Stripe CLI

to localhost. And I am using endpoint secret (from stripe cli provided after "stripe listen" command).

Still having signature verification error!!