mirror of
https://github.com/lkeme/BiliHelper-personal.git
synced 2025-12-19 09:30:10 +08:00
[fix] XliveHeartBeat
This commit is contained in:
parent
358553525e
commit
7ab42e6fc0
@ -40,69 +40,69 @@ trait XliveHeartBeat
|
||||
protected static function resetVar($force = false)
|
||||
{
|
||||
if ($force){
|
||||
self::$_room_info = [];
|
||||
self::$_current_room_id = 0;
|
||||
static::$_room_info = [];
|
||||
static::$_current_room_id = 0;
|
||||
|
||||
self::$_retry = 3;
|
||||
self::$_count_num = 0;
|
||||
self::$_count_time = 0;
|
||||
static::$_retry = 3;
|
||||
static::$_count_num = 0;
|
||||
static::$_count_time = 0;
|
||||
}
|
||||
$data = [
|
||||
'id' => self::$_data['id'],
|
||||
'id' => static::$_data['id'],
|
||||
];
|
||||
$data["id"][2] = 0;
|
||||
self::$_data = $data;
|
||||
static::$_data = $data;
|
||||
}
|
||||
|
||||
|
||||
protected static function xliveHeartBeatTask(int $room_id, int $max_time, int $max_num)
|
||||
{
|
||||
// 加载依赖
|
||||
if (!self::depend()) {
|
||||
return self::$_default;
|
||||
if (!static::depend()) {
|
||||
return static::$_default;
|
||||
}
|
||||
// 对比当前运行
|
||||
if (self::$_current_room_id != $room_id) {
|
||||
self::resetVar(true);
|
||||
self::$_current_room_id = $room_id;
|
||||
if (static::$_current_room_id != $room_id) {
|
||||
static::resetVar(true);
|
||||
static::$_current_room_id = $room_id;
|
||||
}
|
||||
// 加载房间信息
|
||||
if (empty(self::$_room_info)) {
|
||||
if (empty(static::$_room_info)) {
|
||||
$r_data = Live::webGetRoomInfo($room_id);
|
||||
if ($r_data['code'] != 0) {
|
||||
Log::warning('直播间信息获取失败');
|
||||
return self::$_default;
|
||||
return static::$_default;
|
||||
}
|
||||
$rdata = $r_data['data'];
|
||||
$parent_area_id = $rdata['room_info']['parent_area_id'];
|
||||
$area_id = $rdata['room_info']['area_id'];
|
||||
# 短位转长位
|
||||
$room_id = $rdata['room_info']['room_id'];
|
||||
self::$_data['id'] = [$parent_area_id, $area_id, 0, $room_id];
|
||||
static::$_data['id'] = [$parent_area_id, $area_id, 0, $room_id];
|
||||
}
|
||||
// 执行心跳
|
||||
$r_data = self::heartBeatIterator();
|
||||
$index = self::$_data['id'][2];
|
||||
$r_data = static::heartBeatIterator();
|
||||
$index = static::$_data['id'][2];
|
||||
if ($r_data['code'] != 0) {
|
||||
if (self::$_retry) {
|
||||
if (static::$_retry) {
|
||||
Log::warning("心跳失败-{$index} {$r_data['message']}");
|
||||
self::resetVar();
|
||||
self::$_retry -= 1;
|
||||
return self::$_default;
|
||||
static::resetVar();
|
||||
static::$_retry -= 1;
|
||||
return static::$_default;
|
||||
}
|
||||
}
|
||||
self::$_count_num += 1;
|
||||
self::$_count_time += $r_data['heartbeat_interval'];
|
||||
static::$_count_num += 1;
|
||||
static::$_count_time += $r_data['heartbeat_interval'];
|
||||
|
||||
// 最大次数限制
|
||||
if ($max_num <= self::$_count_num) {
|
||||
if ($max_num <= static::$_count_num) {
|
||||
// 成功在id为{room_id}的直播间发送完{ii}次心跳,退出直播心跳(达到最大心跳次数)
|
||||
}
|
||||
// 最大时间限制
|
||||
if ($max_time <= self::$_count_time) {
|
||||
if ($max_time <= static::$_count_time) {
|
||||
//成功在id为{room_id}的直播间发送第{ii}次心跳
|
||||
}
|
||||
$minute = round(self::$_count_time / 60);
|
||||
$minute = round(static::$_count_time / 60);
|
||||
Log::info("已在直播间 {$room_id} 连续观看了 {$minute} 分钟");
|
||||
return $r_data['heartbeat_interval'];
|
||||
|
||||
@ -118,8 +118,8 @@ trait XliveHeartBeat
|
||||
return false;
|
||||
}
|
||||
// 加载加密服务器
|
||||
if (is_null(self::$_enc_server)) {
|
||||
self::$_enc_server = getenv('ENC_SERVER');
|
||||
if (is_null(static::$_enc_server)) {
|
||||
static::$_enc_server = getenv('ENC_SERVER');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -129,21 +129,21 @@ trait XliveHeartBeat
|
||||
{
|
||||
$rdata = [];
|
||||
# 第1次执行 eHeartBeat
|
||||
if (self::$_data['id'][2] == 0) {
|
||||
$r_data = self::eHeartBeat(self::$_data['id']);
|
||||
if (static::$_data['id'][2] == 0) {
|
||||
$r_data = static::eHeartBeat(static::$_data['id']);
|
||||
} else {
|
||||
# 第1次之后执行 xHeartBeat
|
||||
self::$_data['ts'] = time() * 1000;
|
||||
self::$_data['s'] = self::encParamS(self::$_data, self::$_secret_rule);
|
||||
$r_data = self::xHeartBeat(self::$_data['id']);
|
||||
static::$_data['ts'] = time() * 1000;
|
||||
static::$_data['s'] = static::encParamS(static::$_data, static::$_secret_rule);
|
||||
$r_data = static::xHeartBeat(static::$_data['id']);
|
||||
}
|
||||
if ($r_data['code'] == 0) {
|
||||
$rdata = $r_data['data'];
|
||||
self::$_data['ets'] = $rdata['timestamp'];
|
||||
self::$_data['benchmark'] = $rdata['secret_key'];
|
||||
self::$_data['time'] = $rdata['heartbeat_interval'];
|
||||
self::$_secret_rule = $rdata['secret_rule'];
|
||||
self::$_data['id'][2] += 1;
|
||||
static::$_data['ets'] = $rdata['timestamp'];
|
||||
static::$_data['benchmark'] = $rdata['secret_key'];
|
||||
static::$_data['time'] = $rdata['heartbeat_interval'];
|
||||
static::$_secret_rule = $rdata['secret_rule'];
|
||||
static::$_data['id'][2] += 1;
|
||||
}
|
||||
return [
|
||||
'code' => $r_data['code'],
|
||||
@ -182,7 +182,7 @@ trait XliveHeartBeat
|
||||
// {'code':0,'message':'0','ttl':1,'data':{'timestamp':1595342828,'heartbeat_interval':300,'secret_key':'seacasdgyijfhofiuxoannn','secret_rule':[2,5,1,4],'patch_status':2}}
|
||||
|
||||
unset($payload['id']);
|
||||
self::$_data = array_merge_recursive(self::$_data, $payload);
|
||||
static::$_data = array_merge_recursive(static::$_data, $payload);
|
||||
|
||||
return json_decode($raw, true);
|
||||
}
|
||||
@ -197,20 +197,20 @@ trait XliveHeartBeat
|
||||
$url = 'https://live-trace.bilibili.com/xlive/data-interface/v1/x25Kn/X';
|
||||
$user_info = User::parseCookies();
|
||||
$payload = [
|
||||
's' => self::$_data['s'],
|
||||
's' => static::$_data['s'],
|
||||
'id' => json_encode([$id[0], $id[1], $id[2], $id[3]], true),
|
||||
'device' => self::$_data['device'],
|
||||
'ets' => self::$_data['ets'],
|
||||
'benchmark' => self::$_data['benchmark'],
|
||||
'time' => self::$_data['time'],
|
||||
'ts' => self::$_data['ts'],
|
||||
'ua' => self::$_data['ua'],
|
||||
'device' => static::$_data['device'],
|
||||
'ets' => static::$_data['ets'],
|
||||
'benchmark' => static::$_data['benchmark'],
|
||||
'time' => static::$_data['time'],
|
||||
'ts' => static::$_data['ts'],
|
||||
'ua' => static::$_data['ua'],
|
||||
'csrf_token' => $user_info['token'],
|
||||
'csrf' => $user_info['token'],
|
||||
'visit_id' => ''
|
||||
];
|
||||
// print_r($payload);
|
||||
$raw = Curl::post('pc', $url, $payload, self::$hb_headers);
|
||||
$raw = Curl::post('pc', $url, $payload, static::$hb_headers);
|
||||
# {'code':0,'message':'0','ttl':1,'data':{'heartbeat_interval':300,'timestamp':1595346846,'secret_rule':[2,5,1,4],'secret_key':'seacasdgyijfhofiuxoannn'}}
|
||||
return json_decode($raw, true);
|
||||
}
|
||||
@ -228,7 +228,7 @@ trait XliveHeartBeat
|
||||
];
|
||||
// 加密部分
|
||||
$payload = ['t' => $t, 'r' => $r];
|
||||
$data = Curl::put('other', self::$_enc_server, $payload, $headers);
|
||||
$data = Curl::put('other', static::$_enc_server, $payload, $headers);
|
||||
$de_raw = json_decode($data, true);
|
||||
if ($de_raw['code'] == 0) {
|
||||
// Log::info("S加密成功 {$de_raw['s']}");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user