Skip to content

Commit

Permalink
Merge pull request #385 from ywmoyue/dev
Browse files Browse the repository at this point in the history
4.6.20
  • Loading branch information
ywmoyue authored Oct 31, 2023
2 parents d706de4 + 7f7c300 commit ec59e89
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 23 deletions.
10 changes: 10 additions & 0 deletions src/BiliLite.UWP/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,16 @@ public static Color StrToColor(this string obj)
return color;
}

/// <summary>
/// 是否为正确格式的url
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public static bool IsUrl(this string url)
{
return Uri.TryCreate(url, UriKind.Absolute, out Uri _);
}

#region Private methods

/// <summary>
Expand Down
9 changes: 8 additions & 1 deletion src/BiliLite.UWP/Models/Common/ApiKeyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
{
public class ApiKeyInfo
{
public ApiKeyInfo(string key, string secret)
public ApiKeyInfo(string key, string secret, string mobiApp, string userAgent)
{
Appkey = key;
Secret = secret;
MobiApp = mobiApp;
UserAgent = userAgent;
}
public string Appkey { get; set; }

public string Secret { get; set; }

public string MobiApp { get; set; }

public string UserAgent { get; set; }
}
}
14 changes: 14 additions & 0 deletions src/BiliLite.UWP/Models/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ public static class Constants
/// </summary>
public const string COMMENT_SPECIAL_TEXT_REGULAR = @"\[(.*?)\]|https?:\/\/\S+|http?:\/\/\S+|\p{Cs}";

public const string CHROME_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36";

public const string IOS_USER_AGENT = "bili-universal/75200100 CFNetwork/1.0 Darwin/23.0.0 os/ios model/iPad Air 3G mobi_app/iphone build/75200100 osVer/17.0.3 network/2 channel/AppStore";

public const string ANDROID_USER_AGENT = CHROME_USER_AGENT;

public const string IOS_MOBI_APP = "iphone";

public const string ANDROID_MOBI_APP = "android";

public const string IOS_APP_KEY = "27eb53fc9058f8c3";

public const string ANDROID_APP_KEY = "1d8b6e7d45233436";

public static class App
{
/// <summary>
Expand Down
14 changes: 12 additions & 2 deletions src/BiliLite.UWP/Models/Common/Live/LiveAnchorProfileGloryInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Newtonsoft.Json;
using BiliLite.Extensions;
using BiliLite.Services;
using Newtonsoft.Json;

namespace BiliLite.Models.Common.Live
{
Expand All @@ -17,7 +19,15 @@ public class LiveAnchorProfileGloryInfo
[JsonProperty("pic_url")]
public string PicUrl { get; set; }

private string jumpUrl;
[JsonProperty("jump_url")]
public string JumpUrl { get; set; }
public string JumpUrl
{
get => jumpUrl;
set
{
jumpUrl = value.IsUrl() ? value : ApiHelper.NOT_FOUND_URL;
}
}
}
}
4 changes: 2 additions & 2 deletions src/BiliLite.UWP/Models/Common/UpdateJsonAddressOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class UpdateJsonAddressOptions
new UpdateJsonAddressOption() { Name = "[镜像]kgithub", Value = ApiHelper.KGITHUB_GIT_RAW_URL },
};

// 优先使用服务器在香港腾讯云的kgithub
public const string DEFAULT_UPDATE_JSON_ADDRESS = ApiHelper.KGITHUB_GIT_RAW_URL;
// 优先使用更稳定的ghproxy
public const string DEFAULT_UPDATE_JSON_ADDRESS = ApiHelper.GHPROXY_GIT_RAW_URL;

