|
@@ -44,7 +44,19 @@ struct Login: Encodable {
|
|
|
|
|
|
struct UserInfo: Encodable {
|
|
struct UserInfo: Encodable {
|
|
var name: String
|
|
var name: String
|
|
- var o: String
|
|
|
|
|
|
+ var oid: String
|
|
|
|
+ var id: String
|
|
|
|
+ var xydLink: String
|
|
|
|
+ var serviceLink: String
|
|
|
|
+ var studyLink: String
|
|
|
|
+ init() {
|
|
|
|
+ name = "-"
|
|
|
|
+ oid = "-"
|
|
|
|
+ id = "-"
|
|
|
|
+ xydLink = "-"
|
|
|
|
+ serviceLink = "-"
|
|
|
|
+ studyLink = "-"
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
class LoginHandler {
|
|
class LoginHandler {
|
|
@@ -133,16 +145,70 @@ func doLogin(user: String, password: String, action: @escaping (_: Int) -> Void)
|
|
|
|
|
|
struct DecodableType: Decodable { let url: String }
|
|
struct DecodableType: Decodable { let url: String }
|
|
|
|
|
|
-func getUserInfo(action: @escaping (_: UserInfo) -> Void) {
|
|
|
|
|
|
+var Count: Int = 0
|
|
|
|
+
|
|
|
|
+func addCompleted(userInfo: UserInfo, action: @escaping (_: UserInfo) -> Void) {
|
|
|
|
+ Count += 1
|
|
|
|
+ if Count == 3 {
|
|
|
|
+ action(userInfo)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+extension String {
|
|
|
|
+ func replace(regex: String, with: String, options: NSRegularExpression.Options) -> String {
|
|
|
|
+ do {
|
|
|
|
+ let RE = try NSRegularExpression(pattern: regex, options: options)
|
|
|
|
+ let modified = RE.stringByReplacingMatches(in: self, range: NSRange(location: 0, length: count), withTemplate: with)
|
|
|
|
+ return self
|
|
|
|
+ } catch {
|
|
|
|
+ return "ERR"
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func replace(regex: String, with: String) -> String {
|
|
|
|
+ do {
|
|
|
|
+ let RE = try NSRegularExpression(pattern: regex)
|
|
|
|
+ let modified = RE.stringByReplacingMatches(in: self, range: NSRange(location: 0, length: count), withTemplate: with)
|
|
|
|
+ return self
|
|
|
|
+ } catch {
|
|
|
|
+ return "ERR"
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+struct TableParam: Encodable {
|
|
|
|
+ var oid: String
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func getUserInfo(userInfoIn: UserInfo, action: @escaping (_: UserInfo) -> Void) {
|
|
|
|
+ var userInfo: UserInfo = userInfoIn
|
|
FetchHandler().fetchAny(url: "bxn-portal/portal/osforstudent/index") { res in
|
|
FetchHandler().fetchAny(url: "bxn-portal/portal/osforstudent/index") { res in
|
|
- var userInfo: UserInfo = .init(name: "", o: "")
|
|
|
|
- if let name = res.firstMatch(of: /userFullName" value="(.*?)"/) {
|
|
|
|
- userInfo.name = "\(name.1)"
|
|
|
|
|
|
+ if let mat = res.firstMatch(of: /userFullName" value="(.*?)"/) {
|
|
|
|
+ userInfo.name = "\(mat.1)"
|
|
}
|
|
}
|
|
- if let name = res.firstMatch(of: /userId" value="(.*?)"/) {
|
|
|
|
- userInfo.o = "\(name.1)"
|
|
|
|
|
|
+ if let mat = res.firstMatch(of: /userId" value="(.*?)"/) {
|
|
|
|
+ userInfo.oid = "\(mat.1)"
|
|
}
|
|
}
|
|
- action(userInfo)
|
|
|
|
|
|
+ if let mat = res.firstMatch(of: /'https:\/\/service.*?'/) {
|
|
|
|
+ userInfo.serviceLink = "\(mat.output.split(separator: "'")[0])"
|
|
|
|
+ userInfo.studyLink = mat.output.split(separator: "'")[0] + "%2Ffe-pc%2Fb%2Ffe_leco_student%2Fportal%2F%3Fsystem_partition_gId%3D3"
|
|
|
|
+ }
|
|
|
|
+ print(userInfo)
|
|
|
|
+ let tableParam: TableParam = .init(oid: userInfo.oid)
|
|
|
|
+ let header: HTTPHeaders = [
|
|
|
|
+ "user": userInfo.id,
|
|
|
|
+ ]
|
|
|
|
+ AF.request("https://debug.sdsz.icu/getWeek", method: .post, parameters: tableParam, encoder: JSONParameterEncoder.default, headers: header).responseString { res in
|
|
|
|
+ FetchHandler().fetchAny(url: "bxn-timetable/timetable/monitor/homepage/data/student?studentId=\(userInfo.oid)&dateScope=\(res.value ?? "")&_=0") { res in
|
|
|
|
+ print(res)
|
|
|
|
+ addCompleted(userInfo: userInfo, action: action)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ addCompleted(userInfo: userInfo, action: action)
|
|
|
|
+ }
|
|
|
|
+ FetchHandler().fetchAny(url: "bxn-library/library/jumpExamreport?jumpUrl=http://36.112.23.77/analysis/auto/%23/autoLogin") { res in
|
|
|
|
+ userInfo.xydLink = res
|
|
|
|
+ addCompleted(userInfo: userInfo, action: action)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -187,7 +253,8 @@ struct loginView: View {
|
|
btnText = "登录失败"
|
|
btnText = "登录失败"
|
|
btnColor = .red
|
|
btnColor = .red
|
|
} else {
|
|
} else {
|
|
- getUserInfo { res in
|
|
|
|
|
|
+ userInfo.id = username
|
|
|
|
+ getUserInfo(userInfoIn: userInfo) { res in
|
|
userInfo = res
|
|
userInfo = res
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -228,12 +295,17 @@ struct accountView: View {
|
|
HStack {
|
|
HStack {
|
|
Text("姓名")
|
|
Text("姓名")
|
|
Spacer()
|
|
Spacer()
|
|
- Text(userInfo.name)
|
|
|
|
|
|
+ Text(userInfo.name).foregroundColor(.gray)
|
|
}
|
|
}
|
|
HStack {
|
|
HStack {
|
|
Text("内部 ID")
|
|
Text("内部 ID")
|
|
Spacer()
|
|
Spacer()
|
|
- Text(userInfo.o)
|
|
|
|
|
|
+ Text(userInfo.oid).foregroundColor(.gray)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Section {
|
|
|
|
+ NavigationLink(destination: aboutView()) {
|
|
|
|
+ Text("关于")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Section {
|
|
Section {
|
|
@@ -253,9 +325,24 @@ struct accountView: View {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+struct aboutView: View {
|
|
|
|
+ var body: some View {
|
|
|
|
+ List {
|
|
|
|
+ Section(footer: Text("实验中学 74 桌是一款面向北师大附属实验中学学生的 App,提供查分及数字校园基础服务。")) {
|
|
|
|
+ Text("实验中学 74 桌")
|
|
|
|
+ HStack {
|
|
|
|
+ Text("开发者")
|
|
|
|
+ Spacer()
|
|
|
|
+ Text("74 开发组").foregroundColor(.gray)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }.navigationBarTitle("关于")
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
struct accountView_Previews: PreviewProvider {
|
|
struct accountView_Previews: PreviewProvider {
|
|
- @State static var isLoggedIn = 0
|
|
|
|
- @State static var userInfo: UserInfo = .init(name: "", o: "")
|
|
|
|
|
|
+ @State static var isLoggedIn = 1
|
|
|
|
+ @State static var userInfo: UserInfo = .init()
|
|
static var previews: some View {
|
|
static var previews: some View {
|
|
loginView(isLoggedIn: $isLoggedIn, userInfo: $userInfo)
|
|
loginView(isLoggedIn: $isLoggedIn, userInfo: $userInfo)
|
|
}
|
|
}
|