From 49aaecfb0617b0e6043147c86f3d303e9f24867e Mon Sep 17 00:00:00 2001
From: liulin <lin.liu@88.com>
Date: 星期三, 09 七月 2025 20:27:56 +0800
Subject: [PATCH] 修改yml配置

---
 src/main/java/com/fengdu/gas/service/TestInfoService.java |  442 +++++++++++++++++++++++++++++-------------------------
 1 files changed, 239 insertions(+), 203 deletions(-)

diff --git a/src/main/java/com/fengdu/gas/service/TestInfoService.java b/src/main/java/com/fengdu/gas/service/TestInfoService.java
index efb660d..58fe0e5 100644
--- a/src/main/java/com/fengdu/gas/service/TestInfoService.java
+++ b/src/main/java/com/fengdu/gas/service/TestInfoService.java
@@ -1,5 +1,6 @@
 package com.fengdu.gas.service;
 
+import com.fengdu.gas.entity.request.test.TestPayVO;
 import com.fengdu.gas.repository.po.TestInfoPO;
 import com.fengdu.gas.service.convert.TestInfoConvert;
 import com.fengdu.gas.common.ExecutedResult;
@@ -15,10 +16,30 @@
 import com.fengdu.gas.entity.search.SearchTestInfo;
 import com.fengdu.gas.repository.impl.TestInfoMapperImpl;
 import com.fengdu.gas.repository.vo.TestInfoVO;
