refactor(sitecode): 统一各模块分销站点编码解析为公共包
- 新增 internal/sitecode 包:FromRequest 头优先解析、FromQueryThenHeader 探测接口专用、ExtractHost/IsLocalHost 提取 Host 域名 - 替换 auth/order/listing/chat/notification/withdrawal/wallet/distribution 八模块 17 处各自内联的解析逻辑,统一优先级与 TrimSpace 行为 - 修复 notification 漏 TrimSpace、探测接口会话头压过显式 query、 GetPublicSiteInfo 把 localhost Host 当站点域名查库等不一致 - 顺手清理 auth 中无引用的 extractHost 死代码 - gofmt 修复 withdrawal/presenter、chat/file/payment 测试四个历史遗留格式问题
This commit is contained in:
@@ -2,10 +2,10 @@ package auth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"hfb_sys/backend/internal/sitecode"
|
||||
"hfb_sys/backend/pkg/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -86,20 +86,18 @@ func (h *Handler) SendSMS(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
siteCode := strings.TrimSpace(firstNonEmpty(
|
||||
c.GetHeader("X-Distribution-Site-Code"),
|
||||
c.Query("distribution_site_code"),
|
||||
c.Query("site_code"),
|
||||
req.SiteCode,
|
||||
))
|
||||
siteCode := sitecode.FromRequest(c)
|
||||
if siteCode == "" {
|
||||
siteCode = strings.TrimSpace(req.SiteCode)
|
||||
}
|
||||
domain := strings.TrimSpace(firstNonEmpty(
|
||||
c.GetHeader("X-Distribution-Domain"),
|
||||
c.Query("distribution_domain"),
|
||||
c.Query("domain"),
|
||||
))
|
||||
if siteCode == "" && domain == "" {
|
||||
host := extractHost(c.Request.Host)
|
||||
if host != "" && host != "localhost" && host != "127.0.0.1" && host != "::1" {
|
||||
host := sitecode.ExtractHost(c.Request.Host)
|
||||
if host != "" && !sitecode.IsLocalHost(host) {
|
||||
domain = host
|
||||
}
|
||||
}
|
||||
@@ -120,17 +118,6 @@ func firstNonEmpty(items ...string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func extractHost(rawHost string) string {
|
||||
rawHost = strings.TrimSpace(rawHost)
|
||||
if rawHost == "" {
|
||||
return ""
|
||||
}
|
||||
if host, _, err := net.SplitHostPort(rawHost); err == nil {
|
||||
return strings.Trim(host, "[]")
|
||||
}
|
||||
return strings.Trim(rawHost, "[]")
|
||||
}
|
||||
|
||||
// Login 短信验证码登录
|
||||
// @Summary 短信验证码登录
|
||||
// @Description 使用手机号和验证码登录
|
||||
|
||||
Reference in New Issue
Block a user