Пытаюсь сделать автоответчик (бот) на php.
Куда приходит оповещение о новом сообщении:
<?php
include_once "config.php";
include_once "message.php";
if (!isset($_REQUEST))
{
return;
}
$data = json_decode(file_get_contents('php://input'));
if($data->secret != $secretCB)
{
echo("Wrong secret key:" . $data->secret);
return;
}
switch ($data->type)
{
case 'confirmation':
echo $answerCB;
break;
case 'message_new':
echo(msgcallback($data));
}
message.php
<?php
function test()
{
return("ok");
}
function msgcallback($data)
{
$url = 'https://api.vk.com/method/messages.send';
$params = array(
'user_id' => $data->object->message->from_id,
'message' => $data->object->message->$message,
'access_token' => $token,
'random_id' => rand(99999, 9999999),
'v' => $api,
);
$result = file_get_contents($url, false, stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($params)
)
)));
return("ok");
}
?>
test() и msgcallback() не срабатывают, структура в "обработчике" правильная вроде т.к срабатывает
case 'confirmation':
echo $answerCB;
break;