fix(nezha): create 成功码 code==0(生产实测更正,原假设 code==1 会把成功当拒绝)

opus 复审曾 flag 此互操作点需真实响应确认;pangolin1 联调实测:哪吒 create 成功返回
code=0 msg=success,provider 原 isCreateSuccess 判 code==1 → 把成功单当'下单被拒'。
改判 code==0;测试成功 mock 同步 code=0。
This commit is contained in:
wangjia
2026-07-11 16:03:26 +08:00
parent e1060f1f6e
commit 38d6b3633f
2 changed files with 8 additions and 7 deletions
+4 -3
View File
@@ -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
}
+4 -4
View File
@@ -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",
}