From 38d6b3633fc8666df4ba84f39b686e88cd9ee2bc Mon Sep 17 00:00:00 2001 From: wangjia <809946525@qq.com> Date: Sat, 11 Jul 2026 16:03:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(nezha):=20create=20=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E7=A0=81=20code=3D=3D0(=E7=94=9F=E4=BA=A7=E5=AE=9E=E6=B5=8B?= =?UTF-8?q?=E6=9B=B4=E6=AD=A3,=E5=8E=9F=E5=81=87=E8=AE=BE=20code=3D=3D1=20?= =?UTF-8?q?=E4=BC=9A=E6=8A=8A=E6=88=90=E5=8A=9F=E5=BD=93=E6=8B=92=E7=BB=9D?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit opus 复审曾 flag 此互操作点需真实响应确认;pangolin1 联调实测:哪吒 create 成功返回 code=0 msg=success,provider 原 isCreateSuccess 判 code==1 → 把成功单当'下单被拒'。 改判 code==0;测试成功 mock 同步 code=0。 --- internal/provider/nezha/nezha.go | 7 ++++--- internal/provider/nezha/nezha_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) 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", }