f
This commit is contained in:
@@ -23,8 +23,25 @@ func SendSmsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
result.ParamValidateErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
// 获取客户端真实 IP
|
||||
clientIP := getClientIP(r)
|
||||
l := auth.NewSendSmsLogic(r.Context(), svcCtx)
|
||||
err := l.SendSms(&req)
|
||||
err := l.SendSms(&req, clientIP)
|
||||
result.HttpResult(r, w, nil, err)
|
||||
}
|
||||
}
|
||||
|
||||
// getClientIP 获取客户端真实 IP
|
||||
func getClientIP(r *http.Request) string {
|
||||
// 优先从 X-Forwarded-For 获取
|
||||
if xff := r.Header.Get("X-Forwarded-For"); xff != "" {
|
||||
// X-Forwarded-For 可能包含多个 IP,取第一个
|
||||
return xff
|
||||
}
|
||||
// 其次从 X-Real-IP 获取
|
||||
if xri := r.Header.Get("X-Real-IP"); xri != "" {
|
||||
return xri
|
||||
}
|
||||
// 最后使用 RemoteAddr
|
||||
return r.RemoteAddr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user