package com.ydtech.modules.ttqf; import cn.hutool.extra.spring.SpringUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.ipaynow.jiaxin.SdkException; import com.ipaynow.jiaxin.util.AESUtils; import com.ipaynow.jiaxin.util.RSAUtils; import com.ipaynow.jiaxin.util.StringUtils; import lombok.extern.slf4j.Slf4j; import java.util.HashMap; import java.util.Map; @Slf4j public class TtqfDecrypt { /** * 解密通知业务报文 * @param enc * @return */ public static String parse(String enc) { TTFQConfig ttfqConfig = SpringUtil.getBean(TTFQConfig.class); JSONObject encObj = JSON.parseObject(enc); //1. 解密AES秘钥 String aes = null; try { aes = RSAUtils.decrypt(encObj.getString("aes"), ttfqConfig.getMchPrivateKey()); } catch (Exception e) { log.error("天天企赋通知-AES秘钥解密错误", e); throw new SdkException(e); } String bizRequest = null; try { bizRequest = AESUtils.decrypt(encObj.getString("reqData"), aes); } catch (Exception e) { log.error("天天企赋通知-业务报文解密错误", e); throw new SdkException(e); } Map rtMap = new HashMap<>(); rtMap.put("reqData", bizRequest); rtMap.put("mchId", encObj.getString("mchId")); rtMap.put("reqId", encObj.getString("reqId")); rtMap.put("reqTime",encObj.getString("reqTime")); rtMap.put("signType", "RSA"); rtMap.put("aes", aes); rtMap.put("version", "1.0"); // 8. 构造待验签字符串 String dataForm = StringUtils.buildDataForm(rtMap); // 9. 签名结果 boolean check = RSAUtils.verifySign(dataForm, encObj.getString("sign"), ttfqConfig.getPlatformPublicKey()); if(check) { return bizRequest; } else { return null; } } }