Commit e4df144b authored by 胡建龙's avatar 胡建龙

20220427 封装cmb.properties文件

parent b014a6af
...@@ -36,20 +36,14 @@ import java.util.stream.Collectors; ...@@ -36,20 +36,14 @@ import java.util.stream.Collectors;
@Service @Service
public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
private static final String url = "https://api.cmburl.cn:8065/polypay/v1.0/mchorders/qrcodeapply"; //UAT static{
String path = Thread.currentThread().getContextClassLoader().getResource("").getPath().substring(1);
private static final String closeUrl = "https://api.cmburl.cn:8065/polypay/v1.0/mchorders/qrcodeapply"; //UAT Properties pro = Utils.loadProp(path + "cmb.properties");
if (Objects.isNull(pro)){
private static final String queryUrl = "https://api.cmburl.cn:8065/polypay/v1.0/mchorders/orderquery"; LoggerFactory.getLogger(HclcCmbPolyServiceImpl.class).error("配置文件初始化异常");
//uat环境商户国密私钥
public static final String privateKey = "D5F2AFA24E6BA9071B54A8C9AD735F9A1DE9C4657FA386C09B592694BC118B38";
//uat环境招行国密公钥
public static final String publicKey = "MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE6Q+fktsnY9OFP+LpSR5Udbxf5zHCFO0PmOKlFNTxDIGl8jsPbbB/9ET23NV+acSz4FEkzD74sW2iiNVHRLiKHg==";
public static final String appId = "8ab74856-8772-45c9-96db-54cb30ab9f74";
public static final String appSecret = "5b96f20a-011f-4254-8be8-9a5ceb2f317f";
}
}
/*接口区分*/ /*接口区分*/
public static final String getQrCode = "GET_QR_CODE"; public static final String getQrCode = "GET_QR_CODE";
public static final String queryQrState = "QUERY_QR_STATE"; public static final String queryQrState = "QUERY_QR_STATE";
...@@ -69,21 +63,6 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -69,21 +63,6 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
public static final String orderCancel = "C"; public static final String orderCancel = "C";
public static final String orderPass = "P"; public static final String orderPass = "P";
@Value("${cmb.version}")
private String version;
@Value("${cmb.encoding}")
private String encoding;
@Value("${cmb.signMethod}")
private String signMethod;
/*币种,非必传,默认156人民币*/
@Value("${cmb.currencyCode}")
private String currencyCode;
@Value("${cmb.user.id}")
private String cmbUserId;
@Value("${cmb.mer.id}")
private String cmbMerId;
@Autowired @Autowired
private HlsEbankCcbTransactionMapper hlsEbankCcbTransactionMapper; private HlsEbankCcbTransactionMapper hlsEbankCcbTransactionMapper;
...@@ -97,6 +76,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -97,6 +76,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
private HlsEbankCmbTransqryMapper hlsEbankCmbTransqryMapper; private HlsEbankCmbTransqryMapper hlsEbankCmbTransqryMapper;
private Logger logger = LoggerFactory.getLogger(getClass()); private Logger logger = LoggerFactory.getLogger(getClass());
private static Properties pro = null;
@Override @Override
public JSONObject getQrcode(IRequest iRequest, JSONObject params) { public JSONObject getQrcode(IRequest iRequest, JSONObject params) {
...@@ -152,8 +132,8 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -152,8 +132,8 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
// 组apiSign加密Map // 组apiSign加密Map
Map<String, String> apiSign = new TreeMap<>(); Map<String, String> apiSign = new TreeMap<>();
apiSign.put("appid", appId); apiSign.put("appid", pro.getProperty("cmb.appId"));
apiSign.put("secret", appSecret); apiSign.put("secret", pro.getProperty("cmb.appSecret"));
apiSign.put("sign", signResultMap.get("sign")); apiSign.put("sign", signResultMap.get("sign"));
apiSign.put("timestamp", "" + currentTimeMills); apiSign.put("timestamp", "" + currentTimeMills);
...@@ -163,17 +143,17 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -163,17 +143,17 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
// 组request头部Map // 组request头部Map
Map<String, String> apiHeader = new HashMap<>(); Map<String, String> apiHeader = new HashMap<>();
apiHeader.put("appid", appId); apiHeader.put("appid", pro.getProperty("cmb.appId"));
apiHeader.put("timestamp", "" + currentTimeMills); apiHeader.put("timestamp", "" + currentTimeMills);
apiHeader.put("apisign", apiSignString); apiHeader.put("apisign", apiSignString);
//初始化日志 //初始化日志
HlsWsRequests hlsWsRequests = logInterfaceRequest(getQrCode, url, mapper.writeValueAsString(apiHeader), hlsEbankCcbTransaction.getTransactionId()); HlsWsRequests hlsWsRequests = logInterfaceRequest(getQrCode, pro.getProperty("qrCodeapplyUrl"), mapper.writeValueAsString(apiHeader), hlsEbankCcbTransaction.getTransactionId());
logger.info("发送收款码申请请求,请求参数: {}", mapper.writeValueAsString(apiHeader)); logger.info("发送收款码申请请求,请求参数: {}", mapper.writeValueAsString(apiHeader));
try { try {
// 发送HTTP post请求 // 发送HTTP post请求
response = Utils.postForEntity(url, signResult, apiHeader); response = Utils.postForEntity( pro.getProperty("cmb.qrCodeapplyUrl"), signResult, apiHeader);
//处理接口日志 //处理接口日志
logger.info("收款码申请返回结果:" + mapper.writeValueAsString(response)); logger.info("收款码申请返回结果:" + mapper.writeValueAsString(response));
...@@ -352,9 +332,9 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -352,9 +332,9 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
//生成招行扫码交易业务批次数据 //生成招行扫码交易业务批次数据
private HlsEbankCcbTransaction createTransaction(IRequest iRequest, Ld037 ld037) { private HlsEbankCcbTransaction createTransaction(IRequest iRequest, Ld037 ld037) {
HlsEbankCcbTransaction ccbTransaction = new HlsEbankCcbTransaction(); HlsEbankCcbTransaction ccbTransaction = new HlsEbankCcbTransaction();
ccbTransaction.setMerId("3089991701201D0"); ccbTransaction.setMerId(pro.getProperty("cmb.mer.id"));
ccbTransaction.setVersion("0.0.1"); ccbTransaction.setVersion(pro.getProperty("cmb.version"));
ccbTransaction.setUserId("N003574551"); ccbTransaction.setUserId(pro.getProperty("cmb.user.id"));
ccbTransaction.setStatus(transNew); ccbTransaction.setStatus(transNew);
ccbTransaction.setBankType("CMB"); ccbTransaction.setBankType("CMB");
ccbTransaction.setCount(1L); ccbTransaction.setCount(1L);
...@@ -383,9 +363,9 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -383,9 +363,9 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
String requestStr = null; String requestStr = null;
try { try {
//公共请求参数 //公共请求参数
requestPublicParams.put("version", version); //版本号,固定为0.0.1(必传字段) requestPublicParams.put("version", pro.getProperty("cmb.version")); //版本号,固定为0.0.1(必传字段)
requestPublicParams.put("encoding", encoding); //编码方式,固定为UTF-8(必传) requestPublicParams.put("encoding", pro.getProperty("cmb.encoding")); //编码方式,固定为UTF-8(必传)
requestPublicParams.put("signMethod", signMethod); //签名方法,固定为02,表示签名方式为国密(必传) requestPublicParams.put("signMethod", pro.getProperty("cmb.signMethod")); //签名方法,固定为02,表示签名方式为国密(必传)
//业务要素 //业务要素
Map<String, String> requestTransactionParams = new HashMap<>(); Map<String, String> requestTransactionParams = new HashMap<>();
...@@ -393,14 +373,14 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -393,14 +373,14 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
requestTransactionParams.put("orderId", hlsEbankCcbTransaction.getTransactionNumber()); //商户订单号(必传) requestTransactionParams.put("orderId", hlsEbankCcbTransaction.getTransactionNumber()); //商户订单号(必传)
requestTransactionParams.put("userId", hlsEbankCcbTransaction.getUserId()); //收银员 requestTransactionParams.put("userId", hlsEbankCcbTransaction.getUserId()); //收银员
// requestTransactionParams.put("termId", "00774411"); //终端号 // requestTransactionParams.put("termId", "00774411"); //终端号
requestTransactionParams.put("payValidTime", "900"); //支付有效时间,默认15分钟 requestTransactionParams.put("payValidTime", pro.getProperty("cmb.payValidTime")); //支付有效时间,默认15分钟
requestTransactionParams.put("notifyUrl", "http://sign.hitachics.com/core/api/public/cmb/get/qr/code/listen"); //交易通知地址(必传) requestTransactionParams.put("notifyUrl", pro.getProperty("cmb.notifyUrl")); //交易通知地址(必传)
requestTransactionParams.put("mchReserved", ld037.getId().toString()); //交易通知地址(必传) requestTransactionParams.put("mchReserved", ld037.getId().toString()); //保留字段
BigDecimal a1 = new BigDecimal(Double.toString(hlsEbankCcbTransaction.getAmount())); BigDecimal a1 = new BigDecimal(Double.toString(hlsEbankCcbTransaction.getAmount()));
BigDecimal b1 = new BigDecimal(Double.toString(100)); BigDecimal b1 = new BigDecimal(Double.toString(100));
requestTransactionParams.put("txnAmt", a1.multiply(b1).stripTrailingZeros().toPlainString()); //交易金额,单位为分(必传) requestTransactionParams.put("txnAmt", a1.multiply(b1).stripTrailingZeros().toPlainString()); //交易金额,单位为分(必传)
requestTransactionParams.put("currencyCode", currencyCode); //交易币种,默认156,目前只支持人民币(156) requestTransactionParams.put("currencyCode", pro.getProperty("cmb.currencyCode")); //交易币种,默认156,目前只支持人民币(156)
// requestTransactionParams.put("body", "聚合支付测试"); //商户号(必传) // requestTransactionParams.put("body", "聚合支付测试"); //商户号(必传)
//商户保留域 //商户保留域
...@@ -416,7 +396,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -416,7 +396,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
//对待加签内容进行排序拼接 //对待加签内容进行排序拼接
String signContent = SignatureUtil.getSignContent(requestPublicParams); String signContent = SignatureUtil.getSignContent(requestPublicParams);
//加签 //加签
requestPublicParams.put("sign", SM2Util.sm2Sign(signContent, privateKey)); requestPublicParams.put("sign", SM2Util.sm2Sign(signContent, pro.getProperty("cmb.privateKey")));
requestStr = mapper.writeValueAsString(requestPublicParams); requestStr = mapper.writeValueAsString(requestPublicParams);
logger.info("收款码申请加签后的报文内容:" + requestStr); logger.info("收款码申请加签后的报文内容:" + requestStr);
...@@ -437,7 +417,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -437,7 +417,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
Map<String, String> responseBodyMap = objectMapper.readValue(string, Map.class); Map<String, String> responseBodyMap = objectMapper.readValue(string, Map.class);
String sign = responseBodyMap.remove("sign"); String sign = responseBodyMap.remove("sign");
String contentStr = SignatureUtil.getSignContent(responseBodyMap); String contentStr = SignatureUtil.getSignContent(responseBodyMap);
boolean result = SM2Util.sm2Check(contentStr, sign, publicKey); boolean result = SM2Util.sm2Check(contentStr, sign, pro.getProperty("cmb.publicKey"));
if (result) { if (result) {
System.out.println("报文验签成功!"); System.out.println("报文验签成功!");
...@@ -452,29 +432,6 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -452,29 +432,6 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
} }
} }
private Properties loadProp(String propPath) {
Properties props = new Properties();
FileInputStream is = null;
try {
is = new FileInputStream(propPath);
props.load(is);
return props;
} catch (Exception var13) {
LogUtil.writeErrorLog("加载配置文件失败", var13);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException var12) {
;
}
}
}
return null;
}
public HlsWsRequests logInterfaceRequest(String functionName, String url, String request, Long pkValue) { public HlsWsRequests logInterfaceRequest(String functionName, String url, String request, Long pkValue) {
HlsWsRequests hlsWsRequests = new HlsWsRequests(); HlsWsRequests hlsWsRequests = new HlsWsRequests();
...@@ -510,7 +467,6 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -510,7 +467,6 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
//返回结果标志 //返回结果标志
String resultType = null; String resultType = null;
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
final String url = "https://api.cmburl.cn:8065/polypay/v1.0/mchorders/orderquery" ;
HlsEbankCmbTransqry hlsEbankCmbTransqry = new HlsEbankCmbTransqry(); HlsEbankCmbTransqry hlsEbankCmbTransqry = new HlsEbankCmbTransqry();
//去ld037中查找对应的记录的receiptcfmstatus, //去ld037中查找对应的记录的receiptcfmstatus,
if (Objects.isNull(params.get("recamt_id"))) { if (Objects.isNull(params.get("recamt_id"))) {
...@@ -554,8 +510,8 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -554,8 +510,8 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
// 组apiSign加密Map // 组apiSign加密Map
Map<String,String> apiSign = new TreeMap<>(); Map<String,String> apiSign = new TreeMap<>();
apiSign.put("appid", appId); apiSign.put("appid", pro.getProperty("cmb.appId"));
apiSign.put("secret", appSecret); apiSign.put("secret", pro.getProperty("cmb.appSecret"));
apiSign.put("sign", signResultMap.get("sign")); apiSign.put("sign", signResultMap.get("sign"));
apiSign.put("timestamp", "" + currentTimeMills); apiSign.put("timestamp", "" + currentTimeMills);
...@@ -565,14 +521,14 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -565,14 +521,14 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
// 组request头部Map // 组request头部Map
Map<String, String> apiHeader = new HashMap<>(); Map<String, String> apiHeader = new HashMap<>();
apiHeader.put("appid", appId); apiHeader.put("appid", pro.getProperty("cmb.appId"));
apiHeader.put("timestamp", "" + currentTimeMills); apiHeader.put("timestamp", "" + currentTimeMills);
apiHeader.put("apisign", apiSignString); apiHeader.put("apisign", apiSignString);
hlsWsRequests = logInterfaceRequest(queryQrState, url, mapper.writeValueAsString(apiHeader), hlsEbankCcbTransaction.getTransactionId()); hlsWsRequests = logInterfaceRequest(queryQrState, pro.getProperty("cmb.orderQueryUrl"), mapper.writeValueAsString(apiHeader), hlsEbankCcbTransaction.getTransactionId());
//发送http请求 //发送http请求
responseMap = Utils.postForEntity(url,signResult,apiHeader); responseMap = Utils.postForEntity(queryQrState,signResult,apiHeader);
if( null == responseMap){ if( null == responseMap){
resultType="3"; resultType="3";
logger.info("响应的内容为空"); logger.info("响应的内容为空");
...@@ -659,9 +615,9 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -659,9 +615,9 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
String requestStr = null; String requestStr = null;
try { try {
//公共请求参数 //公共请求参数
requestPublicParams.put("version", "0.0.1"); //版本号,固定为0.0.1(必传字段) requestPublicParams.put("version", pro.getProperty("cmb.version")); //版本号,固定为0.0.1(必传字段)
requestPublicParams.put("encoding", "UTF-8"); //编码方式,固定为UTF-8(必传) requestPublicParams.put("encoding", pro.getProperty("cmb.encoding")); //编码方式,固定为UTF-8(必传)
requestPublicParams.put("signMethod", "02"); //签名方法,固定为02,表示签名方式为国密(必传) requestPublicParams.put("signMethod", pro.getProperty("cmb.signMethod")); //签名方法,固定为02,表示签名方式为国密(必传)
//业务要素 //业务要素
Map<String, String> requestTransactionParams = new HashMap<>(); Map<String, String> requestTransactionParams = new HashMap<>();
requestTransactionParams.put("merId", hlsEbankCcbTransaction.getMerId()); //商户号(必传) requestTransactionParams.put("merId", hlsEbankCcbTransaction.getMerId()); //商户号(必传)
...@@ -677,7 +633,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -677,7 +633,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
//对待加签内容进行排序拼接 //对待加签内容进行排序拼接
String signContent= SignatureUtil.getSignContent(requestPublicParams); String signContent= SignatureUtil.getSignContent(requestPublicParams);
//加签 //加签
requestPublicParams.put("sign", SM2Util.sm2Sign(signContent, privateKey)); requestPublicParams.put("sign", SM2Util.sm2Sign(signContent, pro.getProperty("cmb.privateKey")));
requestStr = mapper.writeValueAsString(requestPublicParams); requestStr = mapper.writeValueAsString(requestPublicParams);
...@@ -700,13 +656,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -700,13 +656,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
* @return * @return
*/ */
private HlsEbankCcbTransaction setEbankTransactionQR(HlsEbankCcbTransaction hlsEbankCcbTransaction, Map<String, String> response, String type) { private HlsEbankCcbTransaction setEbankTransactionQR(HlsEbankCcbTransaction hlsEbankCcbTransaction, Map<String, String> response, String type) {
// C - 订单已关闭 //
// D - 交易已撤销
// P - 交易在进行
// F - 交易失败
// S - 交易成功
// R - 转入退款
//接口请求成功 //接口请求成功
if ("1".equalsIgnoreCase(type)) { if ("1".equalsIgnoreCase(type)) {
if (response.get("tradeState").equalsIgnoreCase("P")){ if (response.get("tradeState").equalsIgnoreCase("P")){
...@@ -811,9 +761,9 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -811,9 +761,9 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
Map<String, String> respData = new HashMap<>(); Map<String, String> respData = new HashMap<>();
//设置响应数据 //设置响应数据
respData.put("version", "0.0.1");//版本号,固定为0.0.1(必传) respData.put("version", pro.getProperty("cmb.version"));//版本号,固定为0.0.1(必传)
respData.put("encoding", "UTF-8");//编码方式,固定为UTF-8(必传) respData.put("encoding", pro.getProperty("cmb.encoding"));//编码方式,固定为UTF-8(必传)
respData.put("signMethod", "02");//签名方法,固定为02,国密 respData.put("signMethod", pro.getProperty("cmb.signMethod"));//签名方法,固定为02,国密
try { try {
respData.put("returnCode", "SUCCESS"); //SUCCESS表示商户接收通知成功并校验成功 respData.put("returnCode", "SUCCESS"); //SUCCESS表示商户接收通知成功并校验成功
...@@ -832,7 +782,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -832,7 +782,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
//对待加签内容进行排序拼接 //对待加签内容进行排序拼接
String contentStr = SignatureUtil.getSignContent(resultMap); String contentStr = SignatureUtil.getSignContent(resultMap);
//验证签名-使用招行公钥进行验签 //验证签名-使用招行公钥进行验签
boolean flag = SM2Util.sm2Check(contentStr,sign, publicKey); boolean flag = SM2Util.sm2Check(contentStr,sign, pro.getProperty("cmb.publicKey"));
if (!flag) { if (!flag) {
//验签失败 //验签失败
System.out.println("验签失败"); System.out.println("验签失败");
...@@ -851,7 +801,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -851,7 +801,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
hlsEbankCcbTransaction.setStatus(tranSuccess); hlsEbankCcbTransaction.setStatus(tranSuccess);
hlsEbankCcbTransaction.setOrderStatus("S"); hlsEbankCcbTransaction.setOrderStatus("S");
hlsEbankCcbTransactionMapper.updateByPrimaryKeySelective(hlsEbankCcbTransaction); hlsEbankCcbTransactionMapper.updateByPrimaryKeySelective(hlsEbankCcbTransaction);
hlsWsRequestsMapper.updateByPrimaryKey(logInterfaceRequest(queryQrState, url, new ObjectMapper().writeValueAsString(respData), hlsEbankCcbTransaction.getTransactionId())); hlsWsRequestsMapper.updateByPrimaryKey(logInterfaceRequest(queryQrState, pro.getProperty("cmb.server"), new ObjectMapper().writeValueAsString(respData), hlsEbankCcbTransaction.getTransactionId()));
respData.put("respCode", "SUCCESS");//业务错误码,成功为SUCCESS,失败为FAIL respData.put("respCode", "SUCCESS");//业务错误码,成功为SUCCESS,失败为FAIL
/*如果处理自身业务逻辑发生错误,返回 /*如果处理自身业务逻辑发生错误,返回
respData.put("respCode","FAIL"); respData.put("respCode","FAIL");
...@@ -860,7 +810,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -860,7 +810,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
//对待加签内容进行排序拼接 //对待加签内容进行排序拼接
String signContent = SignatureUtil.getSignContent(respData); String signContent = SignatureUtil.getSignContent(respData);
//加签-使用商户私钥加签 //加签-使用商户私钥加签
respData.put("sign", SM2Util.sm2Sign(signContent, privateKey)); respData.put("sign", SM2Util.sm2Sign(signContent, pro.getProperty("cmb.privateKey")));
System.out.println("加签成功"); System.out.println("加签成功");
return respData; return respData;
} catch (Exception e) { } catch (Exception e) {
...@@ -906,8 +856,8 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -906,8 +856,8 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
// 组apiSign加密Map // 组apiSign加密Map
Map<String,String> apiSign = new TreeMap<>(); Map<String,String> apiSign = new TreeMap<>();
apiSign.put("appid", appId); apiSign.put("appid", pro.getProperty("cmb.appId"));
apiSign.put("secret", appSecret); apiSign.put("secret", pro.getProperty("cmb.privateKey"));
apiSign.put("sign", signResultMap.get("sign")); apiSign.put("sign", signResultMap.get("sign"));
apiSign.put("timestamp", "" + currentTimeMills); apiSign.put("timestamp", "" + currentTimeMills);
...@@ -917,7 +867,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -917,7 +867,7 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
// 组request头部Map // 组request头部Map
apiHeader = new HashMap<>(); apiHeader = new HashMap<>();
apiHeader.put("appid", appId); apiHeader.put("appid", pro.getProperty("cmb.appId"));
apiHeader.put("timestamp", "" + currentTimeMills); apiHeader.put("timestamp", "" + currentTimeMills);
apiHeader.put("apisign", apiSignString); apiHeader.put("apisign", apiSignString);
...@@ -929,8 +879,8 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -929,8 +879,8 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
} }
HlsWsRequests hlsWsRequests = null; HlsWsRequests hlsWsRequests = null;
try { try {
hlsWsRequests = logInterfaceRequest(queryQrState, url, mapper.writeValueAsString(apiHeader), hlsEbankCcbTransaction.getTransactionId()); hlsWsRequests = logInterfaceRequest(closeOrder, pro.getProperty("cmb.closeUrl"), mapper.writeValueAsString(apiHeader), hlsEbankCcbTransaction.getTransactionId());
Map<String,String> responseMap = Utils.postForEntity(closeUrl,signResult,apiHeader); Map<String,String> responseMap = Utils.postForEntity(pro.getProperty("cmb.closeUrl"),signResult,apiHeader);
//处理响应报文 //处理响应报文
Boolean checkResponse = checkSign(mapper.writeValueAsString(responseMap)); Boolean checkResponse = checkSign(mapper.writeValueAsString(responseMap));
//数据验签成功 //数据验签成功
...@@ -1020,5 +970,4 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService { ...@@ -1020,5 +970,4 @@ public class HclcCmbPolyServiceImpl implements HclcCmbPolyService {
} }
return result; return result;
} }
} }
package com.hand.app.cmb.util; package com.hand.app.cmb.util;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.chinapay.secss.LogUtil;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
...@@ -18,9 +19,7 @@ import org.springframework.http.converter.StringHttpMessageConverter; ...@@ -18,9 +19,7 @@ import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import javax.net.ssl.*; import javax.net.ssl.*;
import java.io.BufferedReader; import java.io.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException; import java.security.KeyManagementException;
...@@ -39,13 +38,16 @@ public class Utils { ...@@ -39,13 +38,16 @@ public class Utils {
try { try {
// Create a trust manager that does not validate certificate chains // Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() { public X509Certificate[] getAcceptedIssuers() {
return null; return null;
} }
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType) { public void checkClientTrusted(X509Certificate[] certs, String authType) {
} }
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) { public void checkServerTrusted(X509Certificate[] certs, String authType) {
} }
} }
...@@ -57,6 +59,7 @@ public class Utils { ...@@ -57,6 +59,7 @@ public class Utils {
// Create all-trusting host name verifier // Create all-trusting host name verifier
HostnameVerifier allHostsValid = new HostnameVerifier() { HostnameVerifier allHostsValid = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) { public boolean verify(String hostname, SSLSession session) {
return true; return true;
} }
...@@ -168,4 +171,33 @@ public class Utils { ...@@ -168,4 +171,33 @@ public class Utils {
return paramMap; return paramMap;
} }
/**
* 加载properties配置文件
* @param propPath
* @return
*/
public static Properties loadProp(String propPath) {
Properties props = new Properties();
FileInputStream is = null;
try {
is = new FileInputStream(propPath);
props.load(is);
return props;
} catch (Exception var13) {
LogUtil.writeErrorLog("加载配置文件失败", var13);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException var12) {
;
}
}
}
return null;
}
} }
#招行获取二维码接口
cmb.qrCodeapplyUrl=https://api.cmburl.cn:8065/polypay/v1.0/mchorders/qrcodeapply
#招行查询订单状态接口
cmb.orderQueryUrl=https://api.cmburl.cn:8065/polypay/v1.0/mchorders/orderquery
#招行关闭订单接口
cmb.closeUrl=https://api.cmburl.cn:8065/polypay/v1.0/mchorders/qrcodeapply
#uat环境商户国密私钥
cmb.privateKey=D5F2AFA24E6BA9071B54A8C9AD735F9A1DE9C4657FA386C09B592694BC118B38
#uat环境招行国密公钥
cmb.publicKey=MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE6Q+fktsnY9OFP+LpSR5Udbxf5zHCFO0PmOKlFNTxDIGl8jsPbbB/9ET23NV+acSz4FEkzD74sW2iiNVHRLiKHg==
cmb.appId=8ab74856-8772-45c9-96db-54cb30ab9f74
cmb.appSecret=5b96f20a-011f-4254-8be8-9a5ceb2f317f
cmb.server=cmbServer
cmb.version=0.0.1
cmb.encoding=UTF-8
cmb.signMethod=02
cmb.currencyCode=156
cmb.user.id=N003574551
cmb.mer.id=3089991701201D0
cmb.payValidTime=900
cmb.notifyUrl=http://sign.hitachics.com/core/api/public/cmb/get/qr/code/listen
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment