capEndpointLogic.go 973 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Code scaffolded by goctl. Safe to edit.
  2. // goctl 1.10.1
  3. package pub
  4. import (
  5. "context"
  6. "perms-system-server/internal/svc"
  7. "perms-system-server/internal/types"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type CapEndpointLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewCapEndpointLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CapEndpointLogic {
  16. return &CapEndpointLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. }
  21. }
  22. // CapEndpoint 返回 cap.js 服务的完整验证端点 URL。
  23. // 未配置或 Enable != 1 时返回空 Data,前端据此降级为图片验证码。
  24. func (l *CapEndpointLogic) CapEndpoint() (*types.CapEndpointResp, error) {
  25. cfg := l.svcCtx.Config.Capjs
  26. if cfg.Enable != 1 || cfg.EndpointURL == "" || cfg.Key == "" {
  27. return &types.CapEndpointResp{Data: ""}, nil
  28. }
  29. url := cfg.EndpointURL + "/" + cfg.Key + "/"
  30. return &types.CapEndpointResp{Data: url}, nil
  31. }