diff --git a/config.toml b/config.toml index e8f8877..f57e012 100644 --- a/config.toml +++ b/config.toml @@ -38,6 +38,7 @@ mode = "dev" [captcha] #baseUrl = "http://captcha-resolver.out" baseUrl = "http://likedream-go-captcha:8890" +apiKey = "baca122..." [redis] url = "redis://:jhkdjhkjdhsIUTYURTU_pEGmFP@database.out:56379" diff --git a/internal/application/captcha/captcha_func.go b/internal/application/captcha/captcha_func.go index 92168a7..b7c9c3b 100644 --- a/internal/application/captcha/captcha_func.go +++ b/internal/application/captcha/captcha_func.go @@ -16,13 +16,14 @@ func ApiSemiOCRVerification(bytes []byte, shape1, shape2 int64) string { data := Bytes2Base64(bytes) ctx := gctx.GetInitCtx() baseUrl := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaBaseUrl).String() + "/semiOcr" + apiKey := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaApiKey).String() client := httpclient.Cpdaily.Clone(ctx) client.SetDoNotParseResponse(false) post, err := client.R().SetBody(map[string]any{ "base64": data, "shape1": shape1, "shape2": shape2, - }).Post(baseUrl) + }).SetHeader("X-Api-Key", apiKey).Post(baseUrl) utils.OkOrPanic(err, func(err error) error { return oops. With("SemiOCRVerification", baseUrl). @@ -37,11 +38,12 @@ func ApiAutoOCRVerification(bytes []byte) string { data := Bytes2Base64(bytes) ctx := gctx.GetInitCtx() baseUrl := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaBaseUrl).String() + "/ocr" + apiKey := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaApiKey).String() client := httpclient.Cpdaily.Clone(ctx) client.SetDoNotParseResponse(false) post, err := client.R().SetBody(map[string]any{ "base64": data, - }).Post(baseUrl) + }).SetHeader("X-Api-Key", apiKey).Post(baseUrl) utils.OkOrPanic(err, func(err error) error { return oops. With("AutoOCRVerification", baseUrl). @@ -55,11 +57,12 @@ func ApiAutoOCRVerification(bytes []byte) string { func ApiAutoCalcVerification(b64 string) string { ctx := gctx.GetInitCtx() baseUrl := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaBaseUrl).String() + "/calc" + apiKey := g.Config().MustGetWithEnv(ctx, cst.ConfigCaptchaApiKey).String() client := httpclient.Cpdaily.Clone(ctx) client.SetDoNotParseResponse(false) post, err := client.R().SetBody(map[string]any{ "base64": b64, - }).Post(baseUrl) + }).SetHeader("X-Api-Key", apiKey).Post(baseUrl) utils.OkOrPanic(err, func(err error) error { return oops. With("AutoOCRVerification", baseUrl). diff --git a/internal/common/cst/config.go b/internal/common/cst/config.go index c36c4a4..5d8cf2d 100644 --- a/internal/common/cst/config.go +++ b/internal/common/cst/config.go @@ -15,6 +15,7 @@ const ( ConfigAuthorizationKey = "server.authorization" ConfigJwtKey = "server.jwt" ConfigCaptchaBaseUrl = "captcha.baseUrl" + ConfigCaptchaApiKey = "captcha.apiKey" ConfigS3AccessKey = "s3.accessKey" ConfigS3SecretKey = "s3.secretKey" ConfigS3BaseUrl = "s3.baseUrl"