接收webhook数据并在PHP中使用

时间:2019-07-15 09:57:44

标签: javascript php json api webhooks

我需要一个简单的PHP的帮助,接收webhook数据并运行php。 我的php正常工作,但是没有获取webhook数据,也许我使用了错误的代码来捕获它。 我试图用(。$ _ POST ['loc']。)或(。$ var。)或(。$ _ GET ['loc']。)

捕获[loc]数据。

网络发布数据

Array
(
    [submission_id] => 4391491919028897
    [formID] => 4673665580
    [ip] => 203.63.121.491
    [id] => 26926177418929
    [loc] => -31.86450, 154.08260
    [typea] => BROWSER: Chrome
OS: MacOS
DEVICE: Desktop
LANGUAGE: en-US
TIMEZONE: GMT +10
)


PHP Code:
$_POST['submission_id'];
$_POST['formID'];
$_POST['ip'];
$_POST['id'];
$_POST['loc'];
$_POST['typea'];

PHP

  $products=json_decode($_POST['data'],true);
  $val = $_POST['loc'];
  $textString='';
     $jsonprod = $_POST['data'];
  $url = 'https://api.manychat.com/fb/sending/sendContent';

  $data_string = '{"subscriber_id":"617647418929",
  "data":{
     "version":"v2",
     "content": {
       "messages": [
      {
        "type":"text",
        "text":" test '.$_POST['loc'].'",
        "buttons": [
          {
            "type": "url",
            "caption": "Edit",
            "url": "https://test/cart.php?",
            "webview_size": "medium"
          }
        ]
      }
  ],
  "actions": [
    {
      "action": "set_field_value",
      "field_name": "address",
      "value": "test"
    }
    ]
     }
  }

1 个答案:

答案 0 :(得分:1)

这样做:

print_r(json_decode($json_webhookdata, TRUE));