|
@@ -7,8 +7,7 @@ import com.caimei.modules.coupon.entity.CmCouponOrderRecord;
|
|
import com.caimei.modules.miniprogram.utils.DateUtils;
|
|
import com.caimei.modules.miniprogram.utils.DateUtils;
|
|
import com.caimei.modules.order.dao.*;
|
|
import com.caimei.modules.order.dao.*;
|
|
import com.caimei.modules.order.entity.*;
|
|
import com.caimei.modules.order.entity.*;
|
|
-import com.caimei.modules.order.utils.NewOrderStatus;
|
|
|
|
-import com.caimei.modules.order.utils.PayUtils;
|
|
|
|
|
|
+import com.caimei.modules.order.utils.*;
|
|
import com.caimei.modules.product.dao.CmPromotionDao;
|
|
import com.caimei.modules.product.dao.CmPromotionDao;
|
|
import com.caimei.modules.product.dao.CmSecondHandDetailDao;
|
|
import com.caimei.modules.product.dao.CmSecondHandDetailDao;
|
|
import com.caimei.modules.product.entity.CmPromotion;
|
|
import com.caimei.modules.product.entity.CmPromotion;
|
|
@@ -33,11 +32,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.ui.Model;
|
|
-
|
|
|
|
|
|
+import org.apache.commons.httpclient.HttpStatus;
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
import static com.caimei.modules.miniprogram.utils.UploadPicUtils.saveImageToServer;
|
|
import static com.caimei.modules.miniprogram.utils.UploadPicUtils.saveImageToServer;
|
|
@@ -729,70 +729,121 @@ public class CmReturnedPurchaseService extends CrudService<CmReturnedPurchaseDao
|
|
* @param orderId
|
|
* @param orderId
|
|
*/
|
|
*/
|
|
private void theOnlineRefund(Integer orderId) throws Exception {
|
|
private void theOnlineRefund(Integer orderId) throws Exception {
|
|
- //商户标识
|
|
|
|
- String merAccount = "aa9aee6a148843a6a9e4ea117df4454b";
|
|
|
|
- //私钥,商户密钥
|
|
|
|
- String merKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAM0qCTZFdi1I59/Jeis+8KVhzSNhsRrKiOlHazIVyxNLzUQvFpWN5PlfVKlnJToorURTStfjAv01HD0Z4ZvMauuHhDT0bptiDln928Ld6SzX889X2nsCxl0Q+WzrkFsnT6gotvGnTeQGUgbBV3SQD3IUOwRwxoWYbrZqxtqHFxqRAgMBAAECgYEAvsHx9MMbAToDVmEXtXP8/lh0Cwy/RgDA0d30voni2pslTNtXbVCUcIUBy8y6oVvG1nt3YEmTsuiZy/nvehPT6GV1Gqj8T6lqWQ8KQKsDGlubvh23tzNM90me2TLZEPdNqC5CPRrwYrjght4BXgzu7s2+5FpeYCob1gVNi+w0Jz0CQQD0dXb9Oez+Ybnxb3rCghGWM6cxi8fsqk6MuKaleg53qfXrkgAVH78faeWzRaeSbVOh5+Z9kX5HUeynfM7E/f4nAkEA1tmnvJp4JQaouO1Trzbnkhowjea5daK/tDE8K0hIMHUjAw+c1QTteGOVGBFBHWPkUwkSCd2HKmk4URkp/snMhwJAO32+qF+Jclq8EqqLmHxo5UHKxX7793d2yD5Dp++tR6fgBiUwyfNA4tc1pEwmPLdIbBVwfUyEC70/N39jHoOlbwI/dX6SPJI9IgKCQp+HJEriWQP5iaCjy7E1JVXHkeP1lop4mzPukJAhTbUn1AGbmncGZmKPetWrFYZ1ReR9EtlJAkEA2kBmARWyOTt8fbikImuHr65M+BDgD+2fkuDb5+tqJljNmSqAIRRwcXj1Je6vkzlDJuSw3wlG6iliFtwe0cq7+w==";
|
|
|
|
-
|
|
|
|
- //维沙商户标识
|
|
|
|
- String wsMerAccount = "f8248975517a4feab79cac9d7d453663";
|
|
|
|
- //维沙私钥,商户密钥
|
|
|
|
- String wsMerKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAI4Rb9HBUbjzEsfCOWUsogq8pOoxcSGcL1WFQfqHY1Ul2UwVO5daQtS1pxyM8gKPvvcxNsxz5+wdzb7/cX+SewdF8GbTO2LQIMsOAvtQszsMW8+Hg3J3QFPCHUGh+Q//JXWTFu/GaIlBrpmc7qnB+OMmP315taf5vAmAxC7OzohlAgMBAAECgYBgDiwTn2j46uicxZZ28MmTBt9eNRWvyuE6KoJkuJuR26hjR8vl1rJvDW8y351V3AkbK1xIumlp/PC6ng4IWmrxgu9zuGu+qpb4BdcarS1RMcnpjynCKYO0BnMZBcFrKzWiD6IyZIlLIlJHIDC0mXI/x5V9zG9rL4Tkm4mQPRhzlQJBAPUPledDZXTp2ovvMdL7baI+QVs+tfBqdIdcCgSoEhFh2T/dNVMpBVIjH2D6jTwL94tvWRchMwjXNUSWTRYMH2sCQQCUaOjFeLhSI/gK+f/yXNX/wP6WjXFE9/vuNEaxuaYja2Ia8OwLYoFAYQvKrxLGoHkiI9qKGfqv2h91nF/w/ftvAkBCZA2NkNG8wdpGjO/no9xI1yrnqG6sCns1bLb+GfaDJQoxZiGbPQLHBOLsaBS5Ttiquujc/k6QN5Wj1kBeF7yvAkEAgvWcSfz/8YPJ8q2u3EhtknTUcze29xw5FHbO1y+yWlj8xjdIo7c1xQCd7inVUK70lVq8Etdf7mN1FUx7IOaOQwJAaAl8RFO8zXKy9CdiSsC+2N2qUGLDVOiOJL70Ulh1WxnbLPbwZWCifUu3/UU798dNiZ5Gd06XYinL7lonWpOiEg==";
|
|
|
|
-
|
|
|
|
- //呵呵商户标识
|
|
|
|
- String heHeMerAccount = "150a5459416b4046b9153c1cd442e397";
|
|
|
|
- //呵呵 私钥,商户密钥
|
|
|
|
- String heHeMerKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAIggpVq2S1JLH0szxurEgVTz4JTpoyO6/YreVP3xl2bcVj8ekVU+GBwLXNhokxOavgY116XxScinFPa/VoWhaVzyLTbvKz5B6yytuRc3OkSqdDj83jCk+mpmJ5UuCRQ3jesaZAxRpPLzLc99sPtD7xnzEd9UWG8Hlnm6ATmmEQhDAgMBAAECgYBPX+nLGRyWYaNfsFM+tVJMfN/pNMqhnPkWLkoUwPhtS/EmYOaRc+GPCLkcnu2Tstk2udKCuk0xqOs6bZs/1DygxzifYUltWFpqQ2gfmDMoOL4GOflXEHIpoSzSinXz8rjjlQU0wgkbNn6wV6Ao4Jxm5Rzmr9mvTKrAwsnY2eZnYQJBAP+Gj3rrJ7s5778jCramS7yLei2ljkHa/7P0MQsJ+B02/V5CFCh6qKZ2aaAQdk6Z7og5f641TrKX76QetDItSgsCQQCIYVdOdkC3+P6r7WYKXEJ8fdIrf2xyhcCAt9I4q+rcID+ZQ+UqzPoBuib/xpgBZVukDpj9BbIyObyStkvQsNWpAkBd6ADQ5pz6ZKdkMiecym6pAwVKwz4Nm8M/Si2/5dEGQ5BH1Lb9zV4vlvLofURNTKrp61+uES8z2TybryEAE77TAkAD8YSbwTGX4DxE7mVf8VD+1oiIN3QET7fEQQx0FQyCdvA/10W+GhU0jZRpGu30RGEE+mMUFeEUMLUyLNE+ZI6ZAkEA2t0rz4UpljOPms3yfxvzFnShBdshFZOy8kZRG/+OL9entaSOJ0gDmfeFBE9oWXwTj8aVasgbrBV1HjNfyb8WfA==";
|
|
|
|
-
|
|
|
|
- NewOrder order = newOrderService.findByOrderID(orderId);
|
|
|
|
- if (order != null && order.getOrganizeID() >= 2) {
|
|
|
|
- //维沙订单退款
|
|
|
|
- merAccount = wsMerAccount;
|
|
|
|
- merKey = wsMerKey;
|
|
|
|
- }
|
|
|
|
- if (order != null && "2".equals(order.getOrderType())) {
|
|
|
|
- //呵呵商城退款
|
|
|
|
- merAccount = heHeMerAccount;
|
|
|
|
- merKey = heHeMerKey;
|
|
|
|
- }
|
|
|
|
List<CmReceiptOrderRelation> relationList = cmReceiptOrderRelationDao.findByOrderID(orderId.toString());
|
|
List<CmReceiptOrderRelation> relationList = cmReceiptOrderRelationDao.findByOrderID(orderId.toString());
|
|
if (null != relationList && relationList.size() > 0) {
|
|
if (null != relationList && relationList.size() > 0) {
|
|
for (CmReceiptOrderRelation orderRelation : relationList) {
|
|
for (CmReceiptOrderRelation orderRelation : relationList) {
|
|
- JSONObject json = new JSONObject();
|
|
|
|
- json.put("merAccount", merAccount);
|
|
|
|
- //线上收款
|
|
|
|
|
|
+ //cdr表payway为1纯线上收款
|
|
if ("1".equals(orderRelation.getPayWay())) {
|
|
if ("1".equals(orderRelation.getPayWay())) {
|
|
- // 当前时间戳
|
|
|
|
- long time = System.currentTimeMillis() / 1000;
|
|
|
|
- json.put("time", time);
|
|
|
|
- //商户退款流水号,由商户自行生成,必须唯一
|
|
|
|
- String merchantRefundNo = orderId + "##" + orderRelation.getId();
|
|
|
|
- json.put("merchantRefundNo", merchantRefundNo);
|
|
|
|
- //退款金额,单位分,必须大于0
|
|
|
|
- int refundAmt = (int) (Double.parseDouble(orderRelation.getAssociateAmount()) * 100);
|
|
|
|
- json.put("refundAmt", refundAmt);
|
|
|
|
- //退款原因
|
|
|
|
- String refundCause = "用户主动退款";
|
|
|
|
- json.put("refundCause", refundCause);
|
|
|
|
- //平台交易订单号
|
|
|
|
- json.put("mbOrderId", orderRelation.getMbOrderId());
|
|
|
|
- String sign = PayUtils.buildSign(json, merKey);
|
|
|
|
- json.put("sign", sign);
|
|
|
|
- String data = PayUtils.buildDataPrivate(json, merKey);
|
|
|
|
- JSONObject result = PayUtils.httpPost("https://platform.mhxxkj.com/paygateway/mbrefund/orderRefund/v1", merAccount, data);
|
|
|
|
- String code = result.getString("code");
|
|
|
|
- logger.info("返回结果-------------------------》"+result.toString());
|
|
|
|
- if (!"000000".equals(code)) {
|
|
|
|
- String msg = result.getString("msg");
|
|
|
|
- logger.info("第三方退款失败>>>>>>>msg:" + msg);
|
|
|
|
- throw new Exception("第三方退款失败!");
|
|
|
|
|
|
+ //不同产品区分
|
|
|
|
+ String payType = cmReceiptOrderRelationDao.findPayType(orderId);
|
|
|
|
+ if ("12".equals(payType) || "17".equals(payType)) {
|
|
|
|
+ //网银
|
|
|
|
+ onlinePay(orderRelation.getOrderRequestNo(), orderRelation.getAssociateAmount(), orderId, "1");
|
|
|
|
+ } else {
|
|
|
|
+ //扫码
|
|
|
|
+ unionRefund(orderRelation.getOrderRequestNo(), orderRelation.getAssociateAmount(), orderId, "1");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- logger.info("第三方退款成功>>>>>>>orderId>>>" + orderId);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ void onlinePay(String orderRequestNo, String money, Integer orderId, String type) throws Exception {
|
|
|
|
+ AppPayRefundOrderVo orderVo = new AppPayRefundOrderVo();
|
|
|
|
+ orderVo.setP1_bizType("AppPayRefund");
|
|
|
|
+ //todo 暂用本商户 E1807062884 网络
|
|
|
|
+ orderVo.setP3_customerNumber("E1807062884");
|
|
|
|
+ //退款原单号
|
|
|
|
+ orderVo.setP2_orderId(orderRequestNo);
|
|
|
|
+ //自定义退款单号
|
|
|
|
+ String tk = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
|
|
|
|
+ orderVo.setP4_refundOrderId("TK" + tk +orderRequestNo);
|
|
|
|
+ //退款金额
|
|
|
|
+ orderVo.setP5_amount(money);
|
|
|
|
+ Map<String, String> map = MyBeanUtils.convertBean(orderVo, new LinkedHashMap());
|
|
|
|
+ String oriMessage = MyBeanUtils.getSignedByPresetParameter(map, AppPayRefundOrderVo.NEED_SIGN_PARAMS);
|
|
|
|
+ //网银产品密钥
|
|
|
|
+ oriMessage += "1iHnZaalUNAVcfcbKdh6n86Z0yUHtM6f";
|
|
|
|
+ logger.info("签名原文串:" + oriMessage);
|
|
|
|
+ String sign = Disguiser.disguiseMD5(oriMessage.trim());
|
|
|
|
+ logger.info("签名串:" + sign);
|
|
|
|
+ map.put("sign", sign);
|
|
|
|
+ logger.info("发送参数:" + map);
|
|
|
|
+ Map<String, Object> resultMap = HttpClientService.getHttpResp(map, "http://pay.trx.helipay.com/trx/app/interface.action");
|
|
|
|
+ logger.info("响应结果:" + resultMap);
|
|
|
|
+ if ((Integer) resultMap.get("statusCode") == HttpStatus.SC_OK) {
|
|
|
|
+ String resultMsg = (String) resultMap.get("response");
|
|
|
|
+ AppPayRefundOrderResponseVo orderResponseVo = JSONObject.parseObject(resultMsg, AppPayRefundOrderResponseVo.class);
|
|
|
|
+ String assemblyRespOriSign = MyBeanUtils.getSignedByPresetParameter(orderResponseVo, AppPayRefundOrderResponseVo.NEED_SIGN_PARAMS);
|
|
|
|
+ //密钥区分
|
|
|
|
+ assemblyRespOriSign += "CZiCbGrgFYQMldVkQnzbFQeQkn6mp25w";
|
|
|
|
+ logger.info("组装返回结果签名串:" + assemblyRespOriSign);
|
|
|
|
+ String responseSign = orderResponseVo.getSign();
|
|
|
|
+ logger.info("响应签名:" + responseSign);
|
|
|
|
+ String checkSign = Disguiser.disguiseMD5(assemblyRespOriSign.trim());
|
|
|
|
+ if (checkSign.equals(responseSign)) {
|
|
|
|
+ if ("0001".equals(orderResponseVo.getRt2_retCode())) {
|
|
|
|
+ logger.info("第三方退款成功>>>>>>>orderId>>>" + orderId);
|
|
|
|
+ } else {
|
|
|
|
+ logger.error("退款失败========================" + orderResponseVo.getRt5_orderId() + "-" + orderResponseVo.getRt3_retMsg());
|
|
|
|
+ throw new Exception("第三方退款失败!");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ logger.error("退款验签失败");
|
|
|
|
+ throw new Exception("第三方退款验签失败!");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ logger.error("退款请求失败");
|
|
|
|
+ throw new Exception("第三方退款请求失败!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void unionRefund(String orderRequestNo,String money,Integer orderId,String type) throws Exception{
|
|
|
|
+ OnlineVo onlineVo = new OnlineVo();
|
|
|
|
+ onlineVo.setP1_bizType("OnlineRefund");
|
|
|
|
+ onlineVo.setP2_orderId(orderRequestNo);
|
|
|
|
+ onlineVo.setP3_customerNumber("E1807062884");
|
|
|
|
+ onlineVo.setP4_refundAmount(money);
|
|
|
|
+ onlineVo.setP5_refundOrderId("TK" +orderRequestNo);
|
|
|
|
+ //暂时不设置备注和回调
|
|
|
|
+ //onlineVo.setP6_desc("");
|
|
|
|
+ //onlineVo.setP7_serverCallbackUrl("");
|
|
|
|
+ Map<String, String> map = MyBeanUtils.convertBean(onlineVo, new LinkedHashMap());
|
|
|
|
+ String oriMessage = MyBeanUtils.getSignedByPresetParameter(map, OnlineVo.NEED_SIGN_PARAMS);
|
|
|
|
+ oriMessage += "CZiCbGrgFYQMldVkQnzbFQeQkn6mp25w";
|
|
|
|
+ logger.info("签名原文串:" + oriMessage);
|
|
|
|
+ String sign = Disguiser.disguiseMD5(oriMessage.trim());
|
|
|
|
+ logger.info("签名串:" + sign);
|
|
|
|
+ map.put("sign", sign);
|
|
|
|
+ logger.info("发送参数:" + map);
|
|
|
|
+ Map<String, Object> resultMap = HttpClientService.getHttpResp(map, "http://pay.trx.helipay.com/trx/online/interface.action");
|
|
|
|
+ logger.info("响应结果:" + resultMap);
|
|
|
|
+ if ((Integer) resultMap.get("statusCode") == HttpStatus.SC_OK) {
|
|
|
|
+ String resultMsg = (String) resultMap.get("response");
|
|
|
|
+ OnlineRefundData onlineRefund = JSONObject.parseObject(resultMsg, OnlineRefundData.class);
|
|
|
|
+ String assemblyRespOriSign = MyBeanUtils.getSignedByPresetParameter(onlineRefund, OnlineRefundData.NEED_SIGN_PARAMS);
|
|
|
|
+ //密钥区分
|
|
|
|
+ assemblyRespOriSign += "CZiCbGrgFYQMldVkQnzbFQeQkn6mp25w";
|
|
|
|
+ logger.info("组装返回结果签名串:" + assemblyRespOriSign);
|
|
|
|
+ String responseSign = onlineRefund.getSign();
|
|
|
|
+ logger.info("响应签名:" + responseSign);
|
|
|
|
+ String checkSign = Disguiser.disguiseMD5(assemblyRespOriSign.trim());
|
|
|
|
+ if (checkSign.equals(responseSign)) {
|
|
|
|
+ if ("0000".equals(onlineRefund.getRt2_retCode())) {
|
|
|
|
+ logger.info("第三方退款成功>>>>>>>orderId>>>" + orderId);
|
|
|
|
+ } else {
|
|
|
|
+ logger.error("退款失败========================" + onlineRefund.getRt5_orderId() + "-" + onlineRefund.getRt3_retMsg());
|
|
|
|
+ throw new Exception("第三方退款失败!");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ logger.error("退款验签失败");
|
|
|
|
+ throw new Exception("第三方退款验签失败!");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ logger.error("退款请求失败");
|
|
|
|
+ throw new Exception("第三方退款请求失败!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
@Transactional(readOnly = false)
|
|
@Transactional(readOnly = false)
|
|
public void revokeApply(CmReturnedPurchase cmReturnedPurchase, HttpServletRequest request) {
|
|
public void revokeApply(CmReturnedPurchase cmReturnedPurchase, HttpServletRequest request) {
|