TRX 1 anno fa
parent
commit
7522d4c168

+ 46 - 0
PaymentClient/src/main/java/com/zhongshu/payment/client/payModel/unionFrictionlessPay/model/SignNotifyModel.java

@@ -0,0 +1,46 @@
+package com.zhongshu.payment.client.payModel.unionFrictionlessPay.model;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * 签约通知
+ *
+ * @author TRX
+ * @date 2024/9/2
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class SignNotifyModel {
+
+    @Schema(description = "报文请求时间 格式yyyy-MM-dd HH:mm:ss")
+    private String requestTimestamp;
+
+    @Schema(description = "商户代码 银商商户号")
+    private String mid;
+
+    @Schema(description = "商户签约协议号 原签约交易的商户签约协议号")
+    private String contractNo;
+
+    @Schema(description = "银商免密支付签约协议号 签约成功时返回。云闪付侧的签约协议号,由银联生成。即标记化支付信息域的token。BASE64加密。")
+    private String contractId;
+
+    @Schema(description = "签约状态 通知商户,必传。 UNSIGNED-未签约 SIGNED-已签约 RESCISSION-已解约 DELETING_CONTRACT-解约中 UNKNOWN-未知")
+    private String contractState;
+
+    @Schema(description = "协议签约时间 签约成功时返回。即标记化支付信息域的tokenBegin。格式yyyy-MM-dd HH:mm:ss")
+    private String contractSignedTime;
+
+    @Schema(description = "协议到期时间 签约成功时返回。即标记化支付信息域的tokenEnd。格式yyyy-MM-dd HH:mm:ss")
+    private String contractExpiredTime;
+
+    @Schema(description = "云闪付用户ID 云闪付用户ID")
+    private String acpId;
+
+    @Schema(description = "掩码手机号 前3后4明文,其余*替换")
+    private String maskedPhoneNo;
+
+}

+ 3 - 0
PaymentServer/src/main/java/com/zhongshu/payment/server/core/domain/unionFrictionlessPay/UnionUserOpenInfo.java