+import com.google.gson.Gson;
 import org.apache.commons.lang3.BooleanUtils;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.crypto.Cipher;
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.security.KeyStore;
+import java.security.NoSuchAlgorithmException;
+import java.security.Signature;
+import java.security.interfaces.RSAPrivateCrtKey;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -29,222 +50,237 @@
 public class TestInfoService extends BaseService {
     @Autowired
     private TestInfoMapperImpl mapper;
+    //私钥
+   private final static String PRIVATE_KEY="";
+    private final static String PASSWORD="";
 
-    public ExecutedResult<Long> create(ReqCreateTestInfo request) {
-        // 转换po
-        TestInfoPO item = TestInfoConvert.INSTANCE.toCreate(request);
-        // 设置状态
-        item.setStatus(EState.NORMAL.getValue());
-        // 设置记录创建时间
-        item.setCreateTime(LocalDateTimeUtil.nowTimeStamp());
-        // 非逻辑删除
-        item.setIsDelete(EYesOrNo.NO.getValue());
-
-        int rowCount = mapper.insert(item);
-        if (rowCount != 1) {
-            return ExecutedResult.failed("创建[测试信息]失败。");
-        }
-        return ExecutedResult.success(item.getId());
+    /**
+     * AES256加密
+     * @param data
+     * @return
+     * @throws Exception
+     */
+    public String AES256(String data) throws Exception {
+        KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
+        keyGenerator.init(256); // 初始化密钥生成器,指定AES-256
+        SecretKey key = keyGenerator.generateKey();
+        Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
+        cipher.init(Cipher.ENCRYPT_MODE, key);
+        byte[] encrypted = cipher.doFinal(data.getBytes("UTF-8"));
+        return Base64.getEncoder().encodeToString(encrypted);
     }
 
-    public ExecutedResult<String> modify(ReqModifyTestInfo request) {
-        // 验证记录是否存在
-        ExecutedResult<TestInfoPO> checkExists = this.check4Id(request.getId());
-        if (checkExists.isFailed()) {
-            return ExecutedResult.failed(checkExists.getMsg());
+    /**
+     * Base64加密
+     * @param data
+     * @return
+     */
+    public String Base64(String data) {
+        String encodedString = Base64.getEncoder().encodeToString(data.getBytes());
+        return encodedString;
+    }
+    public static String getKeyAndValueStr(Map<String, String> map) {
+        String result = "";
+        try {
+            List<Map.Entry<String, String>> infoIds = new ArrayList<>(map.entrySet());
+            // 对所有传入参数按照字段名的 ASCII 码从小到大排序(字典序)
+            Collections.sort(infoIds, Comparator.comparing(Map.Entry::getKey));
+            // 构造签名键值对的格式
+            StringBuilder sb = new StringBuilder();
+            for (Map.Entry<String, String> item : infoIds) {
+                if (item.getKey() != null && item.getKey() != "") {
+                    String key = item.getKey();
+                    String val = item.getValue();
+                    if (!(val == "" || val == null)) {
+                        sb.append(key + "=" + val + "&");
+                    }
+                }
+            }
+            result = sb.toString().substring(0, sb.length() - 1);
+        } catch (Exception e) {
+            return null;
         }
-
-        // 转换po
-        TestInfoPO item = TestInfoConvert.INSTANCE.toModify(request);
-
-        int rowCount = mapper.updateById(item);
-        if (rowCount != 1) {
-            return ExecutedResult.failed("编辑[测试信息]失败。");
-        }
-        return ExecutedResult.success();
+        return result;
     }
 
-    public ExecutedResult<TestInfoVO> get(Long id) {
-        TestInfoVO result = new TestInfoVO();
 
-        TestInfoPO find = mapper.selectById(id);
-        if (null != find) {
-            result = TestInfoConvert.INSTANCE.toVo(find);
+    /**
+     * 测试支付
+     * @return
+     * @throws Exception
+     */
+    public ExecutedResult<String> testPay() throws Exception {
+        CloseableHttpClient client = HttpClients.createDefault();
+        HttpPost httpPost = new HttpPost("https://test.sumpay.cn/entrance/gateway.htm");
+        List<BasicNameValuePair> pairList = new ArrayList<>();
+        Map<String, String> map = new HashMap<>();
+        map.put("service", "fosun.sumpay.api.orderpay.order.apply");
+        map.put("version","1.0");
+        map.put("format","JSON");
+        map.put("app_id",);
+        map.put("timestamp","20250313142521");
+        map.put("terminal_type","api");
+        map.put("mer_no", "200102833852");//商户号
+        map.put("account_type", "01");//付款方账户类型
+        map.put("card_no", AES256("6217007200125513450"));//付款方账户号
+        map.put("real_name", AES256("尹勇"));//付款方账户名
+        //map.put("bank_code","");//银行代码
+        //map.put("id_type","1");//证件类型
+        //map.put("id_no",AES256(""));//证件号码
+        //map.put("notify_url");//商户后台通知URL
+        map.put("goods_name", Base64("测试001"));//商品名称
+        map.put("goods_num", "1");//商品数量
+        map.put("goods_price", "0.11");//商品价格
+        map.put("goods_type", "1");//商品类型
+        map.put("order_no", "111111111111111");//订单号
+        map.put("order_amount", "0.11");//订单金额
+        map.put("order_time", "20250313142521");//订单时间
+        map.put("currency", "CNY");//币种
+        // map.put("pay_comments");//附言
+        //map.put("remark");//备注字段
+        Map<String, String> map1 = new HashMap<>();
+        for (Map.Entry<String, String> entry : map.entrySet()) {
+            map1.put(entry.getKey(), entry.getValue());
         }
-        return ExecutedResult.success(result);
-    }
+        //map转换字符串&拼接并排序
+        String keyAndValueStr = getKeyAndValueStr(map);
+        //签名处理
+        String msg = signMsg(keyAndValueStr, PRIVATE_KEY, PASSWORD, "UTF-8");
+        map1.put("sign_type","CERT");
+        map1.put("sign",msg);
 
-    public ExecutedResult<String> stop(Long id) {
-        // 验证记录是否存在
-        ExecutedResult<TestInfoPO> checkExists = this.check4Id(id);
-        if (checkExists.isFailed()) {
-            return ExecutedResult.failed(checkExists.getMsg());
+        for(String key:map1.keySet()){
+            pairList.add(new BasicNameValuePair(key,map1.get(key)));
         }
-
-        TestInfoPO item = new TestInfoPO();
-        item.setId(id);
-        item.setStatus(EState.DISABLED.getValue());
-
-        int rowCount = mapper.updateById(item);
-        if (rowCount != 1) {
-            return ExecutedResult.failed("停用[测试信息]失败。");
-        }
-        return ExecutedResult.success();
-    }
-
-    public ExecutedResult<String> enable(Long id) {
-        // 验证记录是否存在
-        ExecutedResult<TestInfoPO> checkExists = this.check4Id(id);
-        if (checkExists.isFailed()) {
-            return ExecutedResult.failed(checkExists.getMsg());
-        }
-
-        TestInfoPO item = new TestInfoPO();
-        item.setId(id);
-        item.setStatus(EState.NORMAL.getValue());
-
-        int rowCount = mapper.updateById(item);
-        if (rowCount != 1) {
-            return ExecutedResult.failed("启用[测试信息]失败。");
-        }
-        return ExecutedResult.success();
-    }
-
-    public ExecutedResult<String> setSort(ReqSetSort request) {
-        // 验证记录是否存在
-        ExecutedResult<TestInfoPO> checkExists = this.check4Id(request.getId());
-        if (checkExists.isFailed()) {
-            return ExecutedResult.failed(checkExists.getMsg());
-        }
-
-        TestInfoPO item = new TestInfoPO();
-        item.setId(request.getId());
-        item.setSort(request.getSort());
-
-        int rowCount = mapper.updateById(item);
-        if (rowCount != 1) {
-            return ExecutedResult.failed("[测试信息]设置排序值失败。");
-        }
-        return ExecutedResult.success();
-    }
-
-    public ExecutedResult<String> listSetSort(ReqListSetSort request) {
-        // id列表
-        List<Long> listId = request.getList().stream().map(ReqSetSort::getId).collect(Collectors.toList());
-        // 验证记录是否存在
-        ExecutedResult<List<TestInfoPO>> checkExists = this.check4Id(listId);
-        if (checkExists.isFailed()) {
-            return ExecutedResult.failed(checkExists.getMsg());
-        }
-
-        List<TestInfoPO> listUpdate = request.getList().stream()
-                .map(c -> {
-                    TestInfoPO item = new TestInfoPO();
-                    item.setId(c.getId());
-                    item.setSort(c.getSort());
-                    return item;
-                })
-                .collect(Collectors.toList());
-        Boolean result = mapper.modifyList(listUpdate);
-        if (result) {
-            return ExecutedResult.success();
-        }
-        return ExecutedResult.failed("[测试信息]设置排序值失败");
-    }
-
-    public ExecutedResult<String> remove(Long id) {
-        // 验证记录是否存在
-        ExecutedResult<TestInfoPO> checkExists = this.check4Id(id);
-        if (checkExists.isFailed()) {
-            return ExecutedResult.failed(checkExists.getMsg());
-        }
-
-        Boolean result = mapper.deleteLogic(id);
-        if (BooleanUtils.isFalse(result)) {
-            return ExecutedResult.failed("删除[测试信息]失败。");
-        }
-        return ExecutedResult.success();
-    }
-
-    public ExecutedResult<String> removeList(List<Long> listId) {
-        // 验证记录是否存在
-        ExecutedResult<List<TestInfoPO>> checkExists = this.check4Id(listId);
-        if (checkExists.isFailed()) {
-            return ExecutedResult.failed(checkExists.getMsg());
-        }
-
-        Boolean result = mapper.deleteLogic(listId);
-        if (BooleanUtils.isFalse(result)) {
-            return ExecutedResult.failed("删除[测试信息]失败。");
-        }
-        return ExecutedResult.success();
-    }
-
-    public ExecutedResult<List<TestInfoVO>> getList(List<Long> listId) {
-        List<TestInfoVO> result = new ArrayList<>();
-
-        List<TestInfoPO> list = mapper.getList(listId);
-        if (ListUtil.isNotNullOrEmpty(list)) {
-            result = CopierUtil.mapTo(list, TestInfoVO.class);
-        }
-        return ExecutedResult.success(result);
-    }
-
-    public ExecutedResult<PagerResult<TestInfoVO>> search(SearchTestInfo search) {
-        // 处理创建时间范围-查询参数
-        Tuple<String, String> createTimeRange = ParameterUtil.getTimeRange(search.getCreateTimeRange());
-        if (StringUtil.isNotNullOrEmpty(createTimeRange.getItem1())) {
-            search.setCreateTimeStart(LocalDateTimeUtil.getTimeStamp(createTimeRange.getItem1()).getTime());
-        }
-        if (StringUtil.isNotNullOrEmpty(createTimeRange.getItem2())) {
-            search.setCreateTimeEnd(LocalDateTimeUtil.getTimeStamp(createTimeRange.getItem2()).getTime());
-        }
-
-        PagerResult<TestInfoPO> pageList = mapper.search(search);
-        List<TestInfoVO> listVo = new ArrayList<>();
-        List<TestInfoPO> list = pageList.getList();
-        if (ListUtil.isNotNullOrEmpty(list)) {
-            pageList.setLastId(list.get(list.size() - 1).getId());
-            // 转换vo
-            listVo = TestInfoConvert.INSTANCE.toVo(list);
-        }
-        PagerResult<TestInfoVO> result = new PagerResult<>(pageList.getLimit(), pageList.getPage(), pageList.getTotal(), listVo);
-        result.setLastId(pageList.getLastId());
-        return ExecutedResult.success(result);
-    }
-
-    protected ExecutedResult<TestInfoPO> check4Id(Long id) {
-        TestInfoPO exists = mapper.get(id);
-        if (Objects.isNull(exists)) {
-            return ExecutedResult.failed("[测试信息]不存在:" + id);
-        }
-        return ExecutedResult.success(exists);
-    }
-    protected ExecutedResult<List<TestInfoPO>> check4Id(List<Long> listId) {
-        // 从数据库查找测试信息
-        List<TestInfoPO> list = mapper.getList(listId);
-        if (ListUtil.isNullOrEmpty(list)) {
-            return ExecutedResult.failed("[测试信息]不存在." + listId);
-        }
-        // 数据库找到的id列表
-        List<Long> listIdFind = list.stream().map(TestInfoPO::getId).collect(Collectors.toList());
-        // 数量不一致
-        if (listId.size() != listIdFind.size()) {
-            // 筛选数据库不存在的测试信息
-            List<Long> listIdNotFound = listId.stream().filter(c -> !listIdFind.contains(c)).collect(Collectors.toList());
-            if (ListUtil.isNullOrEmpty(list)) {
-                return ExecutedResult.failed("[测试信息]不存在." + listIdNotFound);
+        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairList, "UTF-8");
+        httpPost.setEntity(entity);
+        try {
+            // 执行请求并获取响应
+            CloseableHttpResponse response = client.execute(httpPost);
+            try {
+               if(response.getStatusLine().getStatusCode()== HttpStatus.SC_OK){
+                   String data=EntityUtils.toString(response.getEntity(),"UTF-8");
+                   System.out.println(data);
+               }else {
+                   throw new RuntimeException("接口连接失败");
+               }
+                // 处理响应...
+            } finally {
+                response.close();
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                client.close();
+            } catch (IOException e) {
+                e.printStackTrace();
             }
         }
-        return ExecutedResult.success(list);
+        return ExecutedResult.success();
     }
-
-    protected Map<Long, TestInfoPO> getMap4Id(List<Long> listId) {
-        List<TestInfoPO> list = mapper.getList(listId);
-        if (ListUtil.isNullOrEmpty(list)) {
-            return new HashMap<>(0);
+    /**
+     * 订单支付确认接口
+     * @return
+     * @throws Exception
+     */
+    public ExecutedResult<String> confirmPay() throws Exception {
+        CloseableHttpClient client = HttpClients.createDefault();
+        HttpPost httpPost = new HttpPost("https://test.sumpay.cn/entrance/gateway.htm");
+        List<BasicNameValuePair> pairList = new ArrayList<>();
+        Map<String, String> map = new HashMap<>();
+        map.put("service", "fosun.sumpay.api.orderpay.order.apply");
+        map.put("version","1.0");
+        map.put("format","JSON");
+        map.put("app_id",);
+        map.put("timestamp","20250313142521");
+        map.put("terminal_type","api");
+        map.put("mer_no", "200102833852");//商户号
+        map.put("order_no", "111111111111111");//订单号
+        map.put("serial_no", "");//入账流水号
+        Map<String, String> map1 = new HashMap<>();
+        for (Map.Entry<String, String> entry : map.entrySet()) {
+            map1.put(entry.getKey(), entry.getValue());
         }
-        return list.stream().collect(Collectors.toMap(TestInfoPO::getId, c -> c));
-    }
+        //map转换字符串&拼接并排序
+        String keyAndValueStr = getKeyAndValueStr(map);
+        //签名处理
+        String msg = signMsg(keyAndValueStr, PRIVATE_KEY, PASSWORD, "UTF-8");
+        map1.put("sign_type","CERT");
+        map1.put("sign",msg);
 
+        for(String key:map1.keySet()){
+            pairList.add(new BasicNameValuePair(key,map1.get(key)));
+        }
+        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairList, "UTF-8");
+        httpPost.setEntity(entity);
+        try {
+            // 执行请求并获取响应
+            CloseableHttpResponse response = client.execute(httpPost);
+            try {
+                if(response.getStatusLine().getStatusCode()== HttpStatus.SC_OK){
+                    String data=EntityUtils.toString(response.getEntity(),"UTF-8");
+                    System.out.println(data);
+                }else {
+                    throw new RuntimeException("接口连接失败");
+                }
+                // 处理响应...
+            } finally {
+                response.close();
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                client.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return ExecutedResult.success();
+    }
+    /**
+     * 签名处理
+     * @param privateKeyPath:私钥
+     * @param plaintext:原始字符串
+     * @param passWord:证书密码
+     * @param charset :UTF-8
+     * @return
+     */
+    public String signMsg(String plaintext, String privateKeyPath, String passWord, String charset) {
+        try {
+            InputStream keyFile = new FileInputStream(new File(privateKeyPath));
+            KeyStore ks = KeyStore.getInstance("PKCS12");
+            try {
+                ks.load(keyFile, passWord.toCharArray());
+            } catch (Throwable ex) {
+                if (keyFile != null)
+                    keyFile.close();
+                throw new RuntimeException("加载私钥失败",ex);
+            }
+            Enumeration<String> myEnum = ks.aliases();
+            String keyAlias = null;
+            RSAPrivateCrtKey prikey = null;
+            /* IBM JDK必须使用While循环取最后一个别名,才能得到个人私钥别名 */
+            while (myEnum.hasMoreElements()) {
+                keyAlias = myEnum.nextElement();
+                if (ks.isKeyEntry(keyAlias)) {
+                    prikey = (RSAPrivateCrtKey) ks.getKey(keyAlias, passWord.toCharArray());
+                    break;
+                }
+            }
+            if (prikey == null) {
+                throw new RuntimeException("没有找到匹配私钥");
+            } else {
+                Signature sign = Signature.getInstance("SHA256withRSA");
+                sign.initSign(prikey);
+                sign.update(plaintext.getBytes(charset));
+                return org.apache.commons.codec.binary.Base64.encodeBase64String(sign.sign());
+            }
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Throwable e) {
+            throw new RuntimeException("签名失败",e);
+        }
+    }
 }

--
Gitblit v1.9.3