Files
schedule_converter/captcha/recognize.go

55 lines
1.0 KiB
Go
Raw Normal View History

2026-03-13 20:43:44 +08:00
package captcha
import (
"fmt"
"io"
"log/slog"
2026-03-13 20:43:44 +08:00
"net/http"
"schedule_converter/client"
"schedule_converter/config"
2026-03-13 20:43:44 +08:00
)
func SaveCaptchaImage(httpClient *http.Client) ([]byte, error) {
req, err := http.NewRequest("GET", config.Get().BaseURL+"/captchaImage", nil)
2026-03-13 20:43:44 +08:00
if err != nil {
return nil, err
}
req.Header = client.GetHeaders()
resp, err := httpClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("获取验证码失败, 状态码: %d", resp.StatusCode)
}
2026-03-13 20:43:44 +08:00
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return body, nil
}
func GetAndRecognize(httpClient *http.Client) (string, error) {
_, err := SaveCaptchaImage(httpClient)
2026-03-13 20:43:44 +08:00
if err != nil {
return "", err
}
captchaCode, err := Recognize("captcha.png")
if err != nil {
return "", err
}
slog.Debug("验证码识别完成", "result", captchaCode)
2026-03-13 20:43:44 +08:00
return captchaCode, nil
}
func Recognize(imagePath string) (string, error) {
return "....", nil
}