diff --git a/DarockBili Watch App/Extension/CodeExt.swift b/DarockBili Watch App/Extension/CodeExt.swift index 308fe1e12..e0df3a182 100644 --- a/DarockBili Watch App/Extension/CodeExt.swift +++ b/DarockBili Watch App/Extension/CodeExt.swift @@ -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) { @@ -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)") diff --git a/DarockBili Watch App/PersonalCenter/UserDetailView.swift b/DarockBili Watch App/PersonalCenter/UserDetailView.swift index 09d6a2d6d..82e3f8102 100644 --- a/DarockBili Watch App/PersonalCenter/UserDetailView.swift +++ b/DarockBili Watch App/PersonalCenter/UserDetailView.swift @@ -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