首页 > 解决方案 > 无法解析 razropay 的 webhook

问题描述

webhook ping 成功,但我无法解析它,我花了 4 个小时仍然没有运气,我尝试了所有方法但仍然失败,我只是不知道为什么会发生这种情况,我已经将它用于 stripe webhook,它有效,但这适用于剃刀工资

以下是我在 webhook 上收到的标题和响应:来源:https ://webhook.site/

标头

connection  close
accept-encoding gzip
x-razorpay-signature    f0087994b59ee5ec1b1828a87f794c89bb398033a428bb79971875e5f295322e
x-razorpay-event-id Gb5kMCdcAZ8jJ8
request-id  Gb5kMCdcAZ8jJ8
content-type    application/json
content-length  1053
user-agent  Razorpay-Webhook/v1
host    webhook.site

原始内容

    {
  "entity": "event",
  "account_id": "acc_DOXUp08NQX6Sr9",
  "event": "payment.captured",
  "contains": [
    "payment"
  ],
  "payload": {
    "payment": {
      "entity": {
        "id": "pay_Gb5kLMBMjON6So",
        "entity": "payment",
        "amount": 1132,
        "currency": "USD",
        "base_amount": 82174,
        "base_currency": "INR",
        "status": "captured",
        "order_id": "order_Gb5kEv5w8pveU5",
        "invoice_id": null,
        "international": false,
        "method": "card",
        "amount_refunded": 0,
        "refund_status": null,
        "captured": true,
        "description": null,
        "card_id": "card_Gb5kLUZEfKlXF4",
        "card": {
          "id": "card_Gb5kLUZEfKlXF4",
          "entity": "card",
          "name": "231231231231231231",
          "last4": "8826",
          "network": "Visa",
          "type": "prepaid",
          "issuer": "SBIN",
          "international": false,
          "emi": false,
          "sub_type": "business"
        },
        "bank": null,
        "wallet": null,
        "vpa": null,
        "email": "niteshkmr366@gmail.com",
        "contact": "+918169179450",
        "notes": {
          "ytsubme_account_email": "niteshkmr366@gmail.com",
          "phone": "8169179450"
        },
        "fee": 1644,
        "tax": 0,
        "error_code": null,
        "error_description": null,
        "error_source": null,
        "error_step": null,
        "error_reason": null,
        "acquirer_data": {
          "auth_code": null
        },
        "created_at": 1613226609
      }
    }
  },
  "created_at": 1613226609
}

我的 PHP 代码:

<?
$data = file_get_contents('php://input');           
$obj = json_decode($data);
file_put_contents('data.txt',$data);
//data.txt file is still empty
?>

标签: phpjsonwebhooksrazorpay

解决方案


感谢@IMSoP,在您担心解析它之前提醒我理清为什么它是空的。

我的 webhook 正在 ping 到需要登录的 URL,)更多信息:SESSIONS:即如果没有设置会话,它会将它们重定向到 / 页面。)

由于我得到了空数据,对此我感到很愚蠢。


推荐阅读