Skip to content

Commit

Permalink
添加用户等级显示 (#71)
Browse files Browse the repository at this point in the history
* Updated user VIP & Level show

* Removed phone login

* Fix build issue

* Fix UI Spacer
  • Loading branch information
WindowsMEMZ committed Oct 12, 2024
1 parent 28d4279 commit 65664fd
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 100 deletions.
186 changes: 89 additions & 97 deletions DarockBili Watch App/Others/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,103 +112,95 @@ struct LoginView: View {
}

//--SMS Login--
List {
TextField("国际冠字码", text: $phoneCode)
.autocorrectionDisabled()
.textInputAutocapitalization(.never)
TextField("手机号", text: $accountInput)
.autocorrectionDisabled()
.textInputAutocapitalization(.never)
Button(action: {
let session = ASWebAuthenticationSession(url: URL(string: "https://darock.top/geetest?gt=\(gt)&challenge=\(challenge)")!, callbackURLScheme: "captcha") { callbackURL, _ in
if callbackURL != nil {
if callbackURL!.absoluteString.contains("callback") {
let str = callbackURL!.absoluteString.urlDecoded()
validate = String(str.split(separator: "?")[1].split(separator: "&")[0])
seccode = String(str.split(separator: "&")[1])
}
}
}
session.prefersEphemeralWebBrowserSession = true
session.start()
}, label: {
Text(validate == "" ? "进行人机验证" : "人机验证已完成")
.bold()
})
.disabled(validate != "")
Button(action: {
let headers: HTTPHeaders = [
"Host": "passport.bilibili.com",
"Origin": "https://www.bilibili.com",
"Referer": "https://www.bilibili.com/",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15",
"Cookie": "browser_resolution=1580-497; FEED_LIVE_VERSION=V8; buvid4=818BA302-8EAC-0630-67AB-BB978A5797AF60982-023042618-ho21%2BqF6LZokzAShrGptM4EHZm2TE4%2FTXmfZyPpzfCnLuUmUckb8wg%3D%3D; buvid_fp=5a716236853dd1e737d439882c685594; header_theme_version=CLOSE; home_feed_column=5; _uuid=15B5A2103-BBC2-9109A-7458-6410C3CF101028B94909infoc; b_lsid=CCF71993_18991563B31; b_ut=7; i-wanna-go-back=-1; innersign=0; b_nut=1690360493; buvid3=6481EDF5-10C43-9593-251E-89210B4A1C10A193894infoc"
]
AF.request("https://passport.bilibili.com/x/passport-login/web/sms/send", method: .post, parameters: BiliSmsCodePost(cid: Int(phoneCode)!, tel: Int(accountInput)!, token: loginToken, challenge: challenge, validate: validate, seccode: seccode), headers: headers).response { response in
debugPrint(response)
let json = try! JSON(data: response.data!)
smsLoginToken = json["data"]["captcha_key"].string!
}
}, label: {
Text("获取验证码")
})
.disabled(accountInput == "" || validate == "" || smsLoginToken != "")
SecureField("验证码", text: $passwdInput)
Section {
Button(action: {
if phoneCode == "375" && accountInput == "ASCDemo17245" && passwdInput == "Demo267&ac=*" {
dedeUserID = "3493279255497074"
dedeUserID__ckMd5 = "3dc9e007861d3264"
sessdata = "ee3fe1cd,1706077691,cce33*72iwtRb9aI-sowIE4Wjh_HSt2vFGveKTFChcptZbrn-nNBrz8oDVZVeB-gLx7z5bQXrYq8gQAASgA"
biliJct = "611b2f688b1145802c0e36b722a35234"
dismiss()
} else {
AF.request("https://passport.bilibili.com/x/passport-login/web/login/sms", method: .post, parameters: BiliLoginPost(cid: Int(phoneCode)!, tel: Int(accountInput)!, code: Int(passwdInput)!, captcha_key: smsLoginToken)).response { response in
let data = response.data
if data != nil {
let json = try! JSON(data: data!)
debugPrint(json)
if json["code"].int == 0 {
if json["data"]["status"].int == 0 {
debugPrint(response.response!.headers)
let setCookie = response.response!.headers["Set-Cookie"]!
dedeUserID = String(setCookie.split(separator: "DedeUserID=")[1].split(separator: ";")[0])
dedeUserID__ckMd5 = String(setCookie.split(separator: "DedeUserID__ckMd5=")[1].split(separator: ";")[0])
if setCookie.hasPrefix("SESSDATA") {
sessdata = String(setCookie.split(separator: "SESSDATA=")[0].split(separator: ";")[0])
} else {
sessdata = String(setCookie.split(separator: "SESSDATA=")[1].split(separator: ";")[0])
}
biliJct = String(setCookie.split(separator: "bili_jct=")[1].split(separator: ";")[0])
dismiss()
} else if json["data"]["status"].int == 1006 {

} else if json["data"]["status"].int == 1007 {

}
}
}
}
}
}, label: {
Text("登录")
})
.disabled(accountInput == "" || passwdInput == "")
}
}
.tag(1)
.onAppear {
let headers: HTTPHeaders = [
"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"
]
DarockKit.Network.shared.requestJSON("https://passport.bilibili.com/x/passport-login/captcha?source=main_web", headers: headers) { respJson, isSuccess in
if isSuccess {
challenge = respJson["data"]["geetest"]["challenge"].string!
gt = respJson["data"]["geetest"]["gt"].string!
loginToken = respJson["data"]["token"].string!
}
}
}
//List {
// TextField("国际冠字码", text: $phoneCode)
// .autocorrectionDisabled()
// .textInputAutocapitalization(.never)
// TextField("手机号", text: $accountInput)
// .autocorrectionDisabled()
// .textInputAutocapitalization(.never)
// Button(action: {
// let session = ASWebAuthenticationSession(url: URL(string: "https://darock.top/geetest?gt=\(gt)&challenge=\(challenge)")!, callbackURLScheme: "captcha") { callbackURL, _ in
// if callbackURL != nil {
// if callbackURL!.absoluteString.contains("callback") {
// let str = callbackURL!.absoluteString.urlDecoded()
// validate = String(str.split(separator: "?")[1].split(separator: "&")[0])
// seccode = String(str.split(separator: "&")[1])
// }
// }
// }
// session.prefersEphemeralWebBrowserSession = true
// session.start()
// }, label: {
// Text(validate == "" ? "进行人机验证" : "人机验证已完成")
// .bold()
// })
// .disabled(validate != "")
// Button(action: {
// let headers: HTTPHeaders = [
// "Host": "passport.bilibili.com",
// "Origin": "https://www.bilibili.com",
// "Referer": "https://www.bilibili.com/",
// "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15",
// "Cookie": "browser_resolution=1580-497; FEED_LIVE_VERSION=V8; buvid4=818BA302-8EAC-0630-67AB-BB978A5797AF60982-023042618-ho21%2BqF6LZokzAShrGptM4EHZm2TE4%2FTXmfZyPpzfCnLuUmUckb8wg%3D%3D; buvid_fp=5a716236853dd1e737d439882c685594; header_theme_version=CLOSE; home_feed_column=5; _uuid=15B5A2103-BBC2-9109A-7458-6410C3CF101028B94909infoc; b_lsid=CCF71993_18991563B31; b_ut=7; i-wanna-go-back=-1; innersign=0; b_nut=1690360493; buvid3=6481EDF5-10C43-9593-251E-89210B4A1C10A193894infoc"
// ]
// AF.request("https://passport.bilibili.com/x/passport-login/web/sms/send", method: .post, parameters: BiliSmsCodePost(cid: Int(phoneCode)!, tel: Int(accountInput)!, token: loginToken, challenge: challenge, validate: validate, seccode: seccode), headers: headers).response { response in
// debugPrint(response)
// let json = try! JSON(data: response.data!)
// smsLoginToken = json["data"]["captcha_key"].string!
// }
// }, label: {
// Text("获取验证码")
// })
// .disabled(accountInput == "" || validate == "" || smsLoginToken != "")
// SecureField("验证码", text: $passwdInput)
// Section {
// Button(action: {
// AF.request("https://passport.bilibili.com/x/passport-login/web/login/sms", method: .post, parameters: BiliLoginPost(cid: Int(phoneCode)!, tel: Int(accountInput)!, code: Int(passwdInput)!, captcha_key: smsLoginToken)).response { response in
// let data = response.data
// if data != nil {
// let json = try! JSON(data: data!)
// debugPrint(json)
// if json["code"].int == 0 {
// if json["data"]["status"].int == 0 {
// debugPrint(response.response!.headers)
// let setCookie = response.response!.headers["Set-Cookie"]!
// dedeUserID = String(setCookie.split(separator: "DedeUserID=")[1].split(separator: ";")[0])
// dedeUserID__ckMd5 = String(setCookie.split(separator: "DedeUserID__ckMd5=")[1].split(separator: ";")[0])
// if setCookie.hasPrefix("SESSDATA") {
// sessdata = String(setCookie.split(separator: "SESSDATA=")[0].split(separator: ";")[0])
// } else {
// sessdata = String(setCookie.split(separator: "SESSDATA=")[1].split(separator: ";")[0])
// }
// biliJct = String(setCookie.split(separator: "bili_jct=")[1].split(separator: ";")[0])
// dismiss()
// } else if json["data"]["status"].int == 1006 {
//
// } else if json["data"]["status"].int == 1007 {
//
// }
// }
// }
// }
// }, label: {
// Text("登录")
// })
// .disabled(accountInput == "" || passwdInput == "")
// }
//}
//.tag(1)
//.onAppear {
// let headers: HTTPHeaders = [
// "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"
// ]
// DarockKit.Network.shared.requestJSON("https://passport.bilibili.com/x/passport-login/captcha?source=main_web", headers: headers) { respJson, isSuccess in
// if isSuccess {
// challenge = respJson["data"]["geetest"]["challenge"].string!
// gt = respJson["data"]["geetest"]["gt"].string!
// loginToken = respJson["data"]["token"].string!
// }
// }
//}
}
}