@@ -54,6 +54,9 @@ public class UnionUserOpenInfo extends SuperMain {
     @Schema(description = "协议到期时间,格式:yyyy-MM-dd HH:mm:ss")
     private String contractExpiredTime;
 
+    @Schema(description = "签约到期时间")
+    private Long contractExpiredTimeMillis;
+
     @Schema(description = "签约订单过期时间")
     private Long expiredTime;
 

+ 2 - 0
PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/impl/unionFrictionlessPay/UnionFrictionlessPayMainService.java

@@ -96,6 +96,8 @@ public class UnionFrictionlessPayMainService extends SuperPayService {
         UserCountModel userCountModel = resultContent.getContent();
 
         // 验证学校信息
+
+        // 商户签约协议号 商户生成。在该商户号下唯一
         String contractNo = collectionIdService.getNextNo();
         UnionUserOpenInfo unionUserOpenInfo = unionUserOpenInfoDao.findTopByUserId(userId);
         if (ObjectUtils.isEmpty(unionUserOpenInfo)) {

+ 59 - 36
PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/pay/impl/unionFrictionlessPay/UnionNotifyService.java

@@ -9,7 +9,9 @@ import com.github.microservice.stream.PaymentStreamType;
 import com.github.microservice.stream.model.SignModel;
 import com.github.microservice.types.unionFrictionlessPayType.ContractState;
 import com.zhongshu.card.client.service.feign.OperationLogsFeignService;
+import com.zhongshu.card.client.utils.DateUtils;
 import com.zhongshu.payment.client.payModel.unionFrictionlessPay.model.PayNotifyResponse;
+import com.zhongshu.payment.client.payModel.unionFrictionlessPay.model.SignNotifyModel;
 import com.zhongshu.payment.client.payModel.unionFrictionlessPay.model.SignNotifyParam;
 import com.zhongshu.payment.server.core.dao.unionFrictionlessPay.UnionUserOpenInfoDao;
 import com.zhongshu.payment.server.core.domain.unionFrictionlessPay.UnionUserOpenInfo;
@@ -33,10 +35,7 @@ import org.springframework.stereotype.Service;
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
 import java.security.*;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @author TRX
@@ -96,48 +95,72 @@ public class UnionNotifyService extends SuperService {
             log.info("key: {}, values: {}", key, values);
             paramMap.put(key, values[0]);
         });
+        JSONObject jsonObject = new JSONObject(paramMap);
+        SignNotifyModel notifyModel = JSONUtil.toBean(jsonObject, SignNotifyModel.class);
+        contractNo = notifyModel.getContractNo();
 
-        String contractState = paramMap.get("contractState");
+        String contractState = notifyModel.getContractState();
+        // 签约信息
         UnionUserOpenInfo unionUserOpenInfo = unionUserOpenInfoDao.findTopByContractNo(contractNo);
         if (ObjectUtils.isNotEmpty(unionUserOpenInfo)) {
             unionUserOpenInfo.setContractState(CommonUtil.getEnumByName(ContractState.class, contractState));
         }
+        // 签约协议号
+        unionUserOpenInfo.setContractId(notifyModel.getContractId());
+        // 签约时间
+        unionUserOpenInfo.setContractSignedTime(notifyModel.getContractSignedTime());
+        // 协议到期时间
+        unionUserOpenInfo.setContractExpiredTime(notifyModel.getContractExpiredTime());
+        Date date = DateUtils.parseStr2Date(notifyModel.getContractExpiredTime(), DateUtils.FORMAT_LONG);
+        if (date != null) {
+            // 协议到期时间毫秒数
+            unionUserOpenInfo.setContractExpiredTimeMillis(date.getTime());
+        }
         unionUserOpenInfo.setSignResult(paramMap);
         unionUserOpenInfoDao.save(unionUserOpenInfo);
 
-        Security.addProvider(new BouncyCastleProvider());
-        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(
-                "EC",
-                "BC");
-        JSONObject jsonObject = new JSONObject(paramMap);
-
-        ECNamedCurveParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("sm2p256v1");
-        keyPairGenerator.initialize(ecSpec);
-        KeyPair keyPair = keyPairGenerator.generateKeyPair();
-
-        Signature signature = Signature.getInstance("SM3withSM2", "BC");
-        signature.initVerify(keyPair.getPublic());
-        signature.update("Hello, SM2".getBytes());
-        log.info("验证signature: {}", signature.verify(jsonObject.toString().getBytes()));
-
-        SignNotifyParam signNotifyParam = new SignNotifyParam();
-        BeanUtils.copyProperties(paramMap, signNotifyParam);
-        log.info("签约通知字符串:{} {}", contractNo, paramMap);
-
-        PublicKey publicKey = AesUtils.initializeSM3WithSM2PublicKey(
-                payConfig.getNotifySecret());
-        // 创建 Signature 对象,指定验签算法为 SM3withSM2
-        Signature signature1 = Signature.getInstance("SM3withSM2");
-        // 初始化 Signature 对象,使用公钥进行验签
-        signature1.initVerify(publicKey);
-        // 更新待验签的数据
-        signature1.update(jsonObject.toString().getBytes());
-        // 进行验签并获取验证结果
-        boolean verifyResult = signature1.verify(authorization.getBytes());
-
-
+        // 发送签约结果消息
         SignModel signModel = new SignModel();
+        signModel.setUserId(unionUserOpenInfo.getUserId());
+        signModel.setContractState(unionUserOpenInfo.getContractState());
+        signModel.setMid(unionUserOpenInfo.getMid());
         streamHelper.send(PaymentStreamType.UnionFrictionStateStream.name(), signModel);
+
+        //------------------------------------------est
+        try {
+            Security.addProvider(new BouncyCastleProvider());
+            KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(
+                    "EC",
+                    "BC");
+
+
+            ECNamedCurveParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("sm2p256v1");
+            keyPairGenerator.initialize(ecSpec);
+            KeyPair keyPair = keyPairGenerator.generateKeyPair();
+
+            Signature signature = Signature.getInstance("SM3withSM2", "BC");
+            signature.initVerify(keyPair.getPublic());
+            signature.update("Hello, SM2".getBytes());
+            log.info("验证signature: {}", signature.verify(jsonObject.toString().getBytes()));
+
+            SignNotifyParam signNotifyParam = new SignNotifyParam();
+            BeanUtils.copyProperties(paramMap, signNotifyParam);
+            log.info("签约通知字符串:{} {}", contractNo, paramMap);
+
+            PublicKey publicKey = AesUtils.initializeSM3WithSM2PublicKey(
+                    payConfig.getNotifySecret());
+            // 创建 Signature 对象,指定验签算法为 SM3withSM2
+            Signature signature1 = Signature.getInstance("SM3withSM2");
+            // 初始化 Signature 对象,使用公钥进行验签
+            signature1.initVerify(publicKey);
+            // 更新待验签的数据
+            signature1.update(jsonObject.toString().getBytes());
+            // 进行验签并获取验证结果
+            boolean verifyResult = signature1.verify(authorization.getBytes());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
         return ResultContent.buildSuccess();
     }