p3k / websub
订阅和发布 WebSub 订阅源的库
0.0.1
2017-05-08 15:26 UTC
Requires
- indieweb/link-rel-parser: 0.1.*
- p3k/http: 0.1.*
- p3k/utils: 1.*
Requires (Dev)
- predis/predis: 1.*
This package is auto-updated.
Last update: 2024-09-07 20:54:13 UTC
README
用法
初始化客户端
$http = new p3k\HTTP('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) p3k-websub/0.1.0 example'); $client = new p3k\WebSub\Client($http);
发现主题 URL 的中心 URL 和自 URL
// Returns false unless both hub and self were found $endpoints = $client->discover($topic); // $endpoints['hub'] // $endpoints['self']
发送订阅请求
$secret = p3k\random_string(32); $id = p3k\random_string(32); $callback = 'http://localhost:8080/subscriber.php?id='.$id; $subscription = $client->subscribe($endpoints['hub'], $endpoints['self'], $callback, [ 'lease_seconds' => 300, 'secret' => $secret ]);
验证签名
$signature = $_SERVER['HTTP_X_HUB_SIGNATURE']; $document = file_get_contents('php://input'); $valid = p3k\WebSub\Client::verify_signature($document, $signature, $secret);
许可
版权所有 2017 by Aaron Parecki
在 MIT 许可下可用。