Browse Source

[深爱]科目基础资料对接测试

zxl 1 year ago
parent
commit
7af0acf700

+ 2 - 2
src/main/java/com/uas/eis/controller/STKController.java

@@ -404,8 +404,8 @@ public class STKController {
         dto.setSize("500");
         QueryCashFlowItemsDto dtoParam = new QueryCashFlowItemsDto();
         dto.setParam(dtoParam);
-        CashFlowItemsVo cashFlowItemsVo = requestSTKService.getCashFlowItems(dto);
-        return cashFlowItemsVo;
+        HttpResultResponse cashFlowItemsVo = requestSTKService.buildPostParam();
+        return JSONObject.parseObject(cashFlowItemsVo.getBody(),CashFlowItemsVo.class);
     }
 
 

+ 91 - 6
src/main/java/com/uas/eis/service/Impl/RequestSTKServiceImpl.java

@@ -24,6 +24,11 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.TemporalAdjusters;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -34,11 +39,11 @@ import java.util.Map;
 public class RequestSTKServiceImpl implements RequestSTKService {
 
 
-    //@Value("${STK.app_id}")
-    private String STK_APP_ID = "bf00be8b_0387_44f4_b073_50c3c2d6";
+    @Value("${STK.app_id}")
+    private String STK_APP_ID;
 
-    //@Value("${STK.app_key}")
-    private String STK_APP_KEY = "eb1b6053bdda437c98a93d93013d9fae";
+    @Value("${STK.app_key}")
+    private String STK_APP_KEY;
 
     /** 新增修改客商信息接口地址 */
     @Value("${STK.save_or_update_url}")
@@ -57,8 +62,8 @@ public class RequestSTKServiceImpl implements RequestSTKService {
     private String SAVE_OR_UPDATE_REQUEST_CODE ;
 
     /** 查询现金流量项目接口编码 */
-    //@Value("${STK.cash_flow_items_request_code}")
-    private String CASH_FLOW_ITEMS_REQUEST_CODE="89edb885a8cf4412b870233fc89fb381";
+    @Value("${STK.cash_flow_items_request_code}")
+    private String CASH_FLOW_ITEMS_REQUEST_CODE;
 
     /** 查询会计科目方法编码 */
     @Value("${STK.accountant_project_request_code}")
@@ -183,6 +188,86 @@ public class RequestSTKServiceImpl implements RequestSTKService {
         return detailDtos;
     }
 
+    @Override
+    public HttpResultResponse buildPostParam() throws Exception {
+        /*String appid = "bf00be8b_0387_44f4_b073_50c3c2d6";
+
+        //应用key
+        String appkey = "eb1b6053bdda437c98a93d93013d9fae";
+
+        //接口代码 每个接口的接口代码都不同
+        String apiCode = "89edb885a8cf4412b870233fc89fb381";*/
+
+        //时间戳
+        String timestamp = Long.toString(System.currentTimeMillis());
+
+        //分页内容 自行调整
+        String page = "1";
+        String pageSize = "500";
+
+        //支持  时间字段_start  时间字段_end  的传值  例:UPDATE_TIME
+        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        LocalDateTime begin = LocalDateTime.of(LocalDate.now(), LocalTime.MIN).with(TemporalAdjusters.firstDayOfYear());
+        LocalDateTime end = LocalDateTime.now();
+
+        //加签方法的重要参数
+        JSONObject request=new JSONObject(4);
+        //request.put("code","MJ3ahZ9f");
+        request.put("page",page);
+        request.put("size",pageSize);
+
+        //传入参数  此处案例仅放置了时间,可自行添加
+        JSONObject param=new JSONObject();
+        //param.put("UPDATE_TIME_start","2024-05-09 14:24:06");
+        //param.put("UPDATE_TIME_end","2024-05-09 15:01:28");
+        //param.put("TASKNO","P2022032200000041");
+        //param.put("TASKCODE","202409");
+
+
+        request.put("param",param);
+
+        String content = request.toString();
+
+        //加签方法第一个参数
+        StringBuilder signBuilder = new StringBuilder("appid").append("=").append(STK_APP_ID).append("&")
+                .append(content).append("&")
+                .append("timestamp").append("=").append(timestamp).append("&")
+                .append("key").append("=").append(STK_APP_KEY);
+
+        //加签
+        String sign = STKSignUtil.HMACSHA256(signBuilder.toString(),STK_APP_KEY);
+
+        System.out.println("原始:"+signBuilder);
+        log.info("STK,原始签名:"+signBuilder.toString());
+        System.out.println("签名:"+sign);
+        log.info("STK,加密签名:"+sign);
+        System.out.println("content:"+content);
+
+
+        //请求数据 (接口地址根据测试环境与正式环境变更)
+        /*String body = HttpRequest.post("https://192.168.2.179/api/oapigw/api/oapisvc/automicApi/"+apiCode)
+                .header("appid",appid)  //请求头
+                .header("timestamp", timestamp)
+                .header("sign", sign)
+                .header("Content-Type", "application/json")
+                .body(content)  //请求参数
+                .timeout(20000)  //超时时间
+                .execute().body();
+                )
+                */
+
+        Map<String,String> header = new HashMap<>();
+        header.put("appid",STK_APP_ID);
+        header.put("timestamp", timestamp);
+        header.put("sign", sign);
+        header.put("Content-Type", "application/json");
+        HttpResultResponse resultResponse = HuToolUtils.post("https://192.168.2.179/api/oapigw/api/oapisvc/automicApi/"+CASH_FLOW_ITEMS_REQUEST_CODE
+                ,request, header);
+
+        log.info("示例返回:{}",JSONObject.toJSONString(resultResponse));
+        return resultResponse ;
+    }
+
     @Override
     public List<CustvendDTO> queryList() {
         List<CustvendDTO> custvendDTO = new ArrayList<CustvendDTO>();

+ 6 - 0
src/main/java/com/uas/eis/service/RequestSTKService.java

@@ -42,5 +42,11 @@ public interface RequestSTKService {
     List<CustvendDTO> queryList();
 
 
+    /**
+     * post请求
+     * */
+    HttpResultResponse buildPostParam() throws Exception;
+
+
 
 }