fix(prod): 后端生产级 A 类硬伤全清(7 项:授权/崩溃点/全表扫/限流/鉴权/限额)
部署前生产级审计(可靠性/数据层/安全三路)后,清掉 7 处代码级硬伤: A1 后台定时器 goroutine 无 panic recover → 单个 DB panic 崩整个 gateway。加 safeGo/ safeCall,包住订阅/掉单补偿/微信推送/探针 goroutine,单轮 tick 再兜一层。 A2 提示词控制面(建/激活/停用,热广播全服务)只 RequireAuth → 任意登录用户改全局提示词。 三写端点+列表挂 RequireAdmin。 A3 HITL 审批端点无角色门 → viewer 可放行烧钱执行。加 RequireTenantRole(member)。 A4 审计/护栏列表 limit 无校验,limit=-1 让 gorm 取消 LIMIT 全表扫。加 clampLimit/ clampOffset,AdminTasks/AdminSpaces 补上界。 A5 限流 Redis 一挂就完全放行(fail-open)。加进程内固定窗口兜底(fail-safe) + 登录/注册 按 IP 专用严限流(10/min)。 A6 公开 by-id 端点(stream/exec/report导出/kb导入流)无鉴权无租户过滤。加 AuthFromHeaderOrQuery(从 ?token= 取 JWT) + task/report 按 owner 归属校验;桌面端 5 处 EventSource/下载 URL 经 tokenQuery 附 JWT。 A7 文件上传无大小上限(整文件进内存 OOM 面) → 50MB 闸(KB_MAX_UPLOAD_BYTES)+ LimitReader; http.Server 加 ReadHeaderTimeout/ReadTimeout/MaxHeaderBytes(不设 WriteTimeout 保 SSE)。 带单测:clampLimit/safeCall/procLimiter/AuthFromHeaderOrQuery/TaskOwner。 build+vet+全量 test 绿;desktop tsc 绿。B(迁移工具/实时探针/出网韧性/登录锁定/leader选举) 与 C(TLS/PG HA/K8s/备份自动化/可观测)分期后做,参照 production_readiness.md。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -18,19 +18,32 @@ import (
|
||||
"github.com/sundynix/sundynix-shared/secrets"
|
||||
)
|
||||
|
||||
// clampLimit 解析 ?limit= 并夹到 [1, max],非法/≤0 用 def。
|
||||
// 必须夹:负数(如 limit=-1)会让 gorm `Limit(-1)` **取消 LIMIT 子句**,对审计/护栏这类
|
||||
// 最易膨胀的表变成全表扫 + 深翻分页。
|
||||
func clampLimit(v string, def, max int) int {
|
||||
n, err := strconv.Atoi(v)
|
||||
if err != nil || n <= 0 {
|
||||
return def
|
||||
}
|
||||
if n > max {
|
||||
return max
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// clampOffset 解析 ?offset=,非法/负数归 0。
|
||||
func clampOffset(v string) int {
|
||||
if n, err := strconv.Atoi(v); err == nil && n > 0 {
|
||||
return n
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// AuditList: GET /api/v1/admin/audit?limit=&offset= —— 敏感操作审计流(倒序,供运维溯源)。
|
||||
func (h *Handler) AuditList(c *gin.Context) {
|
||||
limit, offset := 50, 0
|
||||
if v := c.Query("limit"); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil {
|
||||
limit = n
|
||||
}
|
||||
}
|
||||
if v := c.Query("offset"); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil {
|
||||
offset = n
|
||||
}
|
||||
}
|
||||
limit := clampLimit(c.Query("limit"), 50, 200)
|
||||
offset := clampOffset(c.Query("offset"))
|
||||
// 筛选下沉到 SQL:此前是前端在当前页 50 条里过滤,翻页外的记录搜不到,
|
||||
// 对审计来说等于给出错误结论。
|
||||
f := store.AuditFilter{
|
||||
@@ -55,17 +68,8 @@ func (h *Handler) AuditList(c *gin.Context) {
|
||||
|
||||
// GuardrailEvents: GET /api/v1/admin/guardrail-events?limit=&offset= —— 护栏命中安全事件流(倒序)。
|
||||
func (h *Handler) GuardrailEvents(c *gin.Context) {
|
||||
limit, offset := 50, 0
|
||||
if v := c.Query("limit"); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil {
|
||||
limit = n
|
||||
}
|
||||
}
|
||||
if v := c.Query("offset"); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil {
|
||||
offset = n
|
||||
}
|
||||
}
|
||||
limit := clampLimit(c.Query("limit"), 50, 200)
|
||||
offset := clampOffset(c.Query("offset"))
|
||||
rows, err := h.db.ListGuardrailEvents(c.Request.Context(), limit, offset)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadGateway, gin.H{"error": err.Error()})
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -373,12 +372,7 @@ func (h *Handler) AdminReconcile(c *gin.Context) {
|
||||
// 跨租户看所有任务(状态/租户/提交人/评测),含 HITL 待审批(status=waiting)。返回列表 + 状态计数。
|
||||
func (h *Handler) AdminTasks(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
limit := 50
|
||||
if v := c.Query("limit"); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil && n > 0 {
|
||||
limit = n
|
||||
}
|
||||
}
|
||||
limit := clampLimit(c.Query("limit"), 50, 200)
|
||||
rows := h.db.AllTasks(ctx, c.Query("status"), c.Query("tenant"), limit)
|
||||
c.JSON(http.StatusOK, gin.H{"tasks": rows, "counts": h.db.TaskStatusCounts(ctx)})
|
||||
}
|
||||
@@ -404,12 +398,7 @@ func (h *Handler) AdminTaskDetail(c *gin.Context) {
|
||||
|
||||
// AdminSpaces: GET /api/v1/admin/spaces?limit= —— 全平台空间观测(跨租户)。
|
||||
func (h *Handler) AdminSpaces(c *gin.Context) {
|
||||
limit := 200
|
||||
if v := c.Query("limit"); v != "" {
|
||||
if n, err := strconv.Atoi(v); err == nil && n > 0 {
|
||||
limit = n
|
||||
}
|
||||
}
|
||||
limit := clampLimit(c.Query("limit"), 200, 500)
|
||||
c.JSON(http.StatusOK, gin.H{"spaces": h.db.AllSpaces(c.Request.Context(), limit)})
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package handler
|
||||
|
||||
import "testing"
|
||||
|
||||
// A4:limit 必须夹紧——负数(limit=-1 会让 gorm 取消 LIMIT 全表扫)、0、超大都要归位。
|
||||
func TestClampLimit(t *testing.T) {
|
||||
cases := []struct {
|
||||
v string
|
||||
def, max int
|
||||
want int
|
||||
}{
|
||||
{"", 50, 200, 50}, // 空 → 默认
|
||||
{"-1", 50, 200, 50}, // 负数 → 默认(关键:堵住全表扫)
|
||||
{"0", 50, 200, 50}, // 0 → 默认
|
||||
{"abc", 50, 200, 50}, // 非法 → 默认
|
||||
{"100", 50, 200, 100}, // 合法 → 原值
|
||||
{"999", 50, 200, 200}, // 超上界 → 夹到 max
|
||||
}
|
||||
for _, tc := range cases {
|
||||
if got := clampLimit(tc.v, tc.def, tc.max); got != tc.want {
|
||||
t.Fatalf("clampLimit(%q,%d,%d)=%d want %d", tc.v, tc.def, tc.max, got, tc.want)
|
||||
}
|
||||
}
|
||||
if clampOffset("-5") != 0 || clampOffset("abc") != 0 || clampOffset("7") != 7 {
|
||||
t.Fatal("clampOffset 应把负数/非法归 0、合法透传")
|
||||
}
|
||||
}
|
||||
|
||||
// A1:safeCall 必须兜住 panic,不外抛(否则后台 goroutine 一 panic 崩整个进程)。
|
||||
func TestSafeCallRecovers(t *testing.T) {
|
||||
done := false
|
||||
func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Fatalf("safeCall 未兜住 panic:%v", r)
|
||||
}
|
||||
}()
|
||||
safeCall("test", func() { panic("boom") })
|
||||
done = true
|
||||
}()
|
||||
if !done {
|
||||
t.Fatal("safeCall 之后应正常继续")
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,10 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -230,6 +232,17 @@ func noteName(text string) string {
|
||||
|
||||
// KbIngestFile: POST /api/v1/kb/ingest_file(multipart)—— 文件入库(异步,返回 job_id)。
|
||||
// 流水线(解析→切块→向量化→写入)的进度经 sundynix.streams.<job_id> 回流,UI 用 SSE 看。
|
||||
// kbMaxUploadBytes 返回文件入库大小上限(字节)。默认 50MB,可经 KB_MAX_UPLOAD_BYTES 覆盖。
|
||||
func kbMaxUploadBytes() int64 {
|
||||
const def = 50 << 20 // 50MB
|
||||
if v := os.Getenv("KB_MAX_UPLOAD_BYTES"); v != "" {
|
||||
if n, err := strconv.ParseInt(v, 10, 64); err == nil && n > 0 {
|
||||
return n
|
||||
}
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
func (h *Handler) KbIngestFile(c *gin.Context) {
|
||||
kb := c.PostForm("kb")
|
||||
fh, err := c.FormFile("file")
|
||||
@@ -237,17 +250,28 @@ func (h *Handler) KbIngestFile(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "file required"})
|
||||
return
|
||||
}
|
||||
// 大小闸:先看 multipart 头声明的 Size(快速拒绝),再用 LimitReader 兜底防伪造 Size。
|
||||
// 否则整文件 io.ReadAll 进内存 = OOM 面。上限经 KB_MAX_UPLOAD_BYTES 配(默认 50MB)。
|
||||
max := kbMaxUploadBytes()
|
||||
if fh.Size > max {
|
||||
c.JSON(http.StatusRequestEntityTooLarge, gin.H{"error": "文件过大(上限 " + strconv.FormatInt(max/(1<<20), 10) + "MB)"})
|
||||
return
|
||||
}
|
||||
f, err := fh.Open()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadGateway, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
data, err := io.ReadAll(f)
|
||||
data, err := io.ReadAll(io.LimitReader(f, max+1))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadGateway, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
if int64(len(data)) > max {
|
||||
c.JSON(http.StatusRequestEntityTooLarge, gin.H{"error": "文件过大(上限 " + strconv.FormatInt(max/(1<<20), 10) + "MB)"})
|
||||
return
|
||||
}
|
||||
_ = h.db.EnsureKB(c.Request.Context(), spaceID(c), userID(c), rawKB(kb), "general")
|
||||
job, err := h.enqueueIngest(c.Request.Context(), spaceID(c), userID(c), rawKB(kb), scopedKB(c, kb), "", fh.Filename, data, "")
|
||||
if err != nil {
|
||||
|
||||
@@ -56,7 +56,7 @@ func pruneQueryMarks() {
|
||||
// StartReconcile 启动掉单补偿定时器(微信渠道未配置时空转,几乎零成本)。随进程生命周期运行,
|
||||
// ctx 取消即退出。返回给调用方保存以便优雅停机时取消。
|
||||
func (h *Handler) StartReconcile(ctx context.Context) {
|
||||
go func() {
|
||||
safeGo("payment-reconcile-ticker", func() {
|
||||
t := time.NewTicker(reconcileInterval)
|
||||
defer t.Stop()
|
||||
for {
|
||||
@@ -64,11 +64,14 @@ func (h *Handler) StartReconcile(ctx context.Context) {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-t.C:
|
||||
h.reconcilePending(ctx)
|
||||
pruneQueryMarks()
|
||||
// 单轮兜底:某轮 DB/查单 panic 不该终止整个补偿定时器,下一轮继续。
|
||||
safeCall("payment-reconcile-tick", func() {
|
||||
h.reconcilePending(ctx)
|
||||
pruneQueryMarks()
|
||||
})
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
log.Printf("[payment] 掉单补偿定时器已启动(每 %s 扫一次 pending 微信单)", reconcileInterval)
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,9 @@ func (h *Handler) GenerateReport(c *gin.Context) {
|
||||
// 生成阶段只存源;此处经 mcp-go report_export 现渲染("导出时再处理")。PDF 由前端打印预览生成。
|
||||
func (h *Handler) ExportReport(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
if !h.requireTaskOwner(c, id) { // 报告按 task_id 寻址:仅提交者可导出
|
||||
return
|
||||
}
|
||||
format := c.DefaultQuery("format", "docx")
|
||||
res, err := h.bus.CallTool(c.Request.Context(), contract.ToolSubjectGo("report_export"),
|
||||
&contract.ToolCall{Tool: "report_export", Args: map[string]any{"task_id": id, "format": format}})
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// requireTaskOwner 校验请求者(AuthFromHeaderOrQuery 已注入的 uid)是该 task 的提交者。
|
||||
// 用于公开 by-id 端点(SSE 流 / 报告导出):这些资源始终由本人的客户端访问(用户看/导出
|
||||
// 自己提交的运行),故按 owner 判权即安全。非本人 → 403,返回 false。
|
||||
func (h *Handler) requireTaskOwner(c *gin.Context, taskID string) bool {
|
||||
uid := userID(c)
|
||||
if uid == "" || h.db.TaskOwner(c.Request.Context(), taskID) != uid {
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": "无权访问该资源"})
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// safeGo 起一个带 panic 兜底的后台 goroutine:panic 只记日志(含 name + stack)不外抛。
|
||||
// 为什么必须有:Go 里未 recover 的 panic 会崩掉**整个进程**,而 gin.Recovery() 只保护
|
||||
// 请求 goroutine、不覆盖 handler 派生的后台 goroutine(定时器/推送/探针)。一个后台任务的
|
||||
// 意外 panic 不该拖垮整个 gateway、连带所有在途 HTTP。
|
||||
func safeGo(name string, fn func()) {
|
||||
go safeCall(name, fn)
|
||||
}
|
||||
|
||||
// safeCall 同步执行 fn 并兜底 panic。用于定时器**单轮**内部:单轮 panic 不该终止整个 ticker,
|
||||
// 兜住后下一轮照常继续(若把 recover 只放在 safeGo 外层,单轮 panic 会让整个循环 goroutine 结束)。
|
||||
func safeCall(name string, fn func()) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Printf("[panic] 后台任务 %q panic 已兜底: %v\n%s", name, r, debug.Stack())
|
||||
}
|
||||
}()
|
||||
fn()
|
||||
}
|
||||
@@ -75,58 +75,68 @@ func (h *Handler) AdminStatus(c *gin.Context) {
|
||||
// 1) mcp-go health → milvus / neo4j 基建灯
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
ctx, cancel := context.WithTimeout(parent, probeTimeout)
|
||||
defer cancel()
|
||||
if res, err := h.bus.CallTool(ctx, contract.ToolSubjectGo("health"),
|
||||
&contract.ToolCall{Tool: "health"}); err == nil && res != nil && res.OK {
|
||||
var sub map[string]bool
|
||||
if json.Unmarshal([]byte(res.Content), &sub) == nil {
|
||||
milvus, neo4j = sub["milvus"], sub["neo4j"]
|
||||
ftDisk = sub["fulltext_disk"]
|
||||
safeCall("status-probe-mcpgo-health", func() {
|
||||
ctx, cancel := context.WithTimeout(parent, probeTimeout)
|
||||
defer cancel()
|
||||
if res, err := h.bus.CallTool(ctx, contract.ToolSubjectGo("health"),
|
||||
&contract.ToolCall{Tool: "health"}); err == nil && res != nil && res.OK {
|
||||
var sub map[string]bool
|
||||
if json.Unmarshal([]byte(res.Content), &sub) == nil {
|
||||
milvus, neo4j = sub["milvus"], sub["neo4j"]
|
||||
ftDisk = sub["fulltext_disk"]
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}()
|
||||
|
||||
// 2) mcp-go list_tools → 在线判定 + 工具清单
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
goUp, goTools, goLatency = h.probeTools(parent, contract.ToolSubjectGo("list_tools"))
|
||||
safeCall("status-probe-mcpgo-tools", func() {
|
||||
goUp, goTools, goLatency = h.probeTools(parent, contract.ToolSubjectGo("list_tools"))
|
||||
})
|
||||
}()
|
||||
|
||||
// 3) mcp-py list_tools → 在线判定 + 工具清单
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
pyUp, pyTools, pyLatency = h.probeTools(parent, contract.ToolSubjectPy("list_tools"))
|
||||
safeCall("status-probe-mcppy-tools", func() {
|
||||
pyUp, pyTools, pyLatency = h.probeTools(parent, contract.ToolSubjectPy("list_tools"))
|
||||
})
|
||||
}()
|
||||
|
||||
// 4) dispatcher 心跳 → 在线判定 + 模型/运行时长
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
ctx, cancel := context.WithTimeout(parent, probeTimeout)
|
||||
defer cancel()
|
||||
start := time.Now()
|
||||
if data, err := h.bus.Ping(ctx, contract.SubjectHealthDispatcher); err == nil {
|
||||
dispUp = true
|
||||
dispLatency = int(time.Since(start).Milliseconds())
|
||||
var st struct {
|
||||
Model string `json:"model"`
|
||||
Ready bool `json:"ready"`
|
||||
UptimeS int `json:"uptime_s"`
|
||||
safeCall("status-probe-dispatcher", func() {
|
||||
ctx, cancel := context.WithTimeout(parent, probeTimeout)
|
||||
defer cancel()
|
||||
start := time.Now()
|
||||
if data, err := h.bus.Ping(ctx, contract.SubjectHealthDispatcher); err == nil {
|
||||
dispUp = true
|
||||
dispLatency = int(time.Since(start).Milliseconds())
|
||||
var st struct {
|
||||
Model string `json:"model"`
|
||||
Ready bool `json:"ready"`
|
||||
UptimeS int `json:"uptime_s"`
|
||||
}
|
||||
if json.Unmarshal(data, &st) == nil {
|
||||
dispDetail = dispatcherDetail(st.Model, st.Ready, st.UptimeS)
|
||||
}
|
||||
}
|
||||
if json.Unmarshal(data, &st) == nil {
|
||||
dispDetail = dispatcherDetail(st.Model, st.Ready, st.UptimeS)
|
||||
}
|
||||
}
|
||||
})
|
||||
}()
|
||||
|
||||
// 5) 基建活性探针:PG / Redis / MinIO 实时 ping(非仅启动标志,能反映中途掉线)。
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
ctx, cancel := context.WithTimeout(parent, probeTimeout)
|
||||
defer cancel()
|
||||
pgUp = h.db.Ping(ctx)
|
||||
redisUp = h.cache.Ping(ctx)
|
||||
minioUp = h.blob != nil && h.blob.Ping(ctx)
|
||||
safeCall("status-probe-infra", func() {
|
||||
ctx, cancel := context.WithTimeout(parent, probeTimeout)
|
||||
defer cancel()
|
||||
pgUp = h.db.Ping(ctx)
|
||||
redisUp = h.cache.Ping(ctx)
|
||||
minioUp = h.blob != nil && h.blob.Ping(ctx)
|
||||
})
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
|
||||
@@ -16,19 +16,20 @@ const subTickInterval = 10 * time.Minute
|
||||
|
||||
// StartSubscriptionTicker 随进程生命周期运行;多实例并发也安全(发放靠 ledger 唯一索引幂等)。
|
||||
func (h *Handler) StartSubscriptionTicker(ctx context.Context) {
|
||||
go func() {
|
||||
safeGo("subscription-ticker", func() {
|
||||
t := time.NewTicker(subTickInterval)
|
||||
defer t.Stop()
|
||||
h.tickSubscriptions(ctx) // 启动即跑一次,把停机期间欠的补上
|
||||
// 单轮兜底:某轮 panic 不该终止整个定时器,下一轮继续(漏发的下轮补发逻辑兜住)。
|
||||
safeCall("subscription-tick", func() { h.tickSubscriptions(ctx) }) // 启动即跑一次,补停机期间欠的
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-t.C:
|
||||
h.tickSubscriptions(ctx)
|
||||
safeCall("subscription-tick", func() { h.tickSubscriptions(ctx) })
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
log.Printf("[sub] 订阅推进定时器已启动(每 %s 扫一次)", subTickInterval)
|
||||
}
|
||||
|
||||
|
||||
@@ -261,6 +261,9 @@ func (h *Handler) ApproveTask(c *gin.Context) {
|
||||
// 优先从 Redis Stream 读(可回放 + 断点续传,根治连晚/重连丢 token);Redis 降级时回退 live NATS。
|
||||
func (h *Handler) StreamTask(c *gin.Context) {
|
||||
taskID := c.Param("id")
|
||||
if !h.requireTaskOwner(c, taskID) { // 归属校验须在写 SSE 头之前
|
||||
return
|
||||
}
|
||||
c.Writer.Header().Set("Content-Type", "text/event-stream")
|
||||
c.Writer.Header().Set("Cache-Control", "no-cache")
|
||||
c.Writer.Header().Set("Connection", "keep-alive")
|
||||
@@ -370,6 +373,9 @@ func (h *Handler) Health(c *gin.Context) {
|
||||
// 优先从 Redis Stream 读(可回放 + 断点续传,根治连晚/刷新重连丢轨迹事件);Redis 降级时回退 live NATS。
|
||||
func (h *Handler) StreamExec(c *gin.Context) {
|
||||
taskID := c.Param("id")
|
||||
if !h.requireTaskOwner(c, taskID) {
|
||||
return
|
||||
}
|
||||
c.Writer.Header().Set("Content-Type", "text/event-stream")
|
||||
c.Writer.Header().Set("Cache-Control", "no-cache")
|
||||
c.Writer.Header().Set("Connection", "keep-alive")
|
||||
|
||||
@@ -22,7 +22,7 @@ const wxNotifyTimeout = 10 * time.Second
|
||||
// 绝不影响入账主流程(钱已收、账已记,通知发不发都不能回滚)。
|
||||
// 仅在 MarkOrderPaid 返回 changed=true(首次到账)时调用,避免重复回调重复推送。
|
||||
func (h *Handler) notifyOrderPaid(orderID string) {
|
||||
go func() {
|
||||
safeGo("wx-notify-order-paid", func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), wxNotifyTimeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -46,7 +46,7 @@ func (h *Handler) notifyOrderPaid(orderID string) {
|
||||
if err := wechat.SendCustomText(ctx, token, u.WechatOpenID, h.composePaidMessage(ctx, o)); err != nil {
|
||||
log.Printf("[wxnotify] 支付回执推送失败 order=%s: %v", orderID, err)
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
// composePaidMessage 按订单类型拼回执文案,并带上当前积分余额。
|
||||
|
||||
Reference in New Issue
Block a user