Skip to content

Commit

Permalink
Fix No Access Issue (#81)
Browse files Browse the repository at this point in the history
* Add some cookies

* Updated Wbi logic

* Update dm cover strs
  • Loading branch information
WindowsMEMZ authored Jan 20, 2024
1 parent c5f39a8 commit 1e2245d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
20 changes: 12 additions & 8 deletions DarockBili Watch App/Extension/CodeExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,20 @@ func biliWbiSign(paramEncoded: String, completion: @escaping (String?) -> Void)
return String(mixinKeyEncTab.map { orig[orig.index(orig.startIndex, offsetBy: $0)] }.prefix(32))
}

func encWbi(params: [String: Any], imgKey: String, subKey: String) -> [String: Any] {
func encWbi(params: [String: Any], imgKey: String, subKey: String) -> (wts: String, w_rid: String) {
var params = params
let mixinKey = getMixinKey(orig: imgKey + subKey)
let currTime = round(Date().timeIntervalSince1970)
params["wts"] = currTime
params = params.sorted { $0.key < $1.key }.reduce(into: [:]) { $0[$1.key] = $1.value }
params = params.mapValues { String(describing: $0).filter { !"!'()*".contains($0) } }
let query = params.map { "\($0.key)=\($0.value)" }.joined(separator: "&")
params["wts"] = Int(currTime)
let std = params.sorted { $0.key < $1.key }
var query = ""
for q in std {
query += "\(q.key)=\(q.value)&"
}
query.removeLast()
query = query.urlEncoded()
let wbiSign = calculateMD5(string: query + mixinKey)
params["w_rid"] = wbiSign
return params
return (String(Int(currTime)), wbiSign)
}

func getWbiKeys(completion: @escaping (Result<(imgKey: String, subKey: String), Error>) -> Void) {
Expand Down Expand Up @@ -230,7 +233,8 @@ func biliWbiSign(paramEncoded: String, completion: @escaping (String?) -> Void)
}

let signedParams = encWbi(params: spdDicParam, imgKey: keys.imgKey, subKey: keys.subKey)
let query = signedParams.map { "\($0.key)=\($0.value)" }.joined(separator: "&")
var query = decParam + "&w_rid=\(signedParams.w_rid)&wts=\(signedParams.wts)"
query = query.urlEncoded()
completion(query)
case .failure(let error):
print("Error getting keys: \(error)")
Expand Down
6 changes: 3 additions & 3 deletions DarockBili Watch App/PersonalCenter/UserDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,14 @@ struct UserDetailView: View {
//"accept-encoding": "gzip, deflate, br",
//"accept-language": "zh-CN,zh;q=0.9",
//"cookie": "\(sessdata == "" ? "" : "SESSDATA=\(sessdata); ")buvid3=\(globalBuvid3); b_nut=\(Date.now.timeStamp); buvid4=\(globalBuvid4);",
"cookie": "SESSDATA=\(sessdata); buvid_fp=e651c1a382430ea93631e09474e0b395",
"cookie": "SESSDATA=\(sessdata); buvid_fp=e651c1a382430ea93631e09474e0b395; buvid3=\(UuidInfoc.gen()); buvid4=buvid4-failed-1",
//"origin": "https://space.bilibili.com",
//"referer": "https://space.bilibili.com/\(uid)/video",
//"User-Agent": "Mozilla/5.0" // Bypass? drdar://gh/SocialSisterYi/bilibili-API-collect/issues/868/1859065874
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebK…KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"User-Agent": "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
]
// FIXME: Official Wbi crypto logic for this request seems different from other APIs, some IP can get but some can't. It's hard to fix ~_~
biliWbiSign(paramEncoded: "mid=\(uid)&ps=50&pn=\(videoNowPage)".base64Encoded()) { signed in
biliWbiSign(paramEncoded: "mid=\(uid)&ps=50&pn=\(videoNowPage)&dm_img_list=[]&dm_img_str=V2ViR0wgMS4wIChPcGVuR0wgRVMgMi4wIENocm9taXVtKQ&dm_cover_img_str=VjNEIDQuMkJyb2FkY2".base64Encoded()) { signed in
if let signed {
debugPrint(signed)
autoRetryRequestApi("https://api.bilibili.com/x/space/wbi/arc/search?\(signed)", headers: headers) { respJson, isSuccess in
Expand Down

0 comments on commit 1e2245d

Please sign in to comment.