public static UpdateJsonAddressOption GetOption(string type)
{
Expand Down
18 changes: 12 additions & 6 deletions src/BiliLite.UWP/Models/Requests/Api/AccountApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public ApiModel LoginV3(string username, string password, ApiKeyInfo appKey)
{
method = RestSharp.Method.Post,
baseUrl = "https://passport.bilibili.com/x/passport-login/oauth2/login",
body = $"actionKey=appkey&channel=bili&device=phone&permission=ALL&subid=1&username={Uri.EscapeDataString(username)}&password={Uri.EscapeDataString(password)}&" + ApiHelper.MustParameter(appKey)
body = $"actionKey=appkey&channel=bili&device=phone&permission=ALL&subid=1&username={Uri.EscapeDataString(username)}&password={Uri.EscapeDataString(password)}&" + ApiHelper.MustParameter(appKey),
headers = ApiHelper.MustHeader(appKey),
};
api.body += ApiHelper.GetSign(api.body, appKey);
return api;
Expand Down Expand Up @@ -84,7 +85,8 @@ public ApiModel SendSMS(string cid, string phone, string sessionId, ApiKeyInfo a
{
method = RestSharp.Method.Post,
baseUrl = "https://passport.bilibili.com/x/passport-login/sms/send",
body = $"actionKey=appkey&cid={cid}&tel={phone}&login_session_id={sessionId}&" + ApiHelper.MustParameter(appKey)
body = $"actionKey=appkey&cid={cid}&tel={phone}&login_session_id={sessionId}&" + ApiHelper.MustParameter(appKey),
headers = ApiHelper.MustHeader(appKey),
};
api.body += ApiHelper.GetSign(api.body, appKey);
return api;
Expand All @@ -97,7 +99,8 @@ public ApiModel SendSMSWithCaptcha(string cid, string phone, string session_id,
{
method = RestSharp.Method.Post,
baseUrl = "https://passport.bilibili.com/x/passport-login/sms/send",
body = $"buvid={buvid}&actionKey=appkey&cid={cid}&tel={phone}&login_session_id={session_id}&gee_seccode={seccode}&gee_validate={validate}&gee_challenge={challenge}&recaptcha_token={recaptchaToken}&" + ApiHelper.MustParameter(appKey)
body = $"buvid={buvid}&actionKey=appkey&cid={cid}&tel={phone}&login_session_id={session_id}&gee_seccode={seccode}&gee_validate={validate}&gee_challenge={challenge}&recaptcha_token={recaptchaToken}&" + ApiHelper.MustParameter(appKey),
headers = ApiHelper.MustHeader(appKey),
};
api.body += ApiHelper.GetSign(api.body, appKey);
return api;
Expand All @@ -109,7 +112,8 @@ public ApiModel SMSLogin(string cid, string phone, string code, string sessionId
{
method = RestSharp.Method.Post,
baseUrl = "https://passport.bilibili.com/x/passport-login/login/sms",
body = $"actionKey=appkey&cid={cid}&tel={phone}&login_session_id={sessionId}&captcha_key={captchaKey}&code={code}&" + ApiHelper.MustParameter(appKey)
body = $"actionKey=appkey&cid={cid}&tel={phone}&login_session_id={sessionId}&captcha_key={captchaKey}&code={code}&" + ApiHelper.MustParameter(appKey),
headers = ApiHelper.MustHeader(appKey),
};
api.body += ApiHelper.GetSign(api.body, appKey);
return api;
Expand Down Expand Up @@ -327,7 +331,8 @@ public ApiModel QRLoginAuthCodeTV(string local_id, ApiKeyInfo appkey)
{
method = RestSharp.Method.Post,
baseUrl = "https://passport.bilibili.com/x/passport-tv-login/qrcode/auth_code",
body = ApiHelper.MustParameter(appkey, false) + $"&local_id={local_id}",
body = $"appkey={appkey.Appkey}&local_id={local_id}&ts={TimeExtensions.GetTimestampS()}&mobi_app=ios",
headers = ApiHelper.MustHeader(appkey),
};
api.body += ApiHelper.GetSign(api.body, appkey);
return api;
Expand All @@ -344,7 +349,8 @@ public ApiModel QRLoginPollTV(string auth_code, string local_id, ApiKeyInfo appk
{
method = RestSharp.Method.Post,
baseUrl = "https://passport.bilibili.com/x/passport-tv-login/qrcode/poll",
body = ApiHelper.MustParameter(appkey, false) + $"&auth_code={auth_code}&guid={Guid.NewGuid().ToString()}&local_id={local_id}",
body = $"appkey={appkey.Appkey}&auth_code={auth_code}&local_id={local_id}&ts={TimeExtensions.GetTimestampS()}&mobi_app=ios",
headers = ApiHelper.MustHeader(appkey),
};
api.body += ApiHelper.GetSign(api.body, appkey);
return api;
Expand Down
10 changes: 7 additions & 3 deletions src/BiliLite.UWP/Models/Requests/BiliRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ public BiliRequest(string url, IDictionary<string, string> headers, IDictionary<
}

m_needRedirect = needRedirect;
m_request.WithHeader("user-agent",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36");

if (headers == null || !headers.ContainsKey("user-agent"))
{
m_request.WithHeader("user-agent",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36");
}
}

private static string StatusCodeToMessage(int code)
Expand Down Expand Up @@ -123,7 +127,7 @@ private async Task<HttpResults> ConstructNormalResults(IFlurlResponse response,
var results = await response.GetStringAsync();
var httpResults = new HttpResults()
{
code = (int) response.StatusCode,
code = (int)response.StatusCode,
status = responseMsg.StatusCode == HttpStatusCode.OK,
results = results,
message = "",
Expand Down
32 changes: 24 additions & 8 deletions src/BiliLite.UWP/Services/ApiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,29 @@ public static class ApiHelper
// 哔哩哔哩API
public const string API_BASE_URL = "https://api.bilibili.com";

// 哔哩哔哩404页面
public const string NOT_FOUND_URL = "https://www.bilibili.com/404";

//漫游默认的服务器
public const string ROMAING_PROXY_URL = "https://b.chuchai.vip";

// 抓取ipad端appkey
public static ApiKeyInfo IPadOsKey = new ApiKeyInfo("27eb53fc9058f8c3", "c2ed53a74eeefe3cf99fbd01d8c9c375");
public static ApiKeyInfo IPadOsKey = new ApiKeyInfo(Constants.IOS_APP_KEY, "c2ed53a74eeefe3cf99fbd01d8c9c375", Constants.IOS_MOBI_APP, Constants.IOS_USER_AGENT);

public static ApiKeyInfo AndroidVideoKey =
new ApiKeyInfo("iVGUTjsxvpLeuDCf", "aHRmhWMLkdeMuILqORnYZocwMBpMEOdt", null, null);

public static ApiKeyInfo AndroidVideoKey = new ApiKeyInfo("iVGUTjsxvpLeuDCf", "aHRmhWMLkdeMuILqORnYZocwMBpMEOdt");
public static ApiKeyInfo WebVideoKey = new ApiKeyInfo("84956560bc028eb7", "94aba54af9065f71de72f5508f1cd42e");
public static ApiKeyInfo AndroidTVKey = new ApiKeyInfo("4409e2ce8ffd12b8", "59b43e04ad6965f34319062b478f83dd");
public static ApiKeyInfo LoginKey = new ApiKeyInfo("783bbb7264451d82", "2653583c8873dea268ab9386918b1d65");
public static ApiKeyInfo WebVideoKey = new ApiKeyInfo("84956560bc028eb7", "94aba54af9065f71de72f5508f1cd42e",
null, Constants.CHROME_USER_AGENT);

public static ApiKeyInfo AndroidKey = new ApiKeyInfo("1d8b6e7d45233436", "560c52ccd288fed045859ed18bffd973");
public static ApiKeyInfo AndroidTVKey = new ApiKeyInfo("4409e2ce8ffd12b8", "59b43e04ad6965f34319062b478f83dd",
null, Constants.CHROME_USER_AGENT);
public static ApiKeyInfo LoginKey = new ApiKeyInfo("783bbb7264451d82", "2653583c8873dea268ab9386918b1d65", null, null);

public static ApiKeyInfo AndroidKey = new ApiKeyInfo(Constants.ANDROID_APP_KEY, "560c52ccd288fed045859ed18bffd973",
Constants.ANDROID_MOBI_APP, Constants.ANDROID_USER_AGENT);

private const string build = "6235200";
private const string _mobi_app = "android";
private const string _platform = "android";
public static string deviceId = "";
private static int[] mixinKeyEncTab = new int[] {
Expand Down Expand Up @@ -137,7 +145,15 @@ public static string MustParameter(ApiKeyInfo apikey, bool needAccesskey = false
url = $"access_key={SettingService.Account.AccessKey}&";
}

return url + $"appkey={apikey.Appkey}&build={build}&mobi_app={_mobi_app}&platform={_platform}&ts={TimeExtensions.GetTimestampS()}";
return url + $"appkey={apikey.Appkey}&build={build}&mobi_app={apikey.MobiApp}&platform={_platform}&ts={TimeExtensions.GetTimestampS()}";
}

public static Dictionary<string,string> MustHeader(ApiKeyInfo apiKey)
{
return new Dictionary<string, string>()
{
{ "user-agent", apiKey.UserAgent },
};
}

/// <summary>
Expand Down
19 changes: 18 additions & 1 deletion src/BiliLite.UWP/Services/SettingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,24 @@ public static ApiKeyInfo GetLoginAppKeySecret()
}

var keySecret = keySecretPair.Split(':');
var appKey = new ApiKeyInfo(keySecret[0], keySecret[1]);

var key = keySecret[0];
var secret = keySecret[1];
var userAgent = "";
var mobiApp = "";
switch (key)
{
case Constants.IOS_APP_KEY:
mobiApp = Constants.IOS_MOBI_APP;
userAgent = Constants.IOS_USER_AGENT;
break;
case Constants.ANDROID_APP_KEY:
mobiApp = Constants.ANDROID_MOBI_APP;
userAgent = Constants.ANDROID_USER_AGENT;
break;
}

var appKey = new ApiKeyInfo(keySecret[0], keySecret[1], mobiApp, userAgent);
_loginAppKey = appKey;
return appKey;
}
Expand Down

0 comments on commit ec59e89

Please sign in to comment.