【问题标题】:How to implement PubSubHubBub Protocol in php如何在 php 中实现 PubSubHubBub 协议
【发布时间】:2015-07-15 10:40:21
【问题描述】:

我在 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() 函数时,它会成功调用我的回调函数。 从那里我不知道如何进行验证。 请有人从这里帮忙

【问题讨论】:

    标签: php curl kohana publish-subscribe websub


    【解决方案1】:

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

    查看this article了解更多详情。

    【讨论】:

    • 一个函数可以处理这就是为什么我把它作为回调。我已经研究过那篇文章。没有运气
    • “回调”是一个被PubSubHubbub Hub“调用”的URL,所以你必须在不同的URL下提供你的“我的回调函数”的代码。也许这有帮助:josephsmarr.com/2010/03/01/…
    • 谢谢你们。我不知道发生了什么,但集线器工作正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    • 2013-07-01
    • 1970-01-01
    • 2011-06-19
    • 1970-01-01
    • 2011-08-18
    相关资源
    最近更新 更多