magua.go 703 B

12345678910111213141516171819202122232425262728293031323334
  1. package ocr
  2. import (
  3. "io"
  4. "net/http"
  5. "net/url"
  6. "strings"
  7. "time"
  8. )
  9. func GetCaptchaCodeF(imgPath string, comID uint, len int) string {
  10. var client = http.Client{}
  11. client.Timeout = time.Duration(time.Second * 10)
  12. tyURL := "http://111.231.60.74:5088/check"
  13. bstr, err := base64Img(imgPath)
  14. if err != nil {
  15. return ""
  16. }
  17. params := "recognize_img=" + url.QueryEscape(bstr)
  18. req, err := http.NewRequest("POST", tyURL, strings.NewReader(params))
  19. if err != nil {
  20. return ""
  21. }
  22. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  23. resp, err := client.Do(req)
  24. if err != nil {
  25. return ""
  26. }
  27. body, err := io.ReadAll(resp.Body)
  28. if err != nil {
  29. return ""
  30. }
  31. return string(body)
  32. }