diff --git a/internal/provider/nezha/nezha.go b/internal/provider/nezha/nezha.go index 4becc3a..ed610b1 100644 --- a/internal/provider/nezha/nezha.go +++ b/internal/provider/nezha/nezha.go @@ -183,14 +183,15 @@ func (p *Provider) Create(ctx context.Context, req provider.CreateRequest) (*pro }, nil } -// isCreateSuccess 判定 /api/pay/create 响应的 code 是否表示成功:JSON 数字解出来是 +// isCreateSuccess 判定 /api/pay/create 响应的 code 是否表示成功:真实哪吒 create 成功返回 +// code=0 msg=success(与 query 一致),而非 code=1(经生产联调实测更正)。JSON 数字解出来是 // float64,兼容个别实现把 code 当字符串返回。 func isCreateSuccess(raw map[string]any) bool { switch v := raw["code"].(type) { case float64: - return v == 1 + return v == 0 case string: - return v == "1" + return v == "0" default: return false } diff --git a/internal/provider/nezha/nezha_test.go b/internal/provider/nezha/nezha_test.go index bf8c2fa..649a14c 100644 --- a/internal/provider/nezha/nezha_test.go +++ b/internal/provider/nezha/nezha_test.go @@ -188,7 +188,7 @@ func TestCreateRedirect(t *testing.T) { t.Fatalf("content-type = %q", got) } resp := map[string]any{ - "code": float64(1), "msg": "success", + "code": float64(0), "msg": "success", "trade_no": "NZ2026071100001", "out_trade_no": gotForm.Get("out_trade_no"), "pay_type": gotForm.Get("type"), "payurl": "https://nzzf.org/pay/checkout/abc", "qrcode": "", "timestamp": strconv.FormatInt(time.Now().Unix(), 10), @@ -249,7 +249,7 @@ func TestCreateQRWithExplicitType(t *testing.T) { _ = r.ParseForm() gotForm = r.Form resp := map[string]any{ - "code": float64(1), "msg": "success", + "code": float64(0), "msg": "success", "trade_no": "NZ-QR-1", "out_trade_no": gotForm.Get("out_trade_no"), "pay_type": gotForm.Get("type"), "payurl": "", "qrcode": "weixin://wxpay/bizpayurl?pr=abc123", "timestamp": strconv.FormatInt(time.Now().Unix(), 10), @@ -294,7 +294,7 @@ func TestCreateQRAutoSelectedWhenNoPayURL(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _ = r.ParseForm() resp := map[string]any{ - "code": float64(1), "msg": "success", "trade_no": "NZ-AUTO-QR", + "code": float64(0), "msg": "success", "trade_no": "NZ-AUTO-QR", "payurl": "", "qrcode": "https://qr.example/abc", "timestamp": strconv.FormatInt(time.Now().Unix(), 10), "sign_type": "RSA", } @@ -350,7 +350,7 @@ func TestCreateResponseBadSignRejected(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { resp := map[string]any{ - "code": float64(1), "msg": "success", "trade_no": "NZ-EVIL", + "code": float64(0), "msg": "success", "trade_no": "NZ-EVIL", "payurl": "https://evil.example/pay", "timestamp": strconv.FormatInt(time.Now().Unix(), 10), "sign_type": "RSA", }