lx.go 2.4 KB

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