Expand Down
22 changes: 19 additions & 3 deletions DarockBili Watch App/PersonalCenter/UserDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct UserDetailView: View {
@State var userSign = ""
@State var followCount = -1
@State var fansCount = -1
@State var vipLabel = ""
@State var videos = [[String: String]]()
@State var viewSelector: UserDetailViewPubsType = .video
@State var articles = [[String: String]]()
Expand Down Expand Up @@ -102,7 +103,7 @@ struct UserDetailView: View {
.navigationTitle(username)
.tag(1)
}
SecondPageBase(officialType: $officialType, officialTitle: $officialTitle, userSign: $userSign)
SecondPageBase(officialType: $officialType, officialTitle: $officialTitle, userSign: $userSign, userLevel: $userLevel, vipLabel: $vipLabel)
.tag(2)
}
.tabViewStyle(.verticalPage)
Expand All @@ -113,7 +114,7 @@ struct UserDetailView: View {
.offset(y: -10)
.navigationTitle(username)
.tag(1)
SecondPageBase(officialType: $officialType, officialTitle: $officialTitle, userSign: $userSign)
SecondPageBase(officialType: $officialType, officialTitle: $officialTitle, userSign: $userSign, userLevel: $userLevel, vipLabel: $vipLabel)
.tag(2)
}
}
Expand Down Expand Up @@ -144,7 +145,7 @@ struct UserDetailView: View {
}
.onAppear {
let headers: HTTPHeaders = [
"cookie": "SESSDATA=\(sessdata);",
"cookie": "SESSDATA=\(sessdata); buvid3=\(globalBuvid3);",
"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"
]
biliWbiSign(paramEncoded: "mid=\(uid)".base64Encoded()) { signed in
Expand All @@ -166,6 +167,7 @@ struct UserDetailView: View {
officialTitle = respJson["data"]["official"]["title"].string ?? ""
userSign = respJson["data"]["sign"].string ?? "[加载失败]"
coinCount = respJson["data"]["coins"].int ?? -1
vipLabel = respJson["data"]["vip"]["label"]["text"].string ?? ""
DarockKit.Network.shared.requestJSON("https://api.bilibili.com/x/relation/stat?vmid=\(uid)", headers: headers) { respJson, isSuccess in
if isSuccess {
followCount = respJson["data"]["following"].int ?? -1
Expand Down Expand Up @@ -292,6 +294,8 @@ struct UserDetailView: View {
@Binding var officialType: Int
@Binding var officialTitle: String
@Binding var userSign: String
@Binding var userLevel: Int
@Binding var vipLabel: String
var body: some View {
ScrollView {
VStack {
Expand All @@ -318,6 +322,18 @@ struct UserDetailView: View {
Spacer()
}
.padding(.horizontal, 8)
HStack {
Image("Lv\(userLevel)Icon")
Spacer()
}
.padding(.horizontal, 8)
if vipLabel != "" {
HStack {
Image("VIPIcon")
Text(vipLabel)
Spacer()
}
}
}
}
}
Expand Down

0 comments on commit 65664fd

Please sign in to comment.