Search code examples
phpbotsvk

How to confirm URL of server with VK bot?


I'm trying to write bot for vk.com website. I wrote the basic server confirmation code, but it refused to work (means that vk.com sends me a POST request with JSON {type: 'confirmation'} after which I need to respond with my CONFIRM_KEY). The problem is that it is an error while confirmation: "HTTP response code said error".

Here is my code:

<?php
    define('SECRET_KEY', 'blahblahblah');
    define('CONFIRM_KEY', 'ffffff');

    if (!isset($_REQUEST))
    {
        return;
    }

    $event = json_decode(file_get_contents('php://input'));

    if (strcmp($event['secret'], SECRET_KEY) !== 0 && strcmp($event['type'], 'confirmation') !== 0)
    {
        return;
    }

    switch ($event['type'])
    {
        case 'confirmation':

            echo CONFIRM_KEY;
            break;
    }
?>

Solution

  • The problem I bumped into was not in the code, but in the SSL sertificate of my web server. After I added SSL created by CloudFlare everithyng start works.