【发布时间】: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