From 6e439e8cc4f3832b9ed2e8a45920d02539e180ae Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期五, 11 十一月 2022 12:19:54 +0800
Subject: [PATCH] 测试工商银行 支付 可能会编译失败

---
 java110-core/src/main/java/com/java110/core/factory/CallApiServiceFactory.java |   41 ++++++++++++++++++++++++++++++++---------
 1 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/java110-core/src/main/java/com/java110/core/factory/CallApiServiceFactory.java b/java110-core/src/main/java/com/java110/core/factory/CallApiServiceFactory.java
index 58c05ee..750fa4e 100755
--- a/java110-core/src/main/java/com/java110/core/factory/CallApiServiceFactory.java
+++ b/java110-core/src/main/java/com/java110/core/factory/CallApiServiceFactory.java
@@ -2,6 +2,7 @@
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.java110.core.context.Environment;
 import com.java110.core.context.IPageData;
 import com.java110.core.context.PageData;
 import com.java110.core.log.LoggerFactory;
@@ -25,11 +26,13 @@
 public class CallApiServiceFactory {
 
     private static final String URL_API = "http://api-service/api/";
+    private static final String URL_BOOT_API = "http://127.0.0.1:8008/api/";
     //鏃ュ織
     private static Logger logger = LoggerFactory.getLogger(CallApiServiceFactory.class);
 
     @Autowired
     private RestTemplate restTemplate;
+
 
     /**
      * 鏌ヨ
@@ -142,6 +145,10 @@
 
         String url = URL_API + serviceCode;
         RestTemplate restTemplate = ApplicationContextFactory.getBean("restTemplate", RestTemplate.class);
+        if (Environment.isStartBootWay()) {
+            url = URL_BOOT_API + serviceCode;
+            restTemplate = ApplicationContextFactory.getBean("outRestTemplate", RestTemplate.class);
+        }
 
 
         ResponseEntity<String> responseEntity = callCenterService(restTemplate, pd, JSONObject.toJSONString(param), url, HttpMethod.POST);
@@ -151,12 +158,17 @@
         }
 
         JSONObject resultVo = JSONObject.parseObject(responseEntity.getBody());
-
-        if (ResultVo.CODE_MACHINE_OK != resultVo.getInteger("code")) {
-            throw new SMOException(resultVo.getString("msg"));
+        Object bObj = null;
+        if(resultVo.containsKey("code")){
+            if (ResultVo.CODE_MACHINE_OK != resultVo.getInteger("code")) {
+                throw new SMOException(resultVo.getString("msg"));
+            }
+            bObj = resultVo.get("data");
+        }else{
+            bObj = resultVo;
         }
 
-        Object bObj = resultVo.get("data");
+
         JSONArray datas = null;
         if (bObj instanceof JSONObject) {
             datas = new JSONArray();
@@ -183,10 +195,16 @@
     public static <T> List<T> getForApis(IPageData pd, T param, String serviceCode, Class<T> t) {
 
         String url = URL_API + serviceCode;
+        RestTemplate restTemplate = ApplicationContextFactory.getBean("restTemplate", RestTemplate.class);
+
+        if (Environment.isStartBootWay()) {
+            url = URL_BOOT_API + serviceCode;
+            restTemplate = ApplicationContextFactory.getBean("outRestTemplate", RestTemplate.class);
+        }
+
         if (param != null) {
             url += mapToUrlParam(BeanConvertUtil.beanCovertMap(param));
         }
-        RestTemplate restTemplate = ApplicationContextFactory.getBean("restTemplate", RestTemplate.class);
 
         ResponseEntity<String> responseEntity = callCenterService(restTemplate, pd, "", url, HttpMethod.GET);
 
@@ -196,11 +214,15 @@
 
         JSONObject resultVo = JSONObject.parseObject(responseEntity.getBody());
 
-        if (!"0".equals(resultVo.getString("code"))) {
-            throw new SMOException(resultVo.getString("msg"));
+        Object bObj = null;
+        if(resultVo.containsKey("code")){
+            if (ResultVo.CODE_MACHINE_OK != resultVo.getInteger("code")) {
+                throw new SMOException(resultVo.getString("msg"));
+            }
+            bObj = resultVo.get("data");
+        }else{
+            bObj = resultVo;
         }
-
-        Object bObj = resultVo.get("data");
         JSONArray datas = null;
         if (bObj instanceof JSONObject) {
             datas = new JSONArray();
@@ -239,6 +261,7 @@
 
         HttpEntity<String> httpEntity = new HttpEntity<String>(param, header);
         //logger.debug("璇锋眰涓績鏈嶅姟淇℃伅锛寋}", httpEntity);
+
         try {
             responseEntity = restTemplate.exchange(url, httpMethod, httpEntity, String.class);
         } catch (HttpStatusCodeException e) { //杩欓噷spring 妗嗘灦 鍦�4XX 鎴� 5XX 鏃舵姏鍑� HttpServerErrorException 寮傚父锛岄渶瑕侀噸鏂板皝瑁呬竴涓�

--
Gitblit v1.8.0