Skip to content

Commit 3299dde

Browse files
authored
fix(doc/misc/sign/wbi.md): swift demo (SocialSisterYi#1389)
(cherry picked from commit 6eb04ea636f2d38303471dec6e98c4a740024beb)
1 parent f73870b commit 3299dde

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

docs/misc/sign/wbi.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,16 +1131,20 @@ func biliWbiSign(param: String, completion: @escaping (String?) -> Void) {
11311131
func encWbi(params: [String: Any], imgKey: String, subKey: String) -> [String: Any] {
11321132
var params = params
11331133
let mixinKey = getMixinKey(orig: imgKey + subKey)
1134-
let currTime = round(Date().timeIntervalSince1970)
1134+
let currTime = Int(Date().timeIntervalSince1970)
11351135
params["wts"] = currTime
1136-
params = params.sorted { $0.key < $1.key }.reduce(into: [:]) { $0[$1.key] = $1.value }
1137-
params = params.mapValues { value in
1136+
let query = params.sorted {
1137+
$0.key < $1.key
1138+
}.map { (key, value) -> String in
1139+
let stringValue: String
11381140
if let doubleValue = value as? Double, doubleValue.truncatingRemainder(dividingBy: 1) == 0 {
1139-
return String(Int(doubleValue)).filter { !"!'()*".contains($0) }
1141+
stringValue = String(Int(doubleValue))
1142+
} else {
1143+
stringValue = String(describing: value)
11401144
}
1141-
return String(describing: value).filter { !"!'()*".contains($0) }
1142-
}
1143-
let query = params.map { "\($0.key)=\($0.value)" }.joined(separator: "&")
1145+
let filteredValue = stringValue.filter { !"!'()*".contains($0) }
1146+
return "\(key)=\(filteredValue)"
1147+
}.joined(separator: "&")
11441148
let wbiSign = calculateMD5(string: query + mixinKey)
11451149
params["w_rid"] = wbiSign
11461150
return params

0 commit comments

Comments
 (0)