This commit is contained in:
2026-03-02 16:51:15 +08:00
3 changed files with 28 additions and 7 deletions

View File

@@ -35,15 +35,18 @@ func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLo
}
}
// UserAgentContextKey 用于从 context 读取 User-Agent如判断是否微信
const UserAgentContextKey = "user_agent"
func (l *SendSmsLogic) SendSms(req *types.SendSmsReq) error {
// 图形验证码校验(开发环境可跳过)
userAgent, _ := l.ctx.Value(UserAgentContextKey).(string)
cfg := l.svcCtx.Config.Captcha
if err := captcha.Verify(captcha.Config{
if err := captcha.VerifyWithUserAgent(captcha.Config{
AccessKeyID: cfg.AccessKeyID,
AccessKeySecret: cfg.AccessKeySecret,
EndpointURL: cfg.EndpointURL,
SceneID: cfg.SceneID,
}, req.CaptchaVerifyParam); err != nil {
}, req.CaptchaVerifyParam, userAgent); err != nil {
return err
}