Skip to content

Commit

Permalink
Merge pull request #190 from huankong233/dev
Browse files Browse the repository at this point in the history
[+] 增加新账号类型
  • Loading branch information
huankong233 authored Aug 21, 2024
2 parents 5eae5b2 + 839203e commit 7f35c51
Show file tree
Hide file tree
Showing 79 changed files with 135 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ MAIL_FROM_NAME=Example
MAIL_TO_ADDRESS=[email protected]
MAIL_TO_NAME=Example

_94LIST_VERSION=1.3.33
_94LIST_VERSION=1.3.34
_94LIST_SLEEP=3
_94LIST_MAX_ONCE=20
_94LIST_PASSWORD=""
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 2024

### 08-21 v1.3.34

- [+] 增加新账号类型

### 08-17 v1.3.33

- [*] 修复代码异常报错
Expand Down
37 changes: 27 additions & 10 deletions app/Http/Controllers/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function _getAccountInfo($type, $cookie)
$http = new Client([
"headers" => [
"User-Agent" => config("94list.fake_user_agent"),
"cookie" => $type === 1 ? $cookie : ""
"cookie" => $type === 2 ? "" : $cookie
]
]);

Expand Down Expand Up @@ -86,7 +86,7 @@ public static function _getSvipEndAt($type, $cookie)
$http = new Client([
"headers" => [
"User-Agent" => config("94list.fake_user_agent"),
"Cookie" => $type === 1 ? $cookie : ""
"Cookie" => $type === 2 ? "" : $cookie
]
]);

Expand All @@ -105,6 +105,27 @@ public static function _getSvipEndAt($type, $cookie)

public static function _getAccountItems($type, $cookie)
{
if ($type === 3) {
$http = new Client([
"headers" => [
"User-Agent" => config("94list.fake_user_agent"),
"Cookie" => $cookie
]
]);

try {
$res = $http->get("https://pan.baidu.com/mid_enterprise_v2/api/enterprise/organization/allorganizationinfo", ["query" => ["clienttype" => 0, "app_id" => 24029990]]);
$response = JSON::decode($res->getBody()->getContents());
} catch (RequestException $e) {
$response = $e->hasResponse() ? JSON::decode($e->getResponse()->getBody()->getContents()) : null;
} catch (GuzzleException $e) {
return ResponseController::networkError("获取SVIP到期时间");
}

if (isset($response["errmsg"]) && $response["errmsg"] === "Invalid Bduss") return ResponseController::accountExpired();
$cid = $response["data"][0]["cid"];
}

$accountInfoRes = self::_getAccountInfo($type, $cookie);
$accountInfoData = $accountInfoRes->getData(true);
if ($accountInfoData["code"] !== 200) return $accountInfoRes;
Expand Down Expand Up @@ -137,6 +158,7 @@ public static function _getAccountItems($type, $cookie)
return ResponseController::success([
"uk" => $accountInfoData["data"]["uk"],
"baidu_name" => $accountInfoData["data"]["baidu_name"],
"cid" => $cid ?? null,
"cookie" => $cookie,
"vip_type" => $vip_type,
"switch" => $switch ?? 1,
Expand All @@ -148,7 +170,7 @@ public static function _getAccountItems($type, $cookie)
public function addAccount(Request $request)
{
$validator = Validator::make($request->all(), [
"type" => ["required", Rule::in([1, 2])],
"type" => ["required", Rule::in([1, 2, 3])],
"cookie" => "required|string"
]);

Expand All @@ -165,13 +187,6 @@ public function addAccount(Request $request)
$cookieData = $cookie->getData(true);
if ($cookieData["code"] !== 200) return $cookie;
$cookie = $cookieData["data"]["access_token"];
} else {
$cookieData = [
"data" => [
"access_token" => null,
"refresh_token" => null
]
];
}

$accountItemsRes = self::_getAccountItems($request["type"], $cookie);
Expand All @@ -186,6 +201,8 @@ public function addAccount(Request $request)
$accountItemsData["data"]["refresh_token"] = $cookieData["data"]["refresh_token"];
$accountItemsData["data"]["expired_at"] = now()->addSeconds($cookieData["data"]["expires_in"]);
$accountItemsData["data"]["cookie"] = null;
} else if ($request["type"] === 3) {
$accountItemsData["data"]["account_type"] = "enterprise";
}
Account::query()->create($accountItemsData["data"]);
} else {
Expand Down
108 changes: 63 additions & 45 deletions app/Http/Controllers/ParseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getConfig(Request $request)
"announce" => $config["announce"],
"debug" => config("app.debug"),
"max_once" => $config["max_once"],
"have_account" => in_array($config["parse_mode"], [11]) || self::getRandomCookie(["超级会员"], false)->getData(true)["code"] === 200,
"have_account" => self::getRandomCookie(["超级会员"], false)->getData(true)["code"] === 200,
"have_login" => Auth::check(),
"need_inv_code" => $config["need_inv_code"],
"need_password" => $config["password"] !== "",
Expand Down Expand Up @@ -187,6 +187,7 @@ public static function _getRandomCookie($prov, $vipType, $account_type)
'accounts.uk',
'accounts.access_token',
'accounts.refresh_token',
'accounts.cid',
'accounts.expired_at',
'accounts.vip_type',
'accounts.switch',
Expand All @@ -203,7 +204,7 @@ public static function _getRandomCookie($prov, $vipType, $account_type)
->first();
}

public function getRandomCookie(array $vipType = ["超级会员"], $makeNew = true)
public function getRandomCookie($vipType = ["超级会员"], $makeNew = true)
{
$ip = UtilsController::getIp();
if (config("94list.limit_cn") || config("94list.limit_prov")) {
Expand All @@ -214,6 +215,7 @@ public function getRandomCookie(array $vipType = ["超级会员"], $makeNew = tr
}

$account_type = in_array(config("94list.parse_mode"), [5, 10]) ? "access_token" : "cookie";
if (config("94list.parse_mode") === 11) $account_type = "enterprise";

if (in_array("超级会员", $vipType)) {
// 刷新令牌
Expand Down Expand Up @@ -594,49 +596,54 @@ public function getDownloadLinks(Request $request)
$json["vcode_str"] = $request["vcode_str"];
}

if (!in_array($parse_mode, [11])) {
// 插入会员账号
$json["cookie"] = [];

// 检查是否指定了账号管理员
if (isset($request["account_ids"]) && $request["account_ids"] !== "") {
$user_id = Auth::check() ? Auth::user()["id"] : 1;
$user = User::query()->find($user_id);
$role = $user["role"];
if ($role !== "admin") return ResponseController::permissionsDenied();

// 判断是否只是一个文件
if (count($request["fs_ids"]) > 1) return ResponseController::onlyOneFile();

$json["fsidlist"] = [];
$request["account_ids"] = explode(",", $request["account_ids"]);
foreach ($request["account_ids"] as $account_id) {
$account = Account::query()->find($account_id);
if (!$account) return ResponseController::accountNotExists();
$arr = ["id" => $account_id];
if (in_array($parse_mode, [5, 10])) {
if ($account["account_type"] !== "access_token") return ResponseController::accountTypeWrong($account_id);
$arr["access_token"] = $account["access_token"];
} else {
if ($account["account_type"] !== "cookie") return ResponseController::accountTypeWrong($account_id);
$arr["cookie"] = $account["cookie"];
}
$json["cookie"][] = $arr;
$json["fsidlist"][] = $request["fs_ids"][0];
// 插入会员账号
$json["cookie"] = [];

// 检查是否指定了账号管理员
if (isset($request["account_ids"]) && $request["account_ids"] !== "") {
$user_id = Auth::check() ? Auth::user()["id"] : 1;
$user = User::query()->find($user_id);
$role = $user["role"];
if ($role !== "admin") return ResponseController::permissionsDenied();

// 判断是否只是一个文件
if (count($request["fs_ids"]) > 1) return ResponseController::onlyOneFile();

$json["fsidlist"] = [];
$request["account_ids"] = explode(",", $request["account_ids"]);
foreach ($request["account_ids"] as $account_id) {
$account = Account::query()->find($account_id);
if (!$account) return ResponseController::accountNotExists();
$arr = ["id" => $account_id];
if (in_array($parse_mode, [5, 10])) {
if ($account["account_type"] !== "access_token") return ResponseController::accountTypeWrong($account_id);
$arr["access_token"] = $account["access_token"];
} else if ($parse_mode === 11) {
if ($account["account_type"] !== "") return ResponseController::accountTypeWrong($account_id);
$arr["cookie"] = $account["cookie"];
$arr["cid"] = $account["cid"];
} else {
if ($account["account_type"] !== "cookie") return ResponseController::accountTypeWrong($account_id);
$arr["cookie"] = $account["cookie"];
}
} else {
for ($i = 0; $i < count($request["fs_ids"]); $i++) {
$cookie = self::getRandomCookie();
$cookieData = $cookie->getData(true);
if ($cookieData["code"] !== 200) return $cookie;
$arr = ["id" => $cookieData["data"]["id"]];
if ($cookieData["data"]["account_type"] === "access_token") {
$arr["access_token"] = $cookieData["data"]["access_token"];
} else {
$arr["cookie"] = $cookieData["data"]["cookie"];
}
$json["cookie"][] = $arr;
$json["cookie"][] = $arr;
$json["fsidlist"][] = $request["fs_ids"][0];
}
} else {
for ($i = 0; $i < count($request["fs_ids"]); $i++) {
$cookie = self::getRandomCookie($parse_mode === 11 ? ["超级会员", "普通会员", "普通用户"] : ["超级会员"]);
$cookieData = $cookie->getData(true);
if ($cookieData["code"] !== 200) return $cookie;
$arr = ["id" => $cookieData["data"]["id"]];
if ($cookieData["data"]["account_type"] === "access_token") {
$arr["access_token"] = $cookieData["data"]["access_token"];
} else if ($cookieData["data"]["account_type"] === "enterprise") {
$arr["cookie"] = $cookieData["data"]["cookie"];
$arr["cid"] = $cookieData["data"]["cid"];
} else {
$arr["cookie"] = $cookieData["data"]["cookie"];
}
$json["cookie"][] = $arr;
}
}

Expand Down Expand Up @@ -682,7 +689,7 @@ public function getDownloadLinks(Request $request)
if ($key === "") $key = "download";
$server = config("94list.proxy_server");

$data = array_map(function ($responseDatum) use ($ua, $parse_mode, $request, $user_id, $token, $token_id, &$banned, &$limited, $server, $key) {
$data = array_map(function ($responseDatum) use ($ua, $parse_mode, $request, $user_id, $token, $token_id, &$banned, &$limited, $server, $key, $json) {
$url = $responseDatum["url"];
$res = [
"url" => $url,
Expand All @@ -696,7 +703,8 @@ public function getDownloadLinks(Request $request)
$res["url"] = $server . "?data=" . self::xorEncrypt($json, $key);
}

$ck_id = $responseDatum["cookie_id"] ?? 0;
$ck_id = $responseDatum["cookie_id"] ?? 0;
if ($parse_mode === 11) $ck_id = $json["cookie"][0]["id"];
$account = Account::query()->find($ck_id);

if (isset($responseDatum["msg"]) && $responseDatum["msg"] === "获取成功") {
Expand All @@ -710,6 +718,16 @@ public function getDownloadLinks(Request $request)
]);

$limited[] = $ck_id;
} else if (str_contains($url, "风控")) {
$res["url"] = "账号已风控";

$account->update([
"last_use_at" => date("Y-m-d H:i:s"),
"switch" => 0,
"reason" => $url,
]);

$banned[] = $ck_id;
} else {
$account->update(["last_use_at" => date("Y-m-d H:i:s")]);

Expand Down
8 changes: 8 additions & 0 deletions app/Http/Middleware/AutoUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ public function handle(Request $request, Closure $next): Response
]);
}

// 1.3.34 迁移 增加企业cid
if (!Schema::hasColumn("accounts", "cid")) {
Schema::table("accounts", function (Blueprint $table) {
$table->enum("account_type", ["cookie", "access_token", "enterprise"])->change();
$table->unsignedBigInteger("cid")->nullable()->after("refresh_token");
});
}

return $next($request);
}
}
1 change: 1 addition & 0 deletions app/Models/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Account extends Model
"cookie",
"access_token",
"refresh_token",
"cid",
"expired_at",
"vip_type",
"switch",
Expand Down
2 changes: 1 addition & 1 deletion config/94list.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"fake_wx_user_agent" => "Mozilla/5.0 (Linux; Android 7.1.1; MI 6 Build/NMF26X; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/043807 Mobile Safari/537.36 MicroMessenger/6.6.1.1220(0x26060135) NetType/4G Language/zh_CN MicroMessenger/6.6.1.1220(0x26060135) NetType/4G Language/zh_CN miniProgram",
"fake_cookie" => "BAIDUID=A4FDFAE43DDBF7E6956B02F6EF715373:FG=1; BAIDUID_BFESS=A4FDFAE43DDBF7E6956B02F6EF715373:FG=1; newlogin=1",

"version" => "1.3.33",
"version" => "1.3.34",
"sleep" => (int)env("_94LIST_SLEEP", 3),
"max_once" => (int)env("_94LIST_MAX_ONCE", 20),
"password" => env("_94LIST_PASSWORD", ""),
Expand Down
1 change: 1 addition & 0 deletions public/assets/css/AccountManagement-CvA_2gMU.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.table[data-v-a8baa8b2],.el-pagination[data-v-a8baa8b2]{margin-top:15px}
1 change: 0 additions & 1 deletion public/assets/css/AccountManagement-OOe8fkcU.css

This file was deleted.

Loading

0 comments on commit 7f35c51

Please sign in to comment.