XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/bilibili-API-collect

fix(doc/misc/sign/wbi.md): swift demo (#1389)

(cherry picked from commit 6eb04ea636f2d38303471dec6e98c4a740024beb)

3299dde
xjbeta <11794321+xjbeta@users.noreply.github.com>
提交于

代码差异

1 个文件 +11 -7
Modified docs/misc/sign/wbi.md +11 -7
@@ -1131,16 +1131,20 @@ func biliWbiSign(param: String, completion: @escaping (String?) -> Void) {
1131 1131 func encWbi(params: [String: Any], imgKey: String, subKey: String) -> [String: Any] {
1132 1132 var params = params
1133 1133 let mixinKey = getMixinKey(orig: imgKey + subKey)
1134 let currTime = round(Date().timeIntervalSince1970)
1134 let currTime = Int(Date().timeIntervalSince1970)
1135 1135 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
1138 1140 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)
1140 1144 }
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: "&")
1144 1148 let wbiSign = calculateMD5(string: query + mixinKey)
1145 1149 params["w_rid"] = wbiSign
1146 1150 return params