[update] api

This commit is contained in:
Lkeme 2019-10-30 21:01:22 +08:00
parent 2aac7e6af0
commit 17e105e5b0
10 changed files with 149 additions and 64 deletions

View File

@ -1,6 +1,19 @@
# Release Notes
# 本项目Log
## v0.0.1.191030 alpha (2019-10-30)
### Added
-
### Changed
- unify raffle api
- danmu
- captcha ocr api
### Fixed
-
## v0.0.1.190730 alpha (2019-07-30)
### Added

View File

@ -64,11 +64,10 @@ USE_STORM=true
STORM_DROPRATE=0
STORM_ATTEMPT=30,50
# 活跃弹幕|弹幕房间(为空则随机)|弹幕内容(为空随机,但是URL不能为空)
# 活跃弹幕|弹幕房间(为空则随机)|弹幕内容(为空随机)
USE_DANMU=true
DANMU_ROOMID=9522051
DANMU_CONTENT=
CONTENT_FETCH="https://v1.hitokoto.cn/?encode=text"
# 视频投币|投币稿件数(每日任务最大5)|自定义稿件ID,空则随机(AV_NUM=1生效)
USE_ADD_COIN=false

View File

@ -40,16 +40,23 @@ abstract class BaseRaffle
*/
protected static function startLottery(): bool
{
$max_num = mt_rand(5, 10);
while ($max_num) {
$max_num = mt_rand(10, 20);
if (count(static::$wait_list) == 0) {
return false;
}
static::$wait_list = static::arrKeySort(static::$wait_list, 'wait');
for ($i = 0; $i <= $max_num; $i++) {
$raffle = array_shift(static::$wait_list);
if (is_null($raffle)) {
break;
}
if ($raffle['wait'] > strtotime(date("Y-m-d H:i:s"))) {
array_push(static::$wait_list, $raffle);
continue;
}
Live::goToRoom($raffle['room_id']);
Statistics::addJoinList(static::ACTIVE_TITLE);
static::lottery($raffle);
$max_num--;
}
return true;
}
@ -70,6 +77,27 @@ abstract class BaseRaffle
*/
abstract protected static function lottery(array $data): bool;
/**
* @use 二维数组按key排序
* @param $arr
* @param $key
* @param string $type
* @return array
*/
protected static function arrKeySort($arr, $key, $type = 'asc')
{
switch ($type) {
case 'desc':
array_multisort(array_column($arr, $key), SORT_DESC, $arr);
return $arr;
case 'asc':
array_multisort(array_column($arr, $key), SORT_ASC, $arr);
return $arr;
default:
return $arr;
}
}
/**
* 重复检测

View File

@ -18,7 +18,7 @@ class Curl
'Accept-Language' => 'zh-cn',
'Connection' => 'keep-alive',
'Content-Type' => 'application/x-www-form-urlencoded',
'User-Agent' => 'bili-universal/8230 CFNetwork/975.0.3 Darwin/18.2.0',
'User-Agent' => 'bili-universal/8470 CFNetwork/978.0.7 Darwin/18.5.0',
// 'Referer' => 'https://live.bilibili.com/',
);
@ -159,7 +159,55 @@ class Curl
return self::post($url, null, $headers);
}
protected static function http2https($url)
/**
* @use 单次请求
* @param $method
* @param $url
* @param array $payload
* @param array $headers
* @param int $timeout
* @return false|string
*/
public static function singleRequest($method, $url, $payload = [], $headers = [], $timeout = 10)
{
$url = self::http2https($url);
Log::debug($url);
$options = array(
'http' => array(
'method' => strtoupper($method),
'header' => self::arr2str($headers),
'content' => http_build_query($payload),
'timeout' => $timeout,
),
);
$result = @file_get_contents($url, false, stream_context_create($options));
Log::debug($result);
return $result ? $result : null;
}
/**
* @use 关联数组转字符串
* @param array $array
* @param string $separator
* @return string
*/
private static function arr2str(array $array, string $separator = "\r\n"): string
{
$tmp = '';
foreach ($array as $key => $value) {
$tmp .= "{$key}:{$value}{$separator}";
}
return $tmp;
}
/**
* @use http(s)转换
* @param string $url
* @return string
*/
private static function http2https(string $url): string
{
switch (getenv('USE_HTTPS')) {
case 'false':

View File

@ -38,58 +38,52 @@ class Danmu
// 获取随机弹幕
private static function getMsgInfo()
{
/*
/**
* 整理一部分API收集于网络侵权麻烦联系我删除.
* 如果设置项不能用可以选择,只保证代码发布时正常.
* 格式全部为TEXT请自己测试好了再放进配置文件.
* -7. https://api.lwl12.com/hitokoto/v1?encode=realjso
* -6. https://api.ly522.com/yan.php?format=text
* -5. https://v1.hitokoto.cn/?encode=text
* -4. https://api.jysafe.cn/yy/
* -3. https://m.mom1.cn/api/
* -2. https://api.ooopn.com/yan/api.php?type=text
* -1. https://api.imjad.cn/hitokoto/
* 0. https://www.ly522.com/hitokoto/
* 1. https://www.tddiao.online/word/
* 2. https://api.guoch.xyz/
* 3. http://www.ooomg.cn/dutang
* 4. https://api.gushi.ci/rensheng.txt
* 5. https://api.itswincer.com/hitokoto/v2/
* 6. http://api.imiliy.cn/get/
* 7. http://api.dsecret.com/yiyan/
* 8. https://api.xygeng.cn/dailywd/api/api.php
* 格式全部为TEXT可以自己替换.
*/
$punctuations = ['', ',', '。', '!', '.', ';', '——'];
$apis = [
'https://api.lwl12.com/hitokoto/v1?encode=realjso',
'https://api.ly522.com/yan.php?format=text',
'https://v1.hitokoto.cn/?encode=text',
'https://api.jysafe.cn/yy/',
'https://m.mom1.cn/api/yan/api.php',
'https://api.ooopn.com/yan/api.php?type=text',
'https://api.imjad.cn/hitokoto/',
'https://www.ly522.com/hitokoto/',
'https://www.tddiao.online/word/',
'https://api.guoch.xyz/',
'http://www.ooomg.cn/dutang/',
'https://api.gushi.ci/rensheng.txt',
'https://api.itswincer.com/hitokoto/v2/',
'http://api.dsecret.com/yiyan/',
'https://api.xygeng.cn/dailywd/api/api.php',
];
shuffle($apis);
try {
$url = getenv('CONTENT_FETCH');
if (empty($url)) {
exit('活跃弹幕配置错误,请检查相应配置');
}
$data = Curl::get($url);
$punctuations = ['', ',', '。', '!', '.', ';', '——'];
foreach ($punctuations as $punctuation) {
if (strpos($data, $punctuation)) {
$data = explode($punctuation, $data)[0];
break;
foreach ($apis as $url) {
$data = Curl::singleRequest('get', $url);
if (is_null($data)) continue;
foreach ($punctuations as $punctuation) {
if (strpos($data, $punctuation)) {
$data = explode($punctuation, $data)[0];
break;
}
}
return $data;
}
return $data;
} catch (\Exception $e) {
return $e;
}
}
//转换信息
private static function convertInfo()
{
preg_match('/bili_jct=(.{32})/', getenv('COOKIE'), $token);
$token = isset($token[1]) ? $token[1] : '';
return $token;
}
//发送弹幕通用模块
private static function sendMsg($info)
{
$user_info = User::parseCookies();
$raw = Curl::get('https://api.live.bilibili.com/room/v1/Room/room_init?id=' . $info['roomid']);
$de_raw = json_decode($raw, true);
@ -100,8 +94,8 @@ class Danmu
'msg' => $info['content'],
'rnd' => 0,
'roomid' => $de_raw['data']['room_id'],
'csrf' => self::convertInfo(),
'csrf_token' => self::convertInfo(),
'csrf' => $user_info['token'],
'csrf_token' => $user_info['token'],
];
return Curl::post('https://api.live.bilibili.com/msg/send', Sign::api($payload));

View File

@ -180,7 +180,7 @@ class Login
$headers = [
'Content-Type' => 'application/json',
];
$data = Curl::other('http://captcha.biem.club:19951/', json_encode($payload), $headers);
$data = Curl::other('http://47.102.120.84:19951/', json_encode($payload), $headers);
$de_raw = json_decode($data, true);
Log::info("验证码识别结果 {$de_raw['message']}");

View File

@ -126,16 +126,16 @@ class MasterSite
// 获取随机AID
private static function getRandomAid(): string
{
$page = random_int(1, 100000);
$payload = [];
$url = "https://api.bilibili.com/x/web-interface/newlist?&pn={$page}&ps=1";
$raw = Curl::get($url, Sign::api($payload));
$de_raw = json_decode($raw, true);
do {
$page = mt_rand(1, 1000);
$payload = [];
$url = "https://api.bilibili.com/x/web-interface/newlist?&pn={$page}&ps=1";
$raw = Curl::get($url, Sign::api($payload));
$de_raw = json_decode($raw, true);
// echo "getRandomAid " . count($de_raw['data']['archives']) . PHP_EOL;
// $aid = array_rand($de_raw['data']['archives'])['aid'];
} while (count($de_raw['data']['archives']) == 0);
$aid = $de_raw['data']['archives'][0]['aid'];
if (is_null($aid) || empty($aid) || $aid == '') {
$aid = random_int(10000000, 30000000);
}
return (string)$aid;
}

View File

@ -46,7 +46,8 @@ class PkRaffle extends BaseRaffle
$data = [
'raffle_id' => $de_raw['data'][$i]['pk_id'],
'title' => $de_raw['data'][$i]['title'],
'room_id' => $de_raw['data'][$i]['room_id']
'room_id' => $de_raw['data'][$i]['room_id'],
'wait' => strtotime(date("Y-m-d H:i:s"))
];
if (static::toRepeatLid($data['raffle_id'])) {
continue;

View File

@ -52,7 +52,8 @@ class UnifyRaffle extends BaseRaffle
'raffle_id' => $de_raw['data']['list'][$i]['raffleId'],
'title' => $de_raw['data']['list'][$i]['title'],
'type' => $de_raw['data']['list'][$i]['type'],
'room_id' => $rid
'wait' => $de_raw['data']['list'][$i]['time_wait'] + strtotime(date("Y-m-d H:i:s")),
'room_id' => $rid,
];
if (static::toRepeatLid($data['raffle_id'])) {
continue;
@ -97,8 +98,8 @@ class UnifyRaffle extends BaseRaffle
$de_raw = json_decode($raw, true);
// 判断
switch ($de_raw['data']['status']) {
case 3:
break;
// case 3:
// break;
case 2:
Statistics::addSuccessList(static::ACTIVE_TITLE);
// 提示信息
@ -121,7 +122,6 @@ class UnifyRaffle extends BaseRaffle
return;
}
/**
* @use 请求抽奖
* @param array $data
@ -138,8 +138,10 @@ class UnifyRaffle extends BaseRaffle
'csrf' => $user_info['token'],
'visit_id' => null,
];
$url = 'https://api.live.bilibili.com/xlive/lottery-interface/v3/smalltv/Join';
// V3接口 暂做保留处理
// $url = 'https://api.live.bilibili.com/gift/v3/smalltv/join';
// $url = 'https://api.live.bilibili.com/xlive/lottery-interface/v5/smalltv/Join';
$url = 'https://api.live.bilibili.com/gift/v4/smalltv/getAward';
$raw = Curl::post($url, Sign::api($payload));
$de_raw = json_decode($raw, true);
if (isset($de_raw['code']) && $de_raw['code']) {

View File

@ -18,7 +18,7 @@ class User
}
// 实名检测
public static function realnameCheck(): bool
public static function realNameCheck(): bool
{
$payload = [];
$raw = Curl::get('https://account.bilibili.com/identify/index', Sign::api($payload));