-
Notifications
You must be signed in to change notification settings - Fork 0
/
Weibo.php
68 lines (65 loc) · 1.93 KB
/
Weibo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Timer;
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
use Workerman\Protocols\Http\Request;
use Workerman\Protocols\Http\Response;
use WpOrg\Requests\Requests;
function Cron_Run()
{
global $global;
$crazy = new CrazyWeibo('1393786362');
$global->wb_last_result = $crazy->return;
sleep(1);
$crazy = new CrazyWeibo('7426493874');
$global->wb_last_result .= $crazy->return;
sleep(1);
$crazy = new CrazyWeibo('1239246050');
$global->wb_last_result .= $crazy->return;
}
$dianfei_worker = new Worker('http://100.77.158.125:2397');
$dianfei_worker->name = 'Weibo';
$dianfei_worker->onWorkerStart = function (Worker $worker) {
Cron_Run();
Timer::add(
300,
function () {
Cron_Run();
}
);
echo "Cron started.\n";
};
$dianfei_worker->onMessage = function (TcpConnection $connection, Request $request) {
global $global;
switch ($request->path()) {
case '/metrics':
$connection->close($global->wb_last_result);
break;
default:
$connection->close(new Response(404, [], '404 not found'));
}
};
class CrazyWeibo
{
private $url = 'https://m.weibo.cn/api/container/getIndex?type=uid&value=%s';
public $result = array();
public $return = '';
public function __construct($uid)
{
global $global;
$this->url = sprintf($this->url, $uid);
$response = Requests::get($this->url);
if ($response->success) {
$temp = json_decode($response->body, true);
//var_dump($temp);
$this->return .= sprintf(
'CrazyWeiboFans{name="%s"} %s' . "\n",
$temp['data']['userInfo']['screen_name'],
str_replace('万', '', $temp['data']['userInfo']['followers_count'])
);
var_dump($this->return);
}
}
}
Worker::runAll();