diff --git a/backend/cmd/server/main.go b/backend/cmd/server/main.go index f1e3a71..557b73c 100644 --- a/backend/cmd/server/main.go +++ b/backend/cmd/server/main.go @@ -99,7 +99,8 @@ func main() { f.BindRoute("POST", "/mapi.php", service.PayMapiHandler(st, up)), f.BindRoute("GET", "/api.php", service.PayApiHandler(st)), f.BindRoute("POST", "/api.php", service.PayApiHandler(st)), - // submit.php 直出收银台页的状态轮询(经代理走 /api 前缀,直连后端也兼容) + // 收银台页(submit.php 的 302 落点)+ 页内状态轮询(经代理走 /api 前缀,直连后端也兼容) + f.BindRoute("GET", "/cashier.php", service.PayCashierPageHandler(st)), f.BindRoute("GET", "/cashier-status", service.PayCashierStatusHandler(st)), f.BindRoute("GET", "/api/cashier-status", service.PayCashierStatusHandler(st)), f.BindRoute("GET", "/healthz", func(c *fun.RouteCtx) error { diff --git a/backend/internal/service/cashier_page.go b/backend/internal/service/cashier_page.go index 5d289e5..19a4719 100644 --- a/backend/internal/service/cashier_page.go +++ b/backend/internal/service/cashier_page.go @@ -165,6 +165,19 @@ func renderCashier(c *fun.RouteCtx, o db.PayOrder) error { return nil } +// PayCashierPageHandler GET /cashier.php?trade_no=:收银台页渲染 +// (submit.php 302 落点,trade_no 不可枚举即凭证;重复访问按订单当前状态渲染)。 +func PayCashierPageHandler(st *store.Store) fun.RouteHandler { + return func(c *fun.RouteCtx) error { + o, err := st.Q().GetPayOrderByTradeNo(context.Background(), strings.TrimSpace(c.Param("trade_no"))) + if err != nil { + return epayJSON(c, map[string]any{"code": -1, "msg": "订单不存在"}) + } + lazyCloseExpired(st, &o) + return renderCashier(c, o) + } +} + // PayCashierStatusHandler GET /cashier-status?trade_no=:收银台页轮询 // (公开接口,trade_no 不可枚举即凭证;前端经 /api 前缀代理访问)。 func PayCashierStatusHandler(st *store.Store) fun.RouteHandler { diff --git a/backend/internal/service/pay_routes.go b/backend/internal/service/pay_routes.go index 2e22a1b..85a64fe 100644 --- a/backend/internal/service/pay_routes.go +++ b/backend/internal/service/pay_routes.go @@ -12,18 +12,15 @@ import ( "github.com/cyi-cc/cyi-box/backend/internal/store" ) -// paySubmitHandler GET/POST /submit.php:验签建单后直接渲染收银台页(无跳转)。 +// paySubmitHandler GET/POST /submit.php:验签建单后 302 到收银台页(PRG,刷新安全)。 func PaySubmitHandler(st *store.Store, up *payx.Client) fun.RouteHandler { return func(c *fun.RouteCtx) error { order, err := epayCreateOrder(c, st, up) if err != nil { return epayFail(c, err) } - o, err := st.Q().GetPayOrderByTradeNo(context.Background(), order.TradeNo) - if err != nil { - return epayFail(c, err) - } - return renderCashier(c, o) + c.RequestCtx.Redirect("/cashier.php?trade_no="+order.TradeNo, 302) + return nil } } diff --git a/docker/nginx.conf b/docker/nginx.conf index 081a966..885d7a6 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -62,7 +62,7 @@ server { proxy_read_timeout 3600s; } - location ~ ^/(submit|mapi|api)\.php$ { + location ~ ^/(submit|mapi|api|cashier)\.php$ { proxy_pass http://127.0.0.1:8891; proxy_http_version 1.1; proxy_set_header Host $host;