简体   繁体   中英

Read POST webhook PHP

I'm trying to read the contents of a webhook notification in php. The content of the request is in the link below:

Link POST

HEADERS: Pragma: no-cache X-Request-Id: fec7f2ea-ae08-4fc1-9f81-b7ed9b976100 X-Newrelic-Transaction: PxQDWVNWCgBWBlJWVldRV1dUFB8EBw8RVU4aVgANAQAAA1tSBQBVBFUFUkNKQQtVVlNTUVZQFTs= Accept: text/html, image/gif, image/jpeg, *; q=.2, / ; q=.2 Connect-Time: 2 Connection: close Content-Length: 931 Cache-Control: no-cache User-Agent: Java/1.7.0_72 Accept-Encoding: gzip Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Via: 1.1 vegur X-Newrelic-Id: UgcDUFdVGwQAXFdRBAU= Host: requestb.in Total-Route-Time: 0

FORM/POST PARAMETERS: data: { "event": "PAYMENT_UPDATED", "payment": { "object": "payment", "id": "pay_158657847699", "customer": "cus_artujit2nfYe", "value": 160.0, "netValue": 155.75, "originalValue": null, "nossoNumero": "34271724", "description": "", "billingType": "BOLETO", "status": "PENDING", "dueDate": "21/12/2016", "paymentDate": null, "invoiceUrl": "", "boletoUrl": "", "invoiceNumber": "00507815", "externalReference": null, "deleted": false } }

I tried unsuccessfully through the line code: $datasrc = $_POST;

I also tried to read with $ _REQUEST unsuccessfully.

How to read the content in php?

No clue what webhook is or does. But if it is sent as as POST request to a page in PHP, the data posted will be present in the $_POST array.

To see what's in it: var_dump($_POST); will show you the array and it's structure.

To get the value of a specific key: $variable = $_POST['key']; will do the trick.

If I interpret the stuff you posted correctly the json encoded content should be in $_POST['data']; .

To decode the json encoded string, PHP has helpful functions such as json_decode .

$data=json_decode($_POST['data'], true); should give you a PHP array with the data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM