lx.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package ocr
  2. import (
  3. "encoding/base64"
  4. "git.listensoft.net/tool/jspkit/logger"
  5. "net/http"
  6. "os"
  7. "time"
  8. "git.listensoft.net/tool/jspkit/common"
  9. "git.listensoft.net/tool/jspkit/common/lxhttp"
  10. "github.com/go-kratos/kratos/v2/log"
  11. "github.com/tidwall/gjson"
  12. )
  13. func GetCaptchaCodeBeijing(imgPath string) string {
  14. var client = http.Client{}
  15. client.Timeout = time.Duration(time.Second * 15)
  16. tyURL := "https://public.listensoft.net/api/getCaptchaApi"
  17. res, err := common.PostFile(tyURL, map[string]string{"file": imgPath}, map[string]string{"type": "1002"})
  18. if err != nil {
  19. logger.Info(err.Error())
  20. return ""
  21. }
  22. logger.Info("北京图片验证码:" + string(res))
  23. return string(res)
  24. }
  25. func GetCaptchaCodeHebei(imgPath string) string {
  26. var client = http.Client{}
  27. client.Timeout = time.Duration(time.Second * 15)
  28. tyURL := "https://public.listensoft.net/api/getCaptchaApi"
  29. res, err := common.PostFile(tyURL, map[string]string{"file": imgPath}, map[string]string{"type": "1001"})
  30. if err != nil {
  31. logger.Info(err.Error())
  32. return ""
  33. }
  34. logger.Info("河北图片验证码:" + string(res))
  35. return string(res)
  36. }
  37. func GetX(captchaPathJpg, captchaPathPng string) float64 {
  38. u := "http://47.104.147.97:5000/getX"
  39. files := map[string]string{
  40. "target": captchaPathJpg,
  41. "template": captchaPathPng,
  42. }
  43. bys, err := common.PostFile(u, files, map[string]string{})
  44. if err != nil {
  45. return 0
  46. }
  47. if gjson.Get(string(bys), "error").Int() != 0 {
  48. return 0
  49. }
  50. X := gjson.Get(string(bys), "msg").Float()
  51. return X
  52. }
  53. func GetXPython(captchaPathJpg, captchaPathPng string) float64 {
  54. var encodedJpg, encodedPng string
  55. {
  56. imgData, err := os.ReadFile(captchaPathJpg)
  57. if err != nil {
  58. log.Fatal(err)
  59. }
  60. // 将图片数据编码为 Base64
  61. encodedJpg = base64.StdEncoding.EncodeToString(imgData)
  62. imgData, err = os.ReadFile(captchaPathPng)
  63. if err != nil {
  64. log.Fatal(err)
  65. }
  66. // 将图片数据编码为 Base64
  67. encodedPng = base64.StdEncoding.EncodeToString(imgData)
  68. }
  69. u := "http://61.156.89.11:1234/api/capthk"
  70. files := map[string]string{
  71. "canvasSrc": encodedJpg,
  72. "blockSrc": encodedPng,
  73. }
  74. h := map[string]string{
  75. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
  76. "content-type": "application/json",
  77. "x-token": "ab9296b031462c0cfc9d36e9a5d351af",
  78. }
  79. bys, err := lxhttp.POSTJson(http.DefaultClient, u, files, h)
  80. if err != nil {
  81. return 0
  82. }
  83. return gjson.GetBytes(bys, "distance").Float()
  84. }