【问题标题】:HubSpot Webhook to PHP on aws ec2 ubuntu serverHubSpot Webhook 到 aws ec2 ubuntu 服务器上的 PHP
【发布时间】:2017-05-12 18:34:37
【问题描述】:

我正在使用 aws ec2 服务器 (ubuntu)。它设置为对所有流量开放。我正在尝试从 HubSpot 获取我的 Webhook 以连接到我的 php 页面以收集数据。我已经用推荐的 RequestBin 站点测试了这个 webhook,所有数据都很好。所以这导致认为它是我的代码,或者可能是在用于通过终端连接到它的服务器上使用 SSL。

我的 php 代码是...

<?php

# taking data from HubSpot's webhook 

//$hookData = json_decode(file_get_contents("php://input"), ture);
//$_POST = json_decode(file_get_contents("http://requestb.in/150jn861")); // does not get anything
//$_POST = file_get_contents('http://requestb.in/150jn861'); // writes to file the string "ok" 
$_POST = json_decode(file_get_contents("php://input"), ture);
$file = fopen("datadump1.txt", "w");
fwrite($file, $_POST);
fclose($file);
var_dump($_POST); // test input
echo "\nTest completed\n"; 
?>

我在这里找到了另外 2 个关于 webhooks 和 hubspot 的帖子,但修复没有奏效。如您所见,我一直在测试多种东西,但没有任何工作。由于这是 aws ec2,我无法使用 var_dump 或 echo 来真正测试我想要的效果。我以前从未使用过这种类型的环境。提前感谢您提供的任何帮助。

【问题讨论】:

    标签: php amazon-ec2 webhooks hubspot


    【解决方案1】:

    这对我来说是一个很大的问题。我没有考虑 ubuntu 中的权限。在使用本地文件和 cRUL 对我的 testPHP 文件进行测试后,我把它搞定了。使用“sudo chmod -R 777 /var/www/html/testPHP.php”更改权限,然后使用本地 POST 我创建了一个文件并在其中包含数据。这是我的代码给任何想要它的人;如果在 UBUNTU 中,请不要忘记许可。哈哈哈

    <?php
    
    # taking data from HubSpot's webhook 
    
    $hookData = file_get_contents("php://input");
    
    $file = fopen('datadump.json','w') or die("Unable to open file!");
    fwrite($file, $hookData);
    fclose($file);
    
    //var_dump($hookData); // test input
    echo "\nTest completed\n" . $hookData; 
    ?>
    

    在我的 POST 文件中...

    ?php
    
    $myObj = null;
    $myObj->name = "Name";
    $myObj->age = 32;
    $myObj->city = "New York";
    
    $myJSON = json_encode($myObj);
    
    
    //API Url
    $url = 'REMOVED; put your URL here';
    
    //Initiate cURL.
    $ch = curl_init($url);
    
    //Tell cURL that we want to send a POST request.
    curl_setopt($ch, CURLOPT_POST, 1);
    
    //Attach our encoded JSON string to the POST fields.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $myJSON);
    
    //Set the content type to application/json
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
    
    //Execute the request
    $result = curl_exec($ch);
    ?>
    

    【讨论】:

      猜你喜欢
      • 2014-11-04
      • 2012-12-09
      • 1970-01-01
      • 2012-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-24
      • 2023-03-17
      相关资源
      最近更新 更多