简体   繁体   English

在AWS EC2 Ubuntu服务器上将HubSpot Webhook转换为PHP

[英]HubSpot Webhook to PHP on aws ec2 ubuntu server

I am working with an aws ec2 server (ubuntu). 我正在使用AWS EC2服务器(ubuntu)。 It is set to open so for all traffic. 它设置为打开,以便所有流量。 I am trying to get my Webhook from HubSpot to connect to my php page for collecting data. 我正在尝试从HubSpot获取Webhook,以连接到我的php页面以收集数据。 I have tested this webhook with the recommended RequestBin site and all the data comes through just fine. 我已经使用推荐的RequestBin网站测试了该Webhook,所有数据都通过了。 So this leads to think its my code or maybe the use of the SSL on the server that is used to connect to it via terminal. 因此,这导致认为它是我的代码,或者可能是在用于通过终端连接到它的服务器上使用SSL的。

my php code is ... 我的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"; 
?>

I have found 2 other posts on here for webhooks and hubspot but the fix did not work. 我在这里还发现了2个关于webhooks和hubspot的其他帖子,但修复程序不起作用。 As you can see I have been testing multiple things but have not gotten anything to work. 如您所见,我已经测试了多个项目,但没有任何工作。 Since this is aws ec2 I cannot use the var_dump or echo to really test as good as I would like. 由于这是aws ec2,因此我无法使用var_dump或echo来真正测试所需的性能。 I have never used this type of environment before. 我以前从未使用过这种类型的环境。 Thank you in advance for any help you can give. 预先感谢您提供的任何帮助。

This was a big over sight on my part. 在我看来,这是一个很大的发现。 I was not accounting for the permissions in ubuntu. 我没有考虑ubuntu中的权限。 after testing with local files and cRUL to my testPHP file I wound this out. 在使用本地文件和对我的testPHP文件进行cRUL测试之后,我将其打包。 changed permissions with "sudo chmod -R 777 /var/www/html/testPHP.php" then with the local POST I was a file was created and data was in it. 使用“ sudo chmod -R 777 /var/www/html/testPHP.php”更改了权限,然后使用本地POST创建了一个文件,并在其中添加了数据。 here is my code for anyone that wants it; 这是我的代码给任何想要的人; and DON'T FORGET THE PERMISSIONS IF IN UBUNTU. 如果在UBUNTU,也不要忘记权限。 HAHAHA 哈哈哈

<?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; 
?>

in my POST file... 在我的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);
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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