[fix] XliveHeartBeat

This commit is contained in:
Lkeme 2021-04-26 21:23:45 +08:00
parent a3196bb053
commit 26329986ac
5 changed files with 29 additions and 17 deletions

View File

@ -65,7 +65,7 @@ class AnchorRaffle extends BaseRaffle
self::$group_id = $tag_id ? $tag_id : User::createRelationTag(self::$group_name);
}
// 获取需要关注的
$data = Live::getRoomInfo($room_id);
$data = Live::getRoomInfoV1($room_id);
if ($data['code'] == 0 && isset($data['data'])) {
$need_follow_uid = $data['data']['uid'];
} else {

View File

@ -33,11 +33,11 @@ class Barrage
];
if (self::privateSendMsg($info)) {
self::setLock(mt_rand(40, 60) * 60);
self::setLock(mt_rand(40, 80) * 60);
return;
}
self::setLock(30);
self::setLock(10 * 60);
}
/**
@ -64,7 +64,7 @@ class Barrage
* @use 获取一言api消息
* @return string
*/
private static function getMsgInfo():string
private static function getMsgInfo(): string
{
/**
* 整理一部分API收集于网络侵权麻烦联系我删除.
@ -112,7 +112,7 @@ class Barrage
{
$user_info = User::parseCookies();
$url = 'https://api.live.bilibili.com/msg/send';
$data = Live::getRoomInfo($info['roomid']);
$data = Live::getRoomInfoV1($info['roomid']);
$payload = [
'color' => '16777215',
'fontsize' => 25,
@ -140,7 +140,7 @@ class Barrage
Log::info('弹幕发送成功');
return true;
} else {
Log::warning("弹幕发送失败, CODE -> {$response['code']} MSG -> {$response} ");
Log::warning("弹幕发送失败, CODE -> {$response['code']} MSG -> {$response['message']} ");
return false;
}
}

View File

@ -226,7 +226,7 @@ class GiftSend
{
Log::info('正在生成直播间信息...');
$room_id = empty(self::$tid) ? getenv('ROOM_ID') : self::$tid;
$data = Live::getRoomInfo($room_id);
$data = Live::getRoomInfoV1($room_id);
if (isset($data['code']) && $data['code']) {
Log::warning('获取主播房间号失败!', ['msg' => $data['message']]);
Log::warning('清空礼物功能禁用!');

View File

@ -82,7 +82,7 @@ class Live
* @use 获取随机直播房间号
* @return int
*/
public static function getUserRecommend()
public static function getUserRecommend(): int
{
$url = 'https://api.live.bilibili.com/room/v1/Area/getListByAreaID';
$payload = [
@ -105,9 +105,9 @@ class Live
* @param $room_id
* @return bool
*/
public static function getRealRoomID($room_id)
public static function getRealRoomID($room_id): bool
{
$data = self::getRoomInfo($room_id);
$data = self::getRoomInfoV1($room_id);
if (!isset($data['code']) || !isset($data['data'])) {
return false;
}
@ -132,7 +132,7 @@ class Live
* @param $room_id
* @return array
*/
public static function getRoomInfo($room_id): array
public static function getRoomInfoV1($room_id): array
{
$url = 'https://api.live.bilibili.com/room/v1/Room/room_init';
$payload = [
@ -142,6 +142,21 @@ class Live
return json_decode($raw, true);
}
/**
* @use 获取直播间信息
* @param $room_id
* @return array
*/
public static function getRoomInfoV2($room_id): array
{
$url = ' https://api.live.bilibili.com/room/v1/Room/get_info_by_id';
$payload = [
'ids[]' => $room_id
];
$raw = Curl::get('other', $url, $payload);
return json_decode($raw, true);
}
/**
* @use 获取弹幕配置
* @param $room_id
@ -230,7 +245,7 @@ class Live
* @use 获取毫秒
* @return float
*/
public static function getMillisecond()
public static function getMillisecond(): float
{
list($t1, $t2) = explode(' ', microtime());
return (float)sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);
@ -383,7 +398,7 @@ class Live
* @param int $page
* @return array
*/
public static function getAreaRoomList(int $parent_area_id, int $area_id, int $page=1): array
public static function getAreaRoomList(int $parent_area_id, int $area_id, int $page = 1): array
{
$url = 'https://api.live.bilibili.com/xlive/web-interface/v1/second/getList';
$payload = [

View File

@ -68,10 +68,7 @@ trait XliveHeartBeat
return static::$_default;
}
static::$_room_info = $r_data;
}
// 加载房间信息
if (static::$_room_info && static::$_data["id"][2] == 0){
$rdata = static::$_room_info['data'];
$rdata = $r_data['data'];
$parent_area_id = $rdata['room_info']['parent_area_id'];
$area_id = $rdata['room_info']['area_id'];
# 短位转长位