PHP CURL 显示 Post 字段数组错误,而其他代码工作正常

PHP CURL Showing Post Fields Array Error While Other Code Works Fine

我有两个 php 页面 运行 用于 API 的卷曲代码。

Page1.php

$fields = array(
        'item' => array(
            'name' => 'Extra Chair',
            'amount' => 2300,
            'currency' => 'USD'
        ),
        'quantity' => '1'
    );

$fields_string = http_build_query($fields);

然后我在如下所示的 CURL 中使用这个字符串。它工作正常,我收到了回复。

CURLOPT_POSTFIELDS => $fields_string,

Page2.php

$fields = array(
        'plan_id' => 'plan_DiUORv81uf2uyu',
        'total_count' => 120,
        'customer_notify' => true,
        'addons' => array(
            'item' => array(
                'name' => 'Extra',
                'amount' => 2300,
                'currency' => 'USD'
            )
        ),
        'notes' => array(
            'notes_key' => 'Beam me up Scotty'
        )
    );

    $fields_string = http_build_query($fields);

作为CURLOPT_POSTFIELDS => $fields_string,使用后,报错

[description] => addons must be an array

我正在按照 API 显示的文档示例中的说明进行操作 HERE

文档示例:

curl -u <YOUR_KEY_ID>:<YOUR_KEY_SECRET> \
-X POST https://api.razorpay.com/v1/subscriptions \
-H "Content-Type: application/json" \
-d '{
  "plan_id": "plan_00000000000001",
  "total_count": 6,
  "start_at": 1561852800,
  "addons": [
    {
      "item": {
      "name": "Delivery charges",
      "amount": 30000,
      "currency": "INR"
      }
    }
  ],
  "notes": {
    "notes_key": "Beam me up Scotty"
  },
  "customer_notify": 1,
  "expire_by":"1561939199"
}'

根据文档,您需要在项目

之前再包含一个数组
$fields = array(
  'plan_id' => 'plan_DiUORv81uf2uyu',
  'total_count' => 120,
  'customer_notify' => true,
  'addons' => [
    [
      'item' => array(
        'name' => 'Extra',
        'amount' => 2300,
        'currency' => 'USD'
      )
    ]
  ],
  'notes' => array(
    'notes_key' => 'Beam me up Scotty'
  )
);