如何从URL webhook捕获请求?

时间:2019-07-26 04:52:07

标签: php laravel

大家好,我遇到了Webhook的问题,我订阅了URL,该URL会在发生某些情况时将数据发送到我的URL,{"webhook": {"action": "call.start", "account_id": "1", "account_name": "test", "user_id": "2", "user_login": "test@mail.ru"}, "event": <-这来自于测试Webhook捕获器,例如“ requestbin”,问题是我已经订阅了url,却无法像测试捕捉器中那样捕获数据。

我有这个OK,这意味着他们已经向我发送或将向我的url(http://webhook.site/d987438a-6d49-4620-b092-c0f0198a09a4')发送数据,而我只需要做的一件事就是捕获我的数据项目。 oo,我不能)

代码:

public static function meow(Request $request)
{
    $client = new \GuzzleHttp\Client();
    $request = $client->post('https://abylkhairn.moizvonki.ru/api/v1', [
        'headers' => [
            'content-type' => 'application/json',
            'Accept' => 'application/json',
            'auth' => [
                'abylkhairnurgozhaev@gmail.com',
                'im5tjeq92gkr01qgbij6o1mhlxxxbmrg'
            ]
        ],
        'body' => json_encode([
            'user_name' => 'abylkhair@mail.ru',
            'api_key' => 'im5tjeq92gkr01qgbij6o1mhlxxxbmrg',
            'action' => 'webhook.subscribe',
            'hooks' => [
                'call.start' => 'http://webhook.site/d987438a-6d49-4620-b092-c0f0198a09a4'
            ],
//                'from_date' => 1561973787,
//                'supervised' => 0
        ]),
        'verify' => false,

    ]);
    $response = $request->getBody()->getContents();
    $enc = mb_detect_encoding($response);
    if ($enc == 'UTF-8') {
        $response = preg_replace('/[^(\x20-\x7F)]*/', '', $response);
    }
    echo "<pre>";
    $undecode = (json_decode($response, true));
    $undecodee = (json_encode($response, true));

    print_r($undecodee);
    dd($undecodee);
    dd($undecode);
    $url = "http://webhook.site/d987438a-6d49-4620-b092-c0f0198a09a4";
    $query_str = parse_url($url, PHP_URL_QUERY);
    parse_str($query_str, $query_params);
    print_r($query_params);
    dd($query_params);
}

0 个答案:

没有答案