How to write php to get json message from webhook?

I add my url xxx / getjson.php to the webhook and after registering the person, he will send the json data to my url. I use http://requestb.in/ to validate the data, and the result is as follows:

payload{ "signup": { "address": { "address1": "XX",
                                  "country": "United States"},                     
                     "id":22}}
token

PHP script I write:

$obj=json_decode($_POST);            //cannot get the json data

$userid=$obj->signup->id;

Also I don’t know how to use the "payload"

I find a similar code example, and I test it well using my web interceptors. http://support.unbounce.com/entries/307685-how-does-the-form-webhook-work However, they use "data.json" rather than a "payload" as parameters.

$form_data = json_decode($unescaped_post_data['data_json']);  
$userid= =$form_data->signup->id;

I used my stripslashes_deep function and replaced "data_json" with "payload", but it still doesn't work.

. !

+5
3

$_ POST , .

$obj=json_decode($_POST['payload']); // put the second parameter as true if you want it to be a associative array

$userid=$obj->signup->id;
+3

- ! , ... API - . !

$data = $_REQUEST["payload"];           
$unescaped_data = stripslashes($data);
$obj = json_decode($unescaped_data);
$userid = $obj->signup->id;
+2

, $obj=json_decode($_POST); JSON.

, , , , JSON " ".

payload{ 
    "signup": { 
             "address":{ 
                     "address1": "XX",
                     "country": "United States"
              },                     
              "id":22
     }
}

  . { "signup": { "address": { "address1": "XX","country": "United States"},"id":22}} - JSON. JSON .

$_POST['payload'], , , .

, , . HTML, Javascript, / POST. ( - Curl?)

0
source

All Articles