Skip to content

Commit

Permalink
add: GetIdentifierAndCookies
Browse files Browse the repository at this point in the history
  • Loading branch information
SchwarzSail committed Sep 24, 2024
1 parent e7c2a2c commit 59c09fa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ For more detail, plz visit API docs.
- [X] Automatic code identification
- [X] Set any apis but not implement
- [X] Empty Rooms
- [ ] Using Courrency
- [X] Using Currency
- [ ] Complete all apis
- [ ] Benchmark test
- [ ] Bug check & fix
Expand Down
6 changes: 6 additions & 0 deletions jwch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func login() error {
return nil
}

func Test_GetIdentifierAndCookies(t *testing.T) {
Identifier, cookies := stu.GetIdentifierAndCookies()
fmt.Println(Identifier)
fmt.Println(cookies)
}

func Test_Login(t *testing.T) {
err := login()
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package jwch

import (
"encoding/json"
"net/http"
"regexp"

"github.com/west2-online/jwch/constants"
Expand Down Expand Up @@ -128,6 +129,15 @@ func (s *Student) Login() error {
return nil
}

// 方面服务端进行测试设置的接口
func (s *Student) GetIdentifierAndCookies() (string, []*http.Cookie) {
err := s.CheckSession()
if err != nil {
s.Login()
}
return s.Identifier, s.client.Cookies
}

// CheckSession returns not nil if SessionExpired or AccountConflict
func (s *Student) CheckSession() error {
// 逻辑: 如果session没用,我们会返回一个302定向到https://jwcjwxt2.fzu.edu.cn:82/error.asp?id=300,但是我们禁用了重定向,意味着这里HTTP会抛出异常
Expand Down

0 comments on commit 59c09fa

Please sign in to comment.