1

Webhook が、提供した URl にデータを送信しています。データをキャッチしようとしています。これは私が使用しているコードです:-

if ($this->input->server('REQUEST_METHOD') == 'POST')
{
    file_put_contents('test.txt', file_get_contents('php://input'));
    ......................
}

txt ファイルに保存されたデータは次のとおりです。

{
  "created_at": "2017-04-04 12:03:07 UTC",
  "href": "http://api.groovehq.com/v1/tickets/131",
  "links": {
    "customer": {
      "id": "0454984580",
      "href": "http://api.groovehq.com/v1/customers/ncc2017customer@gmail.com"
    },
    "drafts": {
      "href": "http://api.groovehq.com/v1/tickets/131/drafts"
    },
    "state": {
      "href": "http://api.groovehq.com/v1/tickets/131/state"
    },
    "messages": {
      "href": "http://api.groovehq.com/v1/tickets/131/messages"
    }
  },
  "number": 131,
  "priority": "low",
  "resolution_time": null,
  "state": "unread",
  "title": "gh",
  "updated_at": "2017-04-04 12:03:07 UTC",
  "system_updated_at": "2017-04-04 12:03:07 UTC",
  "assigned_group_id": null,
  "assigned_group": null,
  "closed_by": null,
  "tags": [

  ],
  "mailbox": "Inbox",
  "mailbox_id": "1923237790",
  "message_count": 1,
  "summary": "Complaint Date: 2017-4-22 Service Provider: Airtel Type of Complaint: Billing NCC need to do: Investigate and resolve the issue Complaint Details: Vb",
  "type": "API",
  "snoozed_until": null,
  "last_message": "Complaint Date: 2017-4-22<br />\nService Provider: Airtel<br />\nType of Complaint: Billing<br />\nNCC need to do: Investigate and resolve the issue<br />\nComplaint Details: Vb",
  "assignee": null,
  "app_url": "https://matrixdroid.groovehq.com/groove_client/tickets/44746020",
  "app_customer_url": "https://matrixdroid.groovehq.com/groove_client/contacts/customers/17295897",
  "customer_name": "ncc2017customer@gmail.com",
  "last_message_plain_text": "Complaint Date: 2017-4-22\nService Provider: Airtel\nType of Complaint: Billing\nNCC need to do: Investigate and resolve the issue\nComplaint Details: Vb"
}

さて、links->customer->hrefデータを取得する必要があります。これを取得するにはどうすればよいですか?

私はこれを試しました: -

$json_data = file_get_contents('php://input');
$json_decode_data = json_decode($json_data);
file_put_contents('test.txt', $json_decode_data['links']['customer']['href']);

txt ファイルには何も書き込まれません。href データを解析するにはどうすればよいですか?

4

2 に答える 2