pay: submit.php 回到 302,收银台页落在 /cashier.php
直出页面时 POST 表单刷新会丢/重复提交。改为 PRG: submit.php 建单后 302 到 /cashier.php?trade_no=(后端渲染同一 收银台页,按订单当前状态展示,刷新安全);nginx 放行 cashier.php。 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user