2026-03-13 20:43:44 +08:00
|
|
|
package client
|
|
|
|
|
|
|
|
|
|
import (
|
2026-03-16 13:40:53 +08:00
|
|
|
"log/slog"
|
2026-03-13 20:43:44 +08:00
|
|
|
"net/http"
|
|
|
|
|
"strings"
|
|
|
|
|
|
2026-03-16 13:40:53 +08:00
|
|
|
"schedule_converter/config"
|
2026-03-13 20:43:44 +08:00
|
|
|
)
|
|
|
|
|
|
2026-06-09 23:08:03 +08:00
|
|
|
const defaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
2026-03-13 20:43:44 +08:00
|
|
|
|
|
|
|
|
func GetHeaders() http.Header {
|
|
|
|
|
return http.Header{
|
2026-06-09 23:08:03 +08:00
|
|
|
"User-Agent": []string{defaultUserAgent},
|
2026-03-13 20:43:44 +08:00
|
|
|
"Accept": []string{"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"},
|
|
|
|
|
"Accept-Language": []string{"zh-CN,zh;q=0.9,en;q=0.8"},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetHeadersWithContentType(contentType string) http.Header {
|
|
|
|
|
headers := GetHeaders()
|
2026-03-16 13:40:53 +08:00
|
|
|
headers.Set("Content-Type", contentType)
|
2026-03-13 20:43:44 +08:00
|
|
|
return headers
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-16 13:40:53 +08:00
|
|
|
func GetInitialCookiesWithClient(httpClient *http.Client) error {
|
|
|
|
|
slog.Info("访问登录页面获取初始Cookie")
|
|
|
|
|
|
2026-06-09 23:08:03 +08:00
|
|
|
req, err := http.NewRequest("GET", config.Get().BaseURL+"/loginNOCAS", nil)
|
2026-03-13 20:43:44 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
req.Header = GetHeaders()
|
|
|
|
|
|
2026-03-16 13:40:53 +08:00
|
|
|
resp, err := httpClient.Do(req)
|
2026-03-13 20:43:44 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
2026-03-16 13:40:53 +08:00
|
|
|
slog.Info("登录页面访问完成", "status_code", resp.StatusCode)
|
2026-03-13 20:43:44 +08:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CheckLoginSuccess(body string) bool {
|
|
|
|
|
return strings.Contains(body, "本科教学管理服务系统")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func IsCaptchaError(body string) bool {
|
|
|
|
|
return strings.Contains(body, "验证码")
|
2026-06-17 14:48:27 +08:00
|
|
|
}
|