Browse Source

Merge branch 'smb' of http://192.168.0.200:3000/liuj/factoring-trade-backend into smb

wanglang 2 months ago
parent
commit
2aee8e18e1

+ 1 - 1
src/main/java/com/sunxung/factoring/service/smbApi/constants/TransCodeEnum.java

@@ -29,7 +29,7 @@ public enum TransCodeEnum {
         this.code = code;
         this.description = description;
         this.provider = provider;
-    };
+    }
 
     private String code;
     private String description;

+ 2 - 0
src/main/java/com/sunxung/factoring/service/smbApi/spi/impl/SMBSpiRegisterImpl.java

@@ -21,12 +21,14 @@ public class SMBSpiRegisterImpl implements SMBSpiRegister {
 
     @Override
     public void registerCreditNotifyHandler(Function<CreditNotifyPayloadDto, SMBNotifyRespDto> creditNotifyHandler) {
+        logger.debug("register credit notify handler");
         handlerMap.put(TransCodeEnum.CREDIT_NOTIFY.getCode(), creditNotifyHandler);
     }
 
     @Override
     public void registerWithdrawNotifyHandler(
             Function<WithdrawNotifyPayloadDto, SMBNotifyRespDto> withdrawNotifyHandler) {
+        logger.debug("register withdraw notify handler");
         handlerMap.put(TransCodeEnum.WITHDRAW_NOTIFY.getCode(), withdrawNotifyHandler);
     }
 

+ 17 - 2
src/main/java/com/sunxung/factoring/service/smbApi/spi/impl/SMBSpiServiceImpl.java

@@ -3,8 +3,9 @@ package com.sunxung.factoring.service.smbApi.spi.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.snb.fsos.util.SnbSignUtil;
 import com.snb.fsos.util.SnbUtil;
+import com.sunxung.factoring.entity.smbApi.SMBRequestLogPO;
+import com.sunxung.factoring.service.smbApi.api.SMBRequestLogService;
 import com.sunxung.factoring.service.smbApi.configuration.SMBConfiguration;
-import com.sunxung.factoring.service.smbApi.constants.TransCodeEnum;
 import com.sunxung.factoring.service.smbApi.dto.SMBNotifyRespDto;
 import com.sunxung.factoring.service.smbApi.spi.SMBSpiRegister;
 import com.sunxung.factoring.service.smbApi.spi.SMBSpiService;
@@ -26,6 +27,8 @@ public class SMBSpiServiceImpl implements SMBSpiService {
     private SMBConfiguration smbConfiguration;
     @Resource
     private SMBSpiRegister smbSpiRegister;
+    @Resource
+    private SMBRequestLogService smbRequestLogService;
 
     @Override
     public Map handSMBNotifyCallback(Map<String, String[]> reqParameterMap) {
@@ -44,6 +47,11 @@ public class SMBSpiServiceImpl implements SMBSpiService {
         String respCode = SUCCESS_CODE;
         String respMsg = "成功";
         JSONObject jsonObject = null;
+        logger.info("收到来自苏商银行的通知消息,通知类型:{}, 通知内容:{}", channelSerialNo, transCode, reqParameterMap);
+        SMBRequestLogPO smbRequestLogPO = new SMBRequestLogPO();
+        smbRequestLogPO.setSmbSerialNo(channelSerialNo);
+        smbRequestLogPO.setTransCode(transCode);
+        smbRequestLogPO.setChannelSerialNo(serialNo);
         try {
             Map map = SnbUtil.parseNotifyOrRespMsg(parameterMap);
             if ((boolean) map.get("verifyRes")) {
@@ -52,10 +60,13 @@ public class SMBSpiServiceImpl implements SMBSpiService {
             } else {
                 respCode = "00100004";
                 respMsg = "签名验证错误";
+                smbRequestLogPO.setRemark("签名验证错误");
             }
+            smbRequestLogPO.setRequestPayload(JSONObject.toJSONString(map));
         } catch (Exception e) {
             respCode = "00100042";
             respMsg = "payload解密失败";
+            smbRequestLogPO.setRemark("payload解密失败或者参数解析错误");
         }
         Map payloadMap = null;
         if (SUCCESS_CODE.equals(respCode)) {
@@ -66,12 +77,16 @@ public class SMBSpiServiceImpl implements SMBSpiService {
                 if (!smbNotifyRespDto.getRespResult()) {
                     respCode = "00100046";
                     respMsg = smbNotifyRespDto.getRespMsg();
+                    smbRequestLogPO.setRemark("业务处理返回失败:" + smbNotifyRespDto.getRespMsg());
                 }
             } else {
                 payloadMap = jsonObject;
             }
         }
-        return SnbUtil.getResponseNotifyContent(respCode, respMsg, serialNo, channelSerialNo, payloadMap);
+        Map respMap = SnbUtil.getResponseNotifyContent(respCode, respMsg, serialNo, channelSerialNo, payloadMap);
+        smbRequestLogPO.setResponsePayload(JSONObject.toJSONString(respMap));
+        smbRequestLogService.add(smbRequestLogPO);
+        return respMap;
     }
 
     private String getOneValue(Map<String, String[]> parameters, String name) {

+ 14 - 0
src/main/resources/data/update/createTable20240822.sql

@@ -0,0 +1,14 @@
+CREATE TABLE `smb_request_log`  (
+  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+  `trans_code` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '接口交易码',
+  `channel_serial_no` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '长银请求流水号',
+  `smb_serial_no` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '苏商银行流水号',
+  `request_payload` json NULL COMMENT '请求业务数据',
+  `response_payload` json NULL COMMENT '响应业务数据',
+  `success` tinyint(3) UNSIGNED NULL DEFAULT 0 COMMENT '请求结果,0 - 失败 ; 1 - 成功',
+  `remark` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '请求失败原因',
+  `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+  `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
+  PRIMARY KEY (`id`) USING BTREE,
+  INDEX `idx_trans_code`(`trans_code`, `channel_serial_no`) USING BTREE
+) ENGINE = InnoDB AUTO_INCREMENT = 0 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '苏商银行: 接口请求日志' ROW_FORMAT = COMPACT;