77import com .google .gson .JsonElement ;
88import com .google .gson .JsonObject ;
99import lombok .extern .slf4j .Slf4j ;
10+ import me .chanjar .weixin .common .error .WxRuntimeException ;
1011import me .chanjar .weixin .common .util .http .apache .ByteArrayResponseHandler ;
1112import me .chanjar .weixin .common .util .json .GsonParser ;
1213import org .apache .commons .lang3 .StringUtils ;
@@ -128,6 +129,7 @@ public String postV3(String url, String requestStr) throws WxPayException {
128129 }
129130
130131 private String requestV3 (String url , String requestStr , HttpRequestBase httpRequestBase ) throws WxPayException {
132+ this .checkV3SandboxNotSupported ();
131133 CloseableHttpClient httpClient = this .createApiV3HttpClient ();
132134 try (CloseableHttpResponse response = httpClient .execute (httpRequestBase )) {
133135 //v3已经改为通过状态码判断200 204 成功
@@ -163,6 +165,7 @@ public String patchV3(String url, String requestStr) throws WxPayException {
163165
164166 @ Override
165167 public String postV3WithWechatpaySerial (String url , String requestStr ) throws WxPayException {
168+ this .checkV3SandboxNotSupported ();
166169 HttpPost httpPost = this .createHttpPost (url , requestStr );
167170 this .configureRequest (httpPost );
168171 CloseableHttpClient httpClient = this .createApiV3HttpClient ();
@@ -199,6 +202,7 @@ public String postV3(String url, HttpPost httpPost) throws WxPayException {
199202
200203 @ Override
201204 public String requestV3 (String url , HttpRequestBase httpRequest ) throws WxPayException {
205+ this .checkV3SandboxNotSupported ();
202206 this .configureRequest (httpRequest );
203207 CloseableHttpClient httpClient = this .createApiV3HttpClient ();
204208 try (CloseableHttpResponse response = httpClient .execute (httpRequest )) {
@@ -243,6 +247,7 @@ public String getV3WithWechatPaySerial(String url) throws WxPayException {
243247
244248 @ Override
245249 public InputStream downloadV3 (String url ) throws WxPayException {
250+ this .checkV3SandboxNotSupported ();
246251 HttpGet httpGet = new WxPayV3DownloadHttpGet (url );
247252 this .configureRequest (httpGet );
248253 CloseableHttpClient httpClient = this .createApiV3HttpClient ();
@@ -285,6 +290,7 @@ public String deleteV3(String url) throws WxPayException {
285290 }
286291
287292 private void configureRequest (HttpRequestBase request ) {
293+ this .checkV3SandboxNotSupported ();
288294 String serialNumber = getWechatPaySerial (getConfig ());
289295 String method = request .getMethod ();
290296 request .addHeader (ACCEPT , APPLICATION_JSON );
@@ -300,6 +306,12 @@ private void configureRequest(HttpRequestBase request) {
300306 .build ());
301307 }
302308
309+ private void checkV3SandboxNotSupported () {
310+ if (this .getConfig ().isUseSandboxEnv ()) {
311+ throw new WxRuntimeException ("微信支付V3 目前不支持沙箱模式!" );
312+ }
313+ }
314+
303315 private CloseableHttpClient createApiV3HttpClient () throws WxPayException {
304316 CloseableHttpClient apiV3HttpClient = this .getConfig ().getApiV3HttpClient ();
305317 if (null == apiV3HttpClient ) {
0 commit comments