package client import ( "log/slog" "net/http" "strings" "schedule_converter/config" ) 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" func GetHeaders() http.Header { return http.Header{ "User-Agent": []string{defaultUserAgent}, "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() headers.Set("Content-Type", contentType) return headers } func GetInitialCookiesWithClient(httpClient *http.Client) error { slog.Info("访问登录页面获取初始Cookie") req, err := http.NewRequest("GET", config.Get().BaseURL+"/loginNOCAS", nil) if err != nil { return err } req.Header = GetHeaders() resp, err := httpClient.Do(req) if err != nil { return err } defer resp.Body.Close() slog.Info("登录页面访问完成", "status_code", resp.StatusCode) return nil } func CheckLoginSuccess(body string) bool { return strings.Contains(body, "本科教学管理服务系统") } func IsCaptchaError(body string) bool { return strings.Contains(body, "验证码") }