我有两个页面,一个是workflow.php,其中web-hook发送一些数据,接收数据后我想将这些数据发送到其他页面,因为某些原因是aq.php
workflow.php
<?
$cmd = 'echo "hii3" > debug2.log';
echo "<pre>".shell_exec($cmd)."</pre>";
$cmd1 = 'echo '.$_POST['action'].' >> debug2.log';
echo "<pre>".shell_exec($cmd1)."</pre>";
$cmd2 = 'echo ' .$_POST['id'].' >> debug2.log';
echo "<pre>".shell_exec($cmd2)."</pre>";
$id=$_POST['id'];
?>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js">
</script>
<script type="text/javascript">
$(
function() {
var id= '<?php echo $id ;?>';
$.ajax({
url: "http://35.160.133.54/bitrix/aq.php",
dataType: "json",
type: "POST",
data: {id : id},
success: function(data){
}
});
});
</script>
<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>
aq.php
<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetTitle("AQ");
if($_POST)
{
$cmd = "echo ".$_POST['id']." > debug5.log";
echo "<pre>".shell_exec($cmd)."</pre>";
}
?><?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>
当我手动运行workflow.php然后运行aq.php文件。但是当web-hook将一些数据发送到workflow.php时它不运行aq.php
答案 0 :(得分:1)
web-hook不是浏览器......所以你在浏览器中所做的事情都会有效,因为你的浏览器正在执行JavaScript(Ajax调用)。一个只做(GET / POST)请求的web-hook,你回复的将不会被执行! 如果你想解决这个问题,你必须找到另一种方法。
例如,如果您拥有执行curl服务器的权限,则可以模拟Ajax请求。
'curl -i -H "Accept: application/json" -d "id":' . $id .' http://35.160.133.54/bitrix/aq.php'
或者您使用PHP版本:
<?php
$data_string = json_encode(array("id" => $id));
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, "http://35.160.133.54/bitrix/aq.php");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
curl_exec ($curl);
curl_close ($curl);