|
|
@@ -7,12 +7,17 @@ import com.ydtech.constants.InsuranceEnum;
|
|
|
import com.ydtech.exception.SystemException;
|
|
|
import com.ydtech.modules.order.entity.api.huatai.HuaTaiBaseRequest;
|
|
|
import com.ydtech.modules.order.entity.api.huatai.HuaTaiBaseResponse;
|
|
|
+import com.ydtech.modules.order.entity.api.huatai.HuaTaiEncryptReq;
|
|
|
+import com.ydtech.modules.order.entity.api.huatai.HuaTaiEncryptRes;
|
|
|
import com.ydtech.modules.order.entity.api.huatai.constants.HuaTaiTransCode;
|
|
|
import com.ydtech.modules.order.entity.api.huatai.request.HuaTaiQuotedPriceRequest;
|
|
|
import com.ydtech.modules.order.entity.api.huatai.response.HuaTaiQuotedPriceResponse;
|
|
|
import com.ydtech.modules.order.entity.api.huatai.request.*;
|
|
|
import com.ydtech.modules.order.entity.api.huatai.response.*;
|
|
|
+import com.ydtech.modules.order.utils.AESUtilsWithDataBase;
|
|
|
import com.ydtech.modules.order.utils.InsuranceLog;
|
|
|
+import com.ydtech.utils.Base64Utils;
|
|
|
+import com.ydtech.utils.RSA.RSAUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
@@ -64,36 +69,34 @@ public class HuaTaiRequestApiComponents {
|
|
|
String busReqString = JSON.toJSONString(q, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullStringAsEmpty);
|
|
|
InsuranceLog.infoLog(InsuranceEnum.HTIC.getPinyin(), "\n\t---------> URl: {} \n---------> 请求参数:{}", url, busReqString);
|
|
|
// ----加密starting------------
|
|
|
- /* //1.先获取16位随机字符串 Key
|
|
|
+ //1.先获取16位随机字符串 Key
|
|
|
String key=generateRadomStr(8);
|
|
|
//2.使用Base64加密请求报文
|
|
|
- String base64ReqJson=Base64Utils.getBase64Encode(busReqString);
|
|
|
+ String base64ReqJson= Base64Utils.getBase64Encode(busReqString);
|
|
|
//3. 使用AES算法 秘钥Key 对 base64ReqJson加密
|
|
|
- String busiContent=AESUtilsWithDataBase.encryptECBPK5Hex(base64ReqJson, key);
|
|
|
+ String busiContent= AESUtilsWithDataBase.encryptECBPK5Base64(base64ReqJson, key);
|
|
|
//4.对Key 使用RSA算法进行加密
|
|
|
String accessToken="";
|
|
|
try{
|
|
|
- accessToken=RSAUtils.rsaEncrypt(key,properties.getHuaTaiPublicKey(),"UTF-8");
|
|
|
+ accessToken= RSAUtils.rsaEncrypt(key, properties.getHuaTaiPublicKey(),"utf-8");
|
|
|
}catch (Exception e){
|
|
|
throw new SystemException("RSA加密获取accessToken失败!");
|
|
|
}
|
|
|
HuaTaiEncryptReq encryptReq=new HuaTaiEncryptReq();
|
|
|
encryptReq.setInsuredCode(properties.getInsuredCode());
|
|
|
- encryptReq.setSourceCode("016");
|
|
|
+ encryptReq.setSourceCode(properties.getSourceCode());
|
|
|
encryptReq.setBusiContent(busiContent);
|
|
|
encryptReq.setAccessToken(accessToken);
|
|
|
String jsonString = JSON.toJSONString(encryptReq, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullStringAsEmpty);
|
|
|
InsuranceLog.infoLog(InsuranceEnum.HTIC.getPinyin(), "\n\t---------> 加密后的参数:{}", jsonString);
|
|
|
- HttpEntity<String> httpEntity = new HttpEntity<>(jsonString, httpHeaders);*/
|
|
|
+ HttpEntity<String> httpEntity = new HttpEntity<>(jsonString, httpHeaders);
|
|
|
//----加密endding------------
|
|
|
- //不加密
|
|
|
- HttpEntity<String> httpEntity = new HttpEntity<>(busReqString, httpHeaders);
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity(url, httpEntity, String.class);
|
|
|
String body = response.getBody();
|
|
|
|
|
|
InsuranceLog.infoLog(InsuranceEnum.HTIC.getPinyin(), "\n\t---------> 解密前的参数:{}", body);
|
|
|
// ------解密starting---------
|
|
|
- /*HuaTaiEncryptRes encryptRes=JSON.parseObject(body,HuaTaiEncryptRes.class);
|
|
|
+ HuaTaiEncryptRes encryptRes=JSON.parseObject(body,HuaTaiEncryptRes.class);
|
|
|
//1.通过自己的私钥对key进行解密
|
|
|
String resAccessToken="";
|
|
|
try{
|
|
|
@@ -102,14 +105,12 @@ public class HuaTaiRequestApiComponents {
|
|
|
throw new SystemException("RSA解密获取accessToken失败!");
|
|
|
}
|
|
|
//2.用key解密出出参报文
|
|
|
- String aseDecryptStr=AESUtilsWithDataBase.decryptECBPK5Hex(encryptRes.getBusiContent(),resAccessToken);
|
|
|
+ String aseDecryptStr=AESUtilsWithDataBase.decryptECBPK5Base64(encryptRes.getBusiContent(),resAccessToken);
|
|
|
//3.使用Base64解密最终返回报文
|
|
|
- String text = Base64Utils.getBase64Encode(aseDecryptStr);
|
|
|
- S t= JSON.parseObject(text, tClass);*/
|
|
|
+ String text = Base64Utils.getBase64Decode(aseDecryptStr);
|
|
|
// ------解密ending---------
|
|
|
- InsuranceLog.infoLog(InsuranceEnum.HTIC.getPinyin(), "\n\t---------> {}:{}", "响应参数", body);
|
|
|
- //不加密
|
|
|
- S t= JSON.parseObject(body, tClass);
|
|
|
+ InsuranceLog.infoLog(InsuranceEnum.HTIC.getPinyin(), "\n\t---------> {}:{}", "响应参数", text);
|
|
|
+ S t= JSON.parseObject(text, tClass);
|
|
|
if (ObjectUtils.isEmpty(t)) {
|
|
|
throw new SystemException("请求失败");
|
|
|
}
|