<?php
$confirmation_token = 'cfbb7697';
$data = json_decode(file_get_contents('php://input'));
$user_id = $data->object->message->from_id;
$user_info = json_decode(file_get_contents("https://api.vk.com/method/users.get?user_ids={$user_id}&access_token={$token}&v=5.103"));
$user_name = $user_info->response[0]->first_name;
switch ($data->type) {
case 'confirmation':
echo $confirmation_token;
break;
case 'message_new':
$message_text = $data -> object -> text;
$user_id = $data->object->message->from_id;
$user_info = json_decode(file_get_contents("https://api.vk.com/method/users.get?user_ids={$user_id}&access_token={$token}&v=5.103"));
$user_name = $user_info->response[0]->first_name;
$chat_id = $data -> object -> peer_id;
function vk_msg_send($peer_id,$text){
$request_params = array(
'message' => $text,
'peer_id' => $peer_id,
'access_token' => "***",
'v' => '5.87'
);
$get_params = http_build_query($request_params);
file_get_contents('https://api.vk.com/method/messages.send?'. $get_params);
}
if (strpos(mb_strtolower(" ".$message_text), "привет") || mb_strtolower($message_text == "ку") || strpos(mb_strtolower(" ".$message_text), "хай") || strpos(mb_strtolower(" ".$message_text), "салют")){
vk_msg_send($chat_id, "Привет ".$user_name);
}
echo 'ok';
break;
}
?>