From: Xia Kaixiang Date: Tue, 30 Jul 2019 01:23:09 +0000 (+0800) Subject: 卡管对接加密算法修改 X-Git-Tag: 1.0.1^2~59 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=8201e071b4ffa29441339b43768196c2e280e132;p=epayment%2Ffood_payapi.git 卡管对接加密算法修改 --- diff --git a/payapi/src/main/java/com/supwisdom/dlpay/util/DesUtil.java b/payapi/src/main/java/com/supwisdom/dlpay/util/DesUtil.java new file mode 100644 index 00000000..912006f6 --- /dev/null +++ b/payapi/src/main/java/com/supwisdom/dlpay/util/DesUtil.java @@ -0,0 +1,51 @@ +package com.supwisdom.dlpay.util; + +import javax.crypto.*; +import javax.crypto.spec.DESKeySpec; +import javax.crypto.spec.IvParameterSpec; + +public class DesUtil { + + public static String decode(String message, String key) throws Exception { + DESKeySpec desKeySpec = new DESKeySpec(key.getBytes("UTF-8")); + SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); + SecretKey secretKey = keyFactory.generateSecret(desKeySpec); + + Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); + cipher.init(Cipher.DECRYPT_MODE, secretKey); + byte[] retByte = cipher.doFinal(convertHexString(message)); + return new String(retByte, "UTF-8"); + } + + public static String encode(String message, String key) throws Exception { + DESKeySpec desKeySpec = new DESKeySpec(key.getBytes("UTF-8")); + SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); + SecretKey secretKey = keyFactory.generateSecret(desKeySpec); + + Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); + cipher.init(Cipher.ENCRYPT_MODE, secretKey); + byte[] retByte = cipher.doFinal(message.getBytes("UTF-8")); + return toHexString(retByte); + } + + public static byte[] convertHexString(String ss) { + byte digest[] = new byte[ss.length() / 2]; + for (int i = 0; i < digest.length; i++) { + String byteString = ss.substring(2 * i, 2 * i + 2); + int byteValue = Integer.parseInt(byteString, 16); + digest[i] = (byte) byteValue; + } + return digest; + } + + public static String toHexString(byte b[]) { + StringBuffer hexString = new StringBuffer(); + for (int i = 0; i < b.length; i++) { + String plainText = Integer.toHexString(0xff & b[i]); + if (plainText.length() < 2) + plainText = "0" + plainText; + hexString.append(plainText); + } + return hexString.toString(); + } +} diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/advices.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/advices.kt index ecc5f3b0..1fda9f02 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/advices.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/advices.kt @@ -126,9 +126,10 @@ class RestControllerAspect { SecurityContextHolder.getContext().authentication.name))) { throw RequestParamCheckException("参数签名错误") } - } else { - throw TransactionCheckException(TradeErrorCode.REQUEST_PARAM_EEROR, "请求参数实体位置错误") } +// else { +// throw TransactionCheckException(TradeErrorCode.REQUEST_PARAM_EEROR, "请求参数实体位置错误") +// } val result = joinPoint.proceed() logger.debug(result.toString()) diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/bean/api_request_param.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/bean/api_request_param.kt index 739b2c3a..2b19d6f8 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/bean/api_request_param.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/bean/api_request_param.kt @@ -4,7 +4,7 @@ import com.google.gson.Gson import com.google.gson.reflect.TypeToken import com.supwisdom.dlpay.api.exception.RequestParamCheckException import com.supwisdom.dlpay.framework.util.* -import com.supwisdom.dlpay.util.DESedeUtil +import com.supwisdom.dlpay.util.DesUtil class DaliDatasyncParam { var app_id: String = "" @@ -44,7 +44,7 @@ class DaliDatasyncParam { fun decData(deskey: String): ArrayList { try { val listType = object : TypeToken>() {}.type - val decstr = DESedeUtil.getInstance(deskey).decode(data) + val decstr = DesUtil.decode(data, deskey) return Gson().fromJson(decstr, listType) } catch (e: Exception) { throw RequestParamCheckException("数据解密失败!") @@ -72,10 +72,10 @@ class DaliDatasyncDetail { } } -class DaliDatasyncErrorDetail{ - var cardno:String="" - var errcode:String="" - var errmsg:String="" +class DaliDatasyncErrorDetail { + var cardno: String = "" + var errcode: String = "" + var errmsg: String = "" } diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/dali_datasync_api_controller.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/dali_datasync_api_controller.kt index 5f08635c..248c8310 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/dali_datasync_api_controller.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/dali_datasync_api_controller.kt @@ -14,6 +14,7 @@ import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* @RequestMapping("/api/common") +@RestController class DaliDatasyncApiController { @Autowired lateinit var systemUtilService: SystemUtilService @@ -26,7 +27,6 @@ class DaliDatasyncApiController { * ============================================================================ * */ @PostMapping("/datasync") - @ResponseBody fun daliDatasync(@RequestBody param: DaliDatasyncParam): ResponseEntity { try { param.checkParam() diff --git a/payapi/src/main/resources/templates/system/param/sourcetypeconfig.html b/payapi/src/main/resources/templates/system/param/sourcetypeconfig.html index 4058462f..2924cdbe 100644 --- a/payapi/src/main/resources/templates/system/param/sourcetypeconfig.html +++ b/payapi/src/main/resources/templates/system/param/sourcetypeconfig.html @@ -8,10 +8,10 @@
-
+
-
+
diff --git a/payapi/src/main/resources/templates/system/shop/configpara.html b/payapi/src/main/resources/templates/system/shop/configpara.html index 762778c9..70dc1b57 100644 --- a/payapi/src/main/resources/templates/system/shop/configpara.html +++ b/payapi/src/main/resources/templates/system/shop/configpara.html @@ -10,10 +10,10 @@
-
+
-
+
diff --git a/ynrcc-agent/src/main/java/com/supwisdom/agent/api/bean/CheckFileHeader.java b/ynrcc-agent/src/main/java/com/supwisdom/agent/api/bean/CheckFileHeader.java new file mode 100644 index 00000000..d29bc097 --- /dev/null +++ b/ynrcc-agent/src/main/java/com/supwisdom/agent/api/bean/CheckFileHeader.java @@ -0,0 +1,73 @@ +package com.supwisdom.agent.api.bean; + +/** + * 第一行:总笔数|总金额|代扣总笔数|代扣总金额|退款总笔数|退款总金额| + */ +public class CheckFileHeader { + public static final String[] chkFileHeaderColumnList = new String[]{"totalCount", "totalAmount", "payCount", + "payAmount", "refundCount", "refundAmount"}; + + private int totalCount; + private int totalAmount; + private int payCount; + private int payAmount; + private int refundCount; + private int refundAmount; + + public static String[] getChkFileHeaderColumnList() { + return chkFileHeaderColumnList; + } + + public int getTotalCount() { + return totalCount; + } + + public void setTotalCount(int totalCount) { + this.totalCount = totalCount; + } + + public int getTotalAmount() { + return totalAmount; + } + + public void setTotalAmount(int totalAmount) { + this.totalAmount = totalAmount; + } + + public int getPayCount() { + return payCount; + } + + public void setPayCount(int payCount) { + this.payCount = payCount; + } + + public int getPayAmount() { + return payAmount; + } + + public void setPayAmount(int payAmount) { + this.payAmount = payAmount; + } + + public int getRefundCount() { + return refundCount; + } + + public void setRefundCount(int refundCount) { + this.refundCount = refundCount; + } + + public int getRefundAmount() { + return refundAmount; + } + + public void setRefundAmount(int refundAmount) { + this.refundAmount = refundAmount; + } + + public boolean isZero() { + return (totalAmount == 0 && totalCount == 0 + && payAmount == 0 && payCount == 0 && refundAmount == 0 && refundCount == 0); + } +} diff --git a/ynrcc-agent/src/main/java/com/supwisdom/agent/api/controller/YnrccApiController.java b/ynrcc-agent/src/main/java/com/supwisdom/agent/api/controller/YnrccApiController.java index af776874..b0a6e76d 100644 --- a/ynrcc-agent/src/main/java/com/supwisdom/agent/api/controller/YnrccApiController.java +++ b/ynrcc-agent/src/main/java/com/supwisdom/agent/api/controller/YnrccApiController.java @@ -4,6 +4,7 @@ import com.supwisdom.agent.Util.BussinessException; import com.supwisdom.agent.Util.DlpayUtil; import com.supwisdom.agent.Util.ErrorCode; import com.supwisdom.agent.Util.StringUtil; +import com.supwisdom.agent.api.bean.CheckFileHeader; import com.supwisdom.agent.api.bean.CheckFileLine; import com.supwisdom.agent.api.bean.DlpayReq; import com.supwisdom.agent.api.bean.DlpayResp; @@ -42,7 +43,7 @@ public class YnrccApiController { Constant.COL_REFNO, Constant.COL_AGENT_REFNO, Constant.COL_PAYERID, Constant.COL_PAYEEID, Constant.COL_AGENT_DATE, Constant.COL_AMOUNT, Constant.COL_SUMMARY}; - private static final String chkFileDelimiter = "|"; + private static final String chkFileDelimiter = "\\|"; private static final String FLAG_WITHHOLD = "BC5512"; private static final String FLAG_REFUND = "BC5513"; @@ -404,6 +405,7 @@ public class YnrccApiController { data.put(column[col], fields[col]); } BeanUtils.populate(bean, data); + return; } catch (InvocationTargetException | IllegalAccessException e) { e.printStackTrace(); } @@ -500,72 +502,4 @@ public class YnrccApiController { } } - - /** - * 第一行:总笔数|总金额|代扣总笔数|代扣总金额|退款总笔数|退款总金额| - */ - private static class CheckFileHeader { - static final String[] chkFileHeaderColumnList = new String[]{"totalCount", "totalAmount", "payCount", - "payAmount", "refundCount", "refundAmount"}; - - private int totalCount; - private int totalAmount; - private int payCount; - private int payAmount; - private int refundCount; - private int refundAmount; - - int getTotalCount() { - return totalCount; - } - - void setTotalCount(int totalCount) { - this.totalCount = totalCount; - } - - int getTotalAmount() { - return totalAmount; - } - - void setTotalAmount(int totalAmount) { - this.totalAmount = totalAmount; - } - - int getPayCount() { - return payCount; - } - - void setPayCount(int payCount) { - this.payCount = payCount; - } - - int getPayAmount() { - return payAmount; - } - - void setPayAmount(int payAmount) { - this.payAmount = payAmount; - } - - int getRefundCount() { - return refundCount; - } - - void setRefundCount(int refundCount) { - this.refundCount = refundCount; - } - - int getRefundAmount() { - return refundAmount; - } - - void setRefundAmount(int refundAmount) { - this.refundAmount = refundAmount; - } - - boolean isZero() { - return (totalAmount == 0 && totalCount == 0 - && payAmount == 0 && payCount == 0 && refundAmount == 0 && refundCount == 0); - } - } }