1
0
mirror of synced 2026-10-18 05:16:10 +08:00

🎨 #4090 【微信支付】允许V2沙箱与V3配置共存

This commit is contained in:
Binary Wang
2026-08-12 13:34:26 +08:00
committed by GitHub
parent 1286cfd3f3
commit be7b151a7d
4 changed files with 68 additions and 3 deletions

View File

@@ -0,0 +1,53 @@
package com.github.binarywang.wxpay.service.impl;
import com.github.binarywang.wxpay.config.WxPayConfig;
import me.chanjar.weixin.common.error.WxRuntimeException;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.expectThrows;
public class WxPayServiceSandboxTest {
@Test
public void shouldUseV2SandboxUrlWhenV3KeyIsConfigured() {
WxPayConfig config = new WxPayConfig();
config.setApiHostUrl("https://api.mch.weixin.qq.com");
config.setApiHostUrlPath("/payment-proxy");
config.setApiV3Key("v3-key");
config.setUseSandboxEnv(true);
WxPayServiceImpl service = new WxPayServiceImpl();
service.setConfig(config);
assertEquals(service.getPayBaseUrl(), "https://api.mch.weixin.qq.com/payment-proxy/xdc/apiv2sandbox");
}
@Test
public void shouldRejectV3RequestWhenSandboxIsEnabled() {
WxPayConfig config = new WxPayConfig();
config.setUseSandboxEnv(true);
WxPayServiceImpl service = new WxPayServiceImpl();
service.setConfig(config);
WxRuntimeException exception = expectThrows(WxRuntimeException.class,
() -> service.postV3("https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi", "{}"));
assertEquals(exception.getMessage(), "微信支付V3 目前不支持沙箱模式!");
}
@Test
public void shouldRejectHttpComponentsV3RequestWhenSandboxIsEnabled() {
WxPayConfig config = new WxPayConfig();
config.setUseSandboxEnv(true);
WxPayServiceHttpComponentsImpl service = new WxPayServiceHttpComponentsImpl();
service.setConfig(config);
WxRuntimeException exception = expectThrows(WxRuntimeException.class,
() -> service.postV3("https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi", "{}"));
assertEquals(exception.getMessage(), "微信支付V3 目前不支持沙箱模式!");
}
}