首页 > 解决方案 > 如何解析来自 Easyship webhook 的响应

问题描述

我正在与 Easyship 合作,并尝试在订单状态发生变化时解析来自他们的 webhook 的响应。首先,我什至无法接收数据,并尝试了以下方法:

print_r($_POST, TRUE)
print_r($_GET, TRUE)
print_r($_REQUEST, TRUE)
print_r(file_get_contents("php://input"), TRUE)

只有最后一个接收任何数据。我收到的数据如下:

@"event_type":"shipment.tracking.checkpoints.created","resource_type":"shipment","resource_id":"ESHK25561976","tracking_status":{"easyship_shipment_id":"ESHK25561976","platform_order_number":"30","origin":"HK","destination":"HK","company_order_number":null,"status":"In Transit to Customer","tracking_number":"SF1042689716516","tracking_page_url":"https://www.trackmyshipment.co/shipment-tracking/ESHK25561976","checkpoints":[{"order_number":1,"handler":"SF Express Local","message":null,"location":null,"city":null,"country_name":"Hong Kong","country_iso3":"HKG","state":null,"postal_code":null,"checkpoint_time":"2020-10-16T17:47:10.802Z","primary_status":"Pending Pickup Confirmation",@"order_number":2,"handler":"SF Express Local","message":"Your package has been prepared and is awaiting pickup from SF Express Local","location":null,"city":null,"country_name":"Hong Kong","country_iso3":"HKG","state":null,"postal_code":null,"checkpoint_time":"2020-10-16T18:00:55.285Z","primary_status":"Awaiting Scan from Courier",@"order_number":101,"handler":"Sf Express","message":"【Hong Kong】 S.F. Express has picked up the shipment","location":"Hong Kong","city":"Hong Kong","country_name":null,"country_iso3":null,"state":null,"postal_code":null,"checkpoint_time":"2020-10-19T14:45:47.000Z","primary_status":"In Transit to Customer",@"order_number":102,"handler":"Sf Express","message":"【Hong Kong】 Shipment transiting to next station","location":"Hong Kong","city":"Hong Kong","country_name":null,"country_iso3":null,"state":null,"postal_code":null,"checkpoint_time":"2020-10-19T17:31:46.000Z","primary_status":"In Transit to Customer",@"order_number":103,"handler":"Sf Express","message":"【Hong Kong】 Shipment arrive at Hong Kong distribution center","location":"Hong Kong","city":"Hong Kong","country_name":null,"country_iso3":null,"state":null,"postal_code":null,"checkpoint_time":"2020-10-19T20:37:59.000Z","primary_status":"In Transit to Customer"]}}

我不确定如何解析它以提取我需要的信息。我尝试使用 json_decode 和 parse_str 的组合无济于事。

有小费吗?

标签: php

解决方案


推荐阅读