|
|
@@ -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();
|
|
|
}
|
|
|
|