This commit is contained in:
Mrx
2026-02-28 12:45:25 +08:00
parent ed35631900
commit 6a627dc474
3 changed files with 28 additions and 7 deletions

View File

@@ -1,6 +1,9 @@
package captcha
import (
"os"
"strings"
"tyc-server/common/xerr"
captcha20230305 "github.com/alibabacloud-go/captcha-20230305/client"
@@ -18,11 +21,24 @@ type Config struct {
SceneID string
}
// isWeChatUserAgent 判断 User-Agent 是否为微信内置浏览器(含 MicroMessenger
func isWeChatUserAgent(ua string) bool {
return strings.Contains(ua, "MicroMessenger")
}
// VerifyWithUserAgent 根据 User-Agent 与 captchaVerifyParam 校验。微信请求直接通过。
func VerifyWithUserAgent(cfg Config, captchaVerifyParam string, userAgent string) error {
if isWeChatUserAgent(userAgent) {
return nil
}
return Verify(cfg, captchaVerifyParam)
}
// Verify 校验前端传入的 captchaVerifyParam。异常时视为通过以保证业务可用。
func Verify(cfg Config, captchaVerifyParam string) error {
// if os.Getenv("ENV") == "development" {
// return nil
// }
if os.Getenv("ENV") == "development" {
return nil
}
if captchaVerifyParam == "" {
return errors.Wrapf(xerr.NewErrMsg("图形验证码校验失败"), "empty captchaVerifyParam")
}