retet - PHP Online
Form of PHP Sandbox
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of retet.php
- <?php
- if (!isset($_REQUEST)) {
- return;
- }
- //Строка для подтверждения адреса сервера из настроек Callback API
- $confirmation_token = '2749a54a';
- //Ключ доступа сообщества
- $token = 'c0223f775444cf3d58a8a1442ec76a9571c8f58e3e24616d9440f73dc43022bbead9b2e576cb41d09c0a1';
- //Получаем и декодируем уведомление
- $data = json_decode(file_get_contents('php://input'));
- //Проверяем, что находится в поле "type"
- switch ($data->type) {
- //Если это уведомление для подтверждения адреса...
- case 'confirmation':
- //...отправляем строку для подтверждения
- echo $confirmation_token;
- break;
- //Если это уведомление о новом сообщении...
- case 'message_new':
- //...получаем id его автора
- $user_id = $data->object->user_id;
- //затем с помощью users.get получаем данные об авторе
- $user_info = json_decode(file_get_contents("https://api.vk.com/method/users.get?user_ids={$user_id}&access_token={$token}&v=5.0"));
- //и извлекаем из ответа его имя
- $user_name = $user_info->response[0]->first_name;
- //С помощью messages.send отправляем ответное сообщение
- $request_params = array(
- 'message' => "Hello, {$user_name}!",
- 'user_id' => $user_id,
- 'access_token' => $token,
- 'v' => '5.0'
- );
- $get_params = http_build_query($request_params);
- file_get_contents('https://api.vk.com/method/messages.send?'. $get_params);
- //Возвращаем "ok" серверу Callback API
- echo('ok');
- break;
- }
- ?>
File Description
- retet
- PHP Code
- 08 Aug-2018
- 1.66 Kb
You can Share it:
Latest PHP Pastes