Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 读取Json中的条带webhook值_Php_Stripe Payments_Webhooks - Fatal编程技术网

Php 读取Json中的条带webhook值

Php 读取Json中的条带webhook值,php,stripe-payments,webhooks,Php,Stripe Payments,Webhooks,我尝试在PHP中读取条带webhook的值。 已发送的webhook具有以下格式: { "created": 1312403445, "livemode": false, "id": "evt_00000000000000", "type": "checkout.session.completed", "object": "event", "request": null, "pending_webhooks": 1, "api_version": "2019-03

我尝试在PHP中读取条带webhook的值。 已发送的webhook具有以下格式:

{
  "created": 1312403445,
  "livemode": false,
  "id": "evt_00000000000000",
  "type": "checkout.session.completed",
  "object": "event",
  "request": null,
  "pending_webhooks": 1,
  "api_version": "2019-03-14",
  "data": {
    "object": {
      "id": "cs_00000000000000",
      "object": "checkout.session",
      "billing_address_collection": null,
      "cancel_url": "https://example.com/cancel",
      "client_reference_id": null,
      "customer": null,
      "customer_email": null,
      "display_items": [
        {
          "amount": 1500,
          "currency": "usd",
          "custom": {
            "description": "Comfortable cotton t-shirt",
            "images": null,
            "name": "T-shirt"
          },
          "quantity": 2,
          "type": "custom"
        }
      ],
      "livemode": false,
      "locale": null,
      "payment_intent": "pi_00000000000000",
      "payment_method_types": [
        "card"
      ],
      "subscription": null,
      "success_url": "https://example.com/success"
    }
  }
}
我将发送的值写入数据库中的表。我的服务器中的PHP是:

    require 'connectFile.php'; // connect my database
    require_once('vendor/autoload.php');
    require_once('vendor/stripe/stripe-php/init.php');

    $input = @file_get_contents('php://input');
    $event_json = json_decode($input);
    $value_id=$event_json->data->object->id;
    //value_created= $event_json->created;

    $sql = "INSERT INTO myTable VALUES ("test","."'".$value_id."'".")";
    $prepare = $pdo->prepare($sql);
    $prepare ->execute();
    http_response_code(200); // PHP 5.4 or greater
问题是,当我尝试读取数据->对象->id时,它会在数据库中写入0。但是,如果我读取value\u created=$event\u json->created,它将正确读取值


你知道什么是错误的,为什么它读为0吗?

我认为你准备了错误的查询。尝试:

$sql = "INSERT INTO myTable VALUES ('test',':prepared_id')";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':prepared_id', $value_id, PDO::PARAM_STR);
$stmt->execute();

还有一种更安全的方法,因为在查询中构建字符串是不安全的:D

您的数据库、某些关系可能有问题,触发了类似这样的事件?我没有别的想法。