Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix_-663_error_again #86

Merged
merged 18 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ lazy_static! {
}

fn main() -> std::io::Result<()> {
// 拿来生成signed_url挺方便的 此处测试用
// let mut req_params = "access_key=ccd0991e90ab67631b5b644142890733&appkey=783bbb7264451d82&ts=1670929680";
// let mut signed_params = format!("{req_params}&sign=");
// let mut sign = crypto::md5::Md5::new();
// crypto::digest::Digest::input_str(&mut sign, &format!("{req_params}2653583c8873dea268ab9386918b1d65"));
// let md5_sign = crypto::digest::Digest::result_str(&mut sign);
// signed_params.push_str(&md5_sign);
// println!("{signed_params}");
cxw620 marked this conversation as resolved.
Show resolved Hide resolved

// init log
use chrono::Local;
use std::io::Write;
Expand Down
7 changes: 4 additions & 3 deletions src/mods/background_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ pub async fn update_cached_area_background(

pub async fn update_cached_user_info_background(
access_key: String,
retry_num: u8,
bili_runtime: &BiliRuntime<'_>,
) {
trace!("[BACKGROUND TASK] AK {access_key} -> Accept UserInfo Cache Refresh Task...");
let background_task_data =
BackgroundTaskType::Cache(CacheTask::UserInfoCacheRefresh(access_key));
BackgroundTaskType::Cache(CacheTask::UserInfoCacheRefresh(access_key,retry_num));
bili_runtime.send_task(background_task_data).await
}

Expand Down Expand Up @@ -217,7 +218,7 @@ pub async fn background_task_run(
}
},
BackgroundTaskType::Cache(value) => match value {
CacheTask::UserInfoCacheRefresh(access_key) => {
CacheTask::UserInfoCacheRefresh(access_key,retry_num) => {
let appkey = "1d8b6e7d45233436";
let appsec = "560c52ccd288fed045859ed18bffd973";
// let user_agent = "Dalvik/2.1.0 (Linux; U; Android 11; 21091116AC Build/RP1A.200720.011)";
Expand All @@ -227,7 +228,7 @@ pub async fn background_task_run(
is_th: false,
user_agent: &user_agent,
..Default::default()
}, true, &bili_runtime).await {
}, true, retry_num, &bili_runtime).await {
Ok(new_user_info) => match get_blacklist_info(&new_user_info, bili_runtime).await {
Ok(_) => Ok(()),
Err(value) => Err(format!("[BACKGROUND TASK] UID {} | Refreshing blacklist info failed, ErrMsg: {}", new_user_info.uid, value.to_string())),
Expand Down
2 changes: 2 additions & 0 deletions src/mods/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ pub async fn handle_playurl_request(req: &HttpRequest, is_app: bool, is_th: bool
params.appsec,
&params,
false,
1,
&bili_runtime,
)
.await
Expand Down Expand Up @@ -407,6 +408,7 @@ pub async fn handle_search_request(req: &HttpRequest, is_app: bool, is_th: bool)
params.appsec,
&params,
false,
1,
&bili_runtime,
)
.await
Expand Down
2 changes: 1 addition & 1 deletion src/mods/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ pub enum HealthTask {
HealthReport(HealthReportType),
}
pub enum CacheTask {
UserInfoCacheRefresh(String),
UserInfoCacheRefresh(String,u8),
PlayurlCacheRefresh(PlayurlParamsStatic),
ProactivePlayurlCacheRefresh,
EpInfoCacheRefresh(bool, Vec<EpInfo>),
Expand Down
83 changes: 51 additions & 32 deletions src/mods/upstream_res.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub async fn get_upstream_bili_account_info(
_appsec: &str,
_is_app: bool,
user_agent: &str,
retry_num: u8,
bili_runtime: &BiliRuntime<'_>,
) -> Result<UserInfo, EType> {
use rand::Rng;
Expand Down Expand Up @@ -72,7 +73,7 @@ pub async fn get_upstream_bili_account_info(
headers.append("x-bili-aurora-zone: sh001").unwrap();
headers.append("app-key: android64").unwrap();

let api = "https://app.bilibili.com/x/v2/account/myinfo";
let api = "https://app.bilibili.com/x/v2/account/mine";
let (signed_url, sign) = build_signed_url!(api, req_vec, appsec);

debug!(
Expand Down Expand Up @@ -141,39 +142,55 @@ pub async fn get_upstream_bili_account_info(
};
match code {
0 => {
let output_struct = UserInfo {
code: 0,
access_key: String::from(access_key),
uid: upstream_raw_resp_json["data"]["mid"].as_u64().unwrap(),
vip_expire_time: upstream_raw_resp_json["data"]["vip"]["due_date"]
.as_u64()
.unwrap(),
expire_time: {
if ts
< upstream_raw_resp_json["data"]["vip"]["due_date"]
.as_u64()
.unwrap()
&& upstream_raw_resp_json["data"]["vip"]["due_date"]
.as_u64()
.unwrap()
< ts + 25 * 24 * 60 * 60 * 1000
{
upstream_raw_resp_json["data"]["vip"]["due_date"]
.as_u64()
.unwrap()
} else {
ts + 25 * 24 * 60 * 60 * 1000
}
}, //用户状态25天强制更新
};
update_user_info_cache(&output_struct, bili_runtime).await;
Ok(output_struct)
if upstream_raw_resp_json["data"]["mid"].as_u64().unwrap_or(0) == 0 {// accesskey失效时mid为0
let output_struct = UserInfo {
code,
expire_time: ts + 1 * 60 * 60 * 1000, // 未登录缓存1h,防止高频请求b站服务器
..Default::default()
};
update_user_info_cache(&output_struct, bili_runtime).await;
error!(
"[GET USER_INFO][U] AK {} | Get UserInfo failed -101. Upstream Reply -> {}",
access_key, upstream_raw_resp_json
);
Err(EType::UserNotLoginedError)
}else{
let output_struct = UserInfo {
code: 0,
access_key: String::from(access_key),
uid: upstream_raw_resp_json["data"]["mid"].as_u64().unwrap(),
vip_expire_time: upstream_raw_resp_json["data"]["vip"]["due_date"]
.as_u64()
.unwrap(),
expire_time: {
if ts
< upstream_raw_resp_json["data"]["vip"]["due_date"]
.as_u64()
.unwrap()
&& upstream_raw_resp_json["data"]["vip"]["due_date"]
.as_u64()
.unwrap()
< ts + 25 * 24 * 60 * 60 * 1000
{
upstream_raw_resp_json["data"]["vip"]["due_date"]
.as_u64()
.unwrap()
} else {
ts + 25 * 24 * 60 * 60 * 1000
}
}, //用户状态25天强制更新
};
update_user_info_cache(&output_struct, bili_runtime).await;
Ok(output_struct)
}
}
-404 => {
match appkey {
"84956560bc028eb7" | "85eb6835b0a1034e" => {
// 还是迂回更新其用户信息试一下
update_cached_user_info_background(access_key.to_string(), bili_runtime).await;
if retry_num != 0 {
update_cached_user_info_background(access_key.to_string(), retry_num-1,bili_runtime).await;
}
Err(EType::OtherError(
-10403,
"不兼容的APPKEY, 请升级油猴脚本或其他你正在用的客户端!",
Expand Down Expand Up @@ -273,7 +290,9 @@ pub async fn get_upstream_bili_account_info(
"[GET USER_INFO][U] AK {} | Get UserInfo failed -663. Upstream Reply -> {}",
access_key, upstream_raw_resp_json
);
update_cached_user_info_background(access_key.to_string(), bili_runtime).await;
if retry_num != 0 {
update_cached_user_info_background(access_key.to_string(), retry_num-1,bili_runtime).await;
}
let health_report_type = HealthReportType::Others(HealthData {
area_num: 0,
is_200_ok: true,
Expand All @@ -286,7 +305,7 @@ pub async fn get_upstream_bili_account_info(
},
is_custom: true,
custom_message: format!(
"[GET USER_INFO][U] -663错误! 理论上已修复, 仍出现此错误请提issue\nDevice: {}, APPKEY: {}, AK: {}, TS: {}",
"[GET USER_INFO][U] -663错误! 正在尝试修复\nDevice: {}, APPKEY: {}, AK: {}, TS: {}",
mobi_app, appkey, access_key, ts
),
});
Expand Down Expand Up @@ -603,7 +622,7 @@ pub async fn get_upstream_bili_playurl(
if !params.is_vip {
if let Ok(value) = check_vip_status_from_playurl(playurl_type, &upstream_raw_resp_json) {
if value {
update_cached_user_info_background(params.access_key.to_string(), bili_runtime)
update_cached_user_info_background(params.access_key.to_string(), 1, bili_runtime)
.await;
match get_ep_need_vip(params.ep_id, bili_runtime).await {
Some(ep_need_vip) => {
Expand Down
4 changes: 4 additions & 0 deletions src/mods/user_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub async fn get_user_info<T: HasIsappIsthUseragent>(
appsec: &str,
params: &T,
force_update: bool,
retry_num: u8,
bili_runtime: &BiliRuntime<'_>,
) -> Result<UserInfo, EType> {
// detect web request
Expand All @@ -41,6 +42,7 @@ pub async fn get_user_info<T: HasIsappIsthUseragent>(
appsec,
is_app,
params.user_agent(),
retry_num,
bili_runtime,
)
.await
Expand Down Expand Up @@ -88,6 +90,7 @@ pub async fn get_user_info<T: HasIsappIsthUseragent>(
appsec,
is_app,
params.user_agent(),
retry_num,
bili_runtime,
)
.await
Expand Down Expand Up @@ -354,6 +357,7 @@ pub async fn resign_user_info(
params.appsec,
params,
false,
1,
bili_runtime,
)
.await
Expand Down