75 lines
2.1 KiB
Go
75 lines
2.1 KiB
Go
package captcha
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"likedream-goframe/internal/application/httpclient"
|
|
"likedream-goframe/internal/common/cst"
|
|
"likedream-goframe/internal/utils"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
"github.com/samber/oops"
|
|
"github.com/tidwall/gjson"
|
|
)
|
|
|
|
func ApiSemiOCRVerification(bytes []byte, shape1, shape2 int64) string {
|
|
data := Bytes2Base64(bytes)
|
|
ctx := gctx.GetInitCtx()
|
|
baseUrl := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaBaseUrl).String() + "/semiOcr"
|
|
client := httpclient.Cpdaily.Clone(ctx)
|
|
client.SetDoNotParseResponse(false)
|
|
post, err := client.R().SetBody(map[string]any{
|
|
"base64": data,
|
|
"shape1": shape1,
|
|
"shape2": shape2,
|
|
}).Post(baseUrl)
|
|
utils.OkOrPanic(err, func(err error) error {
|
|
return oops.
|
|
With("SemiOCRVerification", baseUrl).
|
|
WithContext(ctx).
|
|
Wrap(err)
|
|
})
|
|
result := post.String()
|
|
return gjson.Get(result, "data").String()
|
|
}
|
|
|
|
func ApiAutoOCRVerification(bytes []byte) string {
|
|
data := Bytes2Base64(bytes)
|
|
ctx := gctx.GetInitCtx()
|
|
baseUrl := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaBaseUrl).String() + "/ocr"
|
|
client := httpclient.Cpdaily.Clone(ctx)
|
|
client.SetDoNotParseResponse(false)
|
|
post, err := client.R().SetBody(map[string]any{
|
|
"base64": data,
|
|
}).Post(baseUrl)
|
|
utils.OkOrPanic(err, func(err error) error {
|
|
return oops.
|
|
With("AutoOCRVerification", baseUrl).
|
|
WithContext(ctx).
|
|
Wrap(err)
|
|
})
|
|
result := post.String()
|
|
return gjson.Get(result, "data").String()
|
|
}
|
|
|
|
func ApiAutoCalcVerification(b64 string) string {
|
|
ctx := gctx.GetInitCtx()
|
|
baseUrl := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaBaseUrl).String() + "/calc"
|
|
client := httpclient.Cpdaily.Clone(ctx)
|
|
client.SetDoNotParseResponse(false)
|
|
post, err := client.R().SetBody(map[string]any{
|
|
"base64": b64,
|
|
}).Post(baseUrl)
|
|
utils.OkOrPanic(err, func(err error) error {
|
|
return oops.
|
|
With("AutoOCRVerification", baseUrl).
|
|
WithContext(ctx).
|
|
Wrap(err)
|
|
})
|
|
result := post.String()
|
|
return gjson.Get(result, "data").String()
|
|
}
|
|
func Bytes2Base64(data []byte) string {
|
|
return base64.StdEncoding.EncodeToString(data)
|
|
}
|