Answer the question
In order to leave comments, you need to log in
Why is the server not responding to a request from the VK API?
Good afternoon fellow programmers.
I'm trying to create the simplest Vkontakte bot in PHP, according to the instructions, but something goes wrong.
The bottom line is that my server responds to the check and responds with the desired string (confirmation event), but it does not respond to other events. (In the settings of the Vkontakte community it is clearly written that the request was sent)
The code is as follows:
<?php
$confirmToken = '450f8570';
$token = 'мой токен';
$group_id = 190089312;
$secretKey = 'мое секретное слово';
$data = json_decode(file_get_contents('php://input'));
switch ($data->type) {
case 'confirmation':
echo $confirmToken;
break;
case 'message_new':
$userId = $data->object->from_id;
$userInfo = json_decode(file_get_contents("https://api.vk.com/method/users.get?user_ids={$userId}&v=5.103"));
$user_name = $userInfo->response[0]->first_name;
//С помощью messages.send и токена сообщества отправляем ответное сообщение
$request_params = array(
'message' => "{$user_name}, ваше сообщение зарегистрировано!<br>".
"Мы постараемся ответить в ближайшее время.",
'user_id' => $userId,
'access_token' => $token,
'v' => '5.103'
);
$get_params = http_build_query($request_params);
$result = file_get_contents('https://api.vk.com/method/messages.send?' . $get_params);
setcookie('API', 'true');
var_dump($result);
//Возвращаем "ok" серверу Callback API
echo('ok');
break;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question