1

我在 kohana 项目中实施 PubSubHubBub。这是我的订阅代码:

   public function action_curl_home()
   {
    $secret = hash('sha1', uniqid(rand(), true));
      $post_fields = array("hub.callback" => "my callback function",
        "hub.mode" => "subscribe",
        "hub.topic" => "http://feeds.feedburner.com/NdtvNews-TopStories",
        "hub.verify" => "async",
        "hub.lease_seconds" => "42800",
        "hub.secret" => $secret
    );

    $curl = curl_init("http://pubsubhubbub.appspot.com/");
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post_fields);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_VERBOSE, 1);
    curl_exec($curl);
    $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    print_r($code);
    if (in_array($code, array(202, 204))) {
        print_r("Positive response - request ($code). - secret: $secret");
    }
    else {
        print_r("Error issuing - request - ($code).");
    }
    curl_close($curl);
    exit;
}

回调函数在这里:

    if (isset($_GET['hub_challenge'])) {
        print $_GET['hub_challenge'];
        file_put_contents($_SERVER['DOCUMENT_ROOT'] . "application/classes/controller/curl.txt", implode(" , ", $_GET));
        exit;
    }
    else {
        $xml=file_get_contents("php://input");
        file_put_contents($_SERVER['DOCUMENT_ROOT'] . "application/classes/controller/curl.txt", date('d-m-y h:i:s a') . $xml, FILE_APPEND);
        exit;
    }

当我调用 action_url_home() 函数时,它成功调用了我的回调函数。从那里我不知道如何进行验证。请从这里有人帮助

4

1 回答 1

3

我认为在hub.callback参数方面存在误解。它不应该是一个函数,而应该是一个webhook:当您发出订阅请求时由集线器(不是您)调用的 URL。

查看这篇文章了解更多详情。

于 2015-07-15T11:25:08.840 回答