From 74e8a46bb6e69e66c9e762b8fb169d232398f01b Mon Sep 17 00:00:00 2001 From: xh-pan1 Date: Fri, 19 May 2023 16:01:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9C=80=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/pay/xs/service/impl/XsPayServiceImpl.java | 23 ++++++++--- .../order/impl/CereShopOrderServiceImpl.java | 4 +- .../src/main/resources/application-security.yml | 1 - .../mybatis/mapper/cart/CereShopCartDAO.xml | 13 +++++++ .../business/controller/XsPayController.java | 19 +++++----- .../pay/xs/service/impl/XsPayServiceImpl.java | 44 +++++++++++++--------- .../order/impl/CereShopOrderServiceImpl.java | 9 +++-- .../src/main/resources/application-security.yml | 1 + .../cereshop/commons/constant/CoReturnFormat.java | 5 ++- .../com/shop/cereshop/commons/utils/UseBCrypt.java | 19 +++++++++- 10 files changed, 98 insertions(+), 40 deletions(-) diff --git a/cereshop-app/src/main/java/com/shop/cereshop/app/pay/xs/service/impl/XsPayServiceImpl.java b/cereshop-app/src/main/java/com/shop/cereshop/app/pay/xs/service/impl/XsPayServiceImpl.java index d2f2686..13c5826 100644 --- a/cereshop-app/src/main/java/com/shop/cereshop/app/pay/xs/service/impl/XsPayServiceImpl.java +++ b/cereshop-app/src/main/java/com/shop/cereshop/app/pay/xs/service/impl/XsPayServiceImpl.java @@ -35,10 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; -import java.util.Base64; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; @Service(value = "xsPayService") @@ -88,8 +85,22 @@ public class XsPayServiceImpl implements XsPayService { String resMsg = responseMap.get("msg"); String responeMsg = new String(Base64.getDecoder().decode(resMsg)); JSONObject jsonObject = JSONObject.parseObject(responeMsg); - JSONObject payInfoObject = jsonObject.getJSONObject("content").getJSONObject("payInfo"); - return JSONObject.parseObject(payInfoObject.toJSONString(),LinkedHashMap.class, Feature.OrderedField); + String payInfoStr = jsonObject.getJSONObject("content").getJSONObject("payInfo").getString("payInfo"); + payInfoStr = payInfoStr.substring(1, payInfoStr.length() - 2); + String[] payInfoDetailArray = payInfoStr.split(","); + Map resultMap = new HashMap<>(); + for (String payInfoDetail : payInfoDetailArray) { + if(StringUtils.isNotBlank(payInfoDetail) && payInfoDetail.contains("=")){ + int firstIndex = payInfoDetail.indexOf("="); + String key = payInfoDetail.substring(0, firstIndex).trim(); + String value = payInfoDetail.substring(firstIndex + 1).trim(); + if(StringUtils.equals(key, "signType")){ + value = "MD5"; + } + resultMap.put(key, value); + } + } + return resultMap; } catch (CoBusinessException e) { throw e; } catch (Exception e) { diff --git a/cereshop-app/src/main/java/com/shop/cereshop/app/service/order/impl/CereShopOrderServiceImpl.java b/cereshop-app/src/main/java/com/shop/cereshop/app/service/order/impl/CereShopOrderServiceImpl.java index cea829f..e38b73f 100644 --- a/cereshop-app/src/main/java/com/shop/cereshop/app/service/order/impl/CereShopOrderServiceImpl.java +++ b/cereshop-app/src/main/java/com/shop/cereshop/app/service/order/impl/CereShopOrderServiceImpl.java @@ -465,7 +465,9 @@ public class CereShopOrderServiceImpl implements CereShopOrderService { // if(EmptyUtils.isEmpty(user.getWechatOpenId())){ // throw new CoBusinessException(CoReturnFormat.OPENID_IS_NULL); // } - if (param.getPaymentMode() == null) { + if(PayConfig.paymentMode == IntegerEnum.ORDER_PAY_XS.getCode()){ + param.setPaymentMode(PayConfig.paymentMode); + }else if (param.getPaymentMode() == null) { param.setPaymentMode(PayConfig.paymentMode); } diff --git a/cereshop-app/src/main/resources/application-security.yml b/cereshop-app/src/main/resources/application-security.yml index 8bab30a..0b25628 100644 --- a/cereshop-app/src/main/resources/application-security.yml +++ b/cereshop-app/src/main/resources/application-security.yml @@ -44,7 +44,6 @@ security: - /order/alipayRefund/rolBack - /order/pay - /extend/** - - /extend/** - /doc.html - /doc.html#/** - /webjars/** diff --git a/cereshop-app/src/main/resources/mybatis/mapper/cart/CereShopCartDAO.xml b/cereshop-app/src/main/resources/mybatis/mapper/cart/CereShopCartDAO.xml index dd86a33..eb91fc7 100644 --- a/cereshop-app/src/main/resources/mybatis/mapper/cart/CereShopCartDAO.xml +++ b/cereshop-app/src/main/resources/mybatis/mapper/cart/CereShopCartDAO.xml @@ -330,6 +330,19 @@ ) + + insert into cere_shop_cart ( + buyer_user_id, shop_id, product_id, sku_id, product_name, `number`, product_price, + image, SKU, weight, selected, create_time, update_time + ) values + ( + #{buyerUserId}, #{shopId}, #{productId}, #{skuId}, #{productName}, #{number}, #{productPrice}, + #{image}, #{SKU}, #{weight}, #{selected}, #{createTime}, #{updateTime} + ) + on duplicate key + update `number` = `number` + #{number}, product_price = #{productPrice}, update_time = #{updateTime} + + update cere_shop_cart diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/controller/XsPayController.java b/cereshop-business/src/main/java/com/shop/cereshop/business/controller/XsPayController.java index cab4979..a2a1a52 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/controller/XsPayController.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/controller/XsPayController.java @@ -4,8 +4,10 @@ import com.alibaba.fastjson.JSONObject; import com.google.gson.Gson; import com.shop.cereshop.business.pay.xs.domain.XsCallBackRequestVo; import com.shop.cereshop.business.pay.xs.service.XsPayService; +import com.shop.cereshop.business.service.after.CereOrderAfterService; import com.shop.cereshop.business.service.order.CereShopOrderService; -import com.shop.cereshop.commons.utils.EmptyUtils; +import com.shop.cereshop.commons.constant.IntegerEnum; +import com.shop.cereshop.commons.utils.SpringUtil; import com.shop.cereshop.commons.utils.StringUtils; import io.swagger.annotations.Api; import lombok.extern.slf4j.Slf4j; @@ -93,15 +95,12 @@ public class XsPayController { //截取订单编号 JSONObject content = xsCallBackRequestVo.getContent(); String merOrderId = content.getString("merOrderId"); - String[] split = merOrderId.split("-"); - if(!EmptyUtils.isEmpty(split)){ - String orderFormId=split[0]; - if(!EmptyUtils.isEmpty(orderFormId)){ - String dealId = content.getString("refundOrderNo"); - //处理支付成功后的其他逻辑 - cereShopOrderService.handleRefundWxLog(orderFormId, dealId, merOrderId); - } - } + String oldMerOrderId = content.getString("oldMerOrderId"); + String oldDealId = content.getString("oldDealId"); + CereOrderAfterService afterService = SpringUtil.getBean(CereOrderAfterService.class); + afterService.handleRefundSuc(merOrderId, oldDealId, oldMerOrderId, IntegerEnum.ORDER_PAY_XS.getCode()); +// //处理支付成功后的其他逻辑 +// cereShopOrderService.handleRefundWxLog(orderFormId, dealId, merOrderId); } } catch (Exception e) { e.printStackTrace(); diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/pay/xs/service/impl/XsPayServiceImpl.java b/cereshop-business/src/main/java/com/shop/cereshop/business/pay/xs/service/impl/XsPayServiceImpl.java index bccfd73..000ac9d 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/pay/xs/service/impl/XsPayServiceImpl.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/pay/xs/service/impl/XsPayServiceImpl.java @@ -13,6 +13,7 @@ import com.shop.cereshop.business.pay.xs.utils.CommonUtils; import com.shop.cereshop.business.pay.xs.utils.HttpUtils; import com.shop.cereshop.business.service.order.CereShopOrderService; import com.shop.cereshop.commons.config.XspayConfig; +import com.shop.cereshop.commons.constant.CoReturnFormat; import com.shop.cereshop.commons.constant.WxPayEnum; import com.shop.cereshop.commons.constant.XsPayEnum; import com.shop.cereshop.commons.exception.CoBusinessException; @@ -46,7 +47,7 @@ public class XsPayServiceImpl implements XsPayService { //构建请求参数 Map headMap = CommonUtils.buildHeadMap(REFUND_SER_CODE); - Map contentMap = build06ContentMap(outTradeNo, transactionId, refund, + Map contentMap = build06ContentMap(outRefundNo, outTradeNo, transactionId, refund, XspayConfig.BUSINESS_RETURN_NOTICE_URL); //head+content做md5并根据加签方式加密 String msg = CommonUtils.getRequestMsg(headMap, contentMap); @@ -88,7 +89,7 @@ public class XsPayServiceImpl implements XsPayService { } } catch (CoBusinessException e) { if(StringUtils.equals(e.getCode(), "0005")){ - throw new CoBusinessException("10000","支付系统正在处理,请支付5分钟后再申请退款"); + throw new CoBusinessException(CoReturnFormat.APPLY_REFUND_FAILED_LATER,"支付系统正在处理,请支付5分钟后再申请退款"); }else { throw e; } @@ -111,7 +112,7 @@ public class XsPayServiceImpl implements XsPayService { //构建请求参数 Map headMap = CommonUtils.buildHeadMap(REFUND_SER_CODE); - Map contentMap = build06ContentMap(outTradeNo, transactionId, refund, XspayConfig.APP_NOTICE_URL); + Map contentMap = build06ContentMap(outRefundNo, outTradeNo, transactionId, refund, XspayConfig.APP_NOTICE_URL); //head+content做md5并根据加签方式加密 String msg = CommonUtils.getRequestMsg(headMap, contentMap); log.info("【" + REFUND_SER_CODE + "】接口-请求报文:msg="+msg); @@ -132,21 +133,30 @@ public class XsPayServiceImpl implements XsPayService { JSONObject content = jsonObject.getJSONObject("content"); String status = content.getString("status"); //2成功 3失败 - if(StringUtils.equals(status, "0")) { - String merOrderId = content.getString("merOrderId"); - String[] split = merOrderId.split("-"); - if (!EmptyUtils.isEmpty(split)) { - String orderFormId = split[0]; - if (!EmptyUtils.isEmpty(orderFormId)) { - String dealId = content.getString("refundOrderNo"); - //处理支付成功后的其他逻辑 - cereShopOrderService.handleRefundWxLog(orderFormId, dealId, merOrderId); - } - } + if(StringUtils.equals(status, "1")) { + Map result = new HashMap<>(); + result.put("return_msg", WxPayEnum.REFUND_SUCCESS.getCode()); + result.put("return_code", WxPayEnum.REFUND_OK.getCode()); + return result; +// if(StringUtils.equals(status, "0")) { +// String merOrderId = content.getString("merOrderId"); +// String[] split = merOrderId.split("-"); +// if (!EmptyUtils.isEmpty(split)) { +// String orderFormId = split[0]; +// if (!EmptyUtils.isEmpty(orderFormId)) { +// String dealId = content.getString("refundOrderNo"); +// //处理支付成功后的其他逻辑 +// cereShopOrderService.handleRefundWxLog(orderFormId, dealId, merOrderId); +// } +// } } } catch (CoBusinessException e) { - throw e; + if(StringUtils.equals(e.getCode(), "0005")){ + throw new CoBusinessException(CoReturnFormat.APPLY_REFUND_FAILED_LATER,"支付系统正在处理,请支付5分钟后再申请退款"); + }else { + throw e; + } } catch (Exception e) { //支付方式为B2C、B2B、H5,成功响应时respMsg为html页面代码 if(respMsg.contains("toNativePayIndexForm")){ @@ -227,10 +237,10 @@ public class XsPayServiceImpl implements XsPayService { * 构建content请求参数 * @return */ - private static Map build06ContentMap(String orderFormid, String dealId, BigDecimal money, String noticeUrl){ + private static Map build06ContentMap(String merOrderId, String orderFormid, String dealId, BigDecimal money, String noticeUrl){ Map contentMap = new LinkedHashMap<>(); log.info("orderFormid:" + orderFormid); - contentMap.put("merOrderId", System.currentTimeMillis()+""); + contentMap.put("merOrderId", merOrderId); //oldMerOrderId 对应 101004、101005接口中merOrderId contentMap.put("oldMerOrderId", orderFormid); //oldDealId 对应 101004、101005接口响应参数中dealId diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/service/order/impl/CereShopOrderServiceImpl.java b/cereshop-business/src/main/java/com/shop/cereshop/business/service/order/impl/CereShopOrderServiceImpl.java index a5700b5..23cb06d 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/service/order/impl/CereShopOrderServiceImpl.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/service/order/impl/CereShopOrderServiceImpl.java @@ -24,6 +24,7 @@ import com.shop.cereshop.business.pay.PayFactory; import com.shop.cereshop.business.pay.PayService; import com.shop.cereshop.business.redis.service.api.StringRedisService; import com.shop.cereshop.business.service.activity.CereBuyerCouponService; +import com.shop.cereshop.business.service.after.CereOrderAfterService; import com.shop.cereshop.business.service.buyer.CereBuyerShopCouponService; import com.shop.cereshop.business.service.log.CerePlatformLogService; import com.shop.cereshop.business.service.notice.CereNoticeService; @@ -366,9 +367,11 @@ public class CereShopOrderServiceImpl implements CereShopOrderService { //退款成功 支付宝的退款是立即退款的,需要同步处理 if (Arrays.asList(IntegerEnum.ORDER_PAY_ALI.getCode(),IntegerEnum.ORDER_PAY_XS.getCode(), IntegerEnum.ORDER_PAY_HUABEI.getCode()).contains(order.getPaymentMode())) { - //内部调用不会执行事务,所以通过springUtil获取service对象 - CereShopOrderService cereShopOrderService = SpringUtil.getBean(CereShopOrderService.class); - cereShopOrderService.handleRefundWxLog(refund.getOrderFormid(),refund.getTransactionId(),refund.getOutTradeNo()); + CereOrderAfterService afterService = SpringUtil.getBean(CereOrderAfterService.class); + afterService.handleRefundSuc(refund.getOutRefundNo(), refund.getTransactionId(), refund.getOutTradeNo(), order.getPaymentMode()); +// //内部调用不会执行事务,所以通过springUtil获取service对象 +// CereShopOrderService cereShopOrderService = SpringUtil.getBean(CereShopOrderService.class); +// cereShopOrderService.handleRefundWxLog(refund.getOrderFormid(),refund.getTransactionId(),refund.getOutTradeNo()); } }else if(resultMap.get("return_code").equals(WxPayEnum.BUSINESS_BALANCE_NOTENOUGH.getCode())){ //退款失败,商户余额不足 diff --git a/cereshop-business/src/main/resources/application-security.yml b/cereshop-business/src/main/resources/application-security.yml index 596306b..e281f27 100644 --- a/cereshop-business/src/main/resources/application-security.yml +++ b/cereshop-business/src/main/resources/application-security.yml @@ -34,6 +34,7 @@ security: - /doc.html - /doc.html#/** - /webjars/** + - /extend/** - /swagger-resources/** - /order/syncOrderList - /product/syncProductList diff --git a/cereshop-commons/src/main/java/com/shop/cereshop/commons/constant/CoReturnFormat.java b/cereshop-commons/src/main/java/com/shop/cereshop/commons/constant/CoReturnFormat.java index 19d7cf1..1fbd896 100644 --- a/cereshop-commons/src/main/java/com/shop/cereshop/commons/constant/CoReturnFormat.java +++ b/cereshop-commons/src/main/java/com/shop/cereshop/commons/constant/CoReturnFormat.java @@ -185,7 +185,7 @@ public class CoReturnFormat { put(CoReturnFormat.APPLY_REFUND_FAILED, "退款申请失败"); put(CoReturnFormat.GENERATE_COLLECTION_CODE_FAILED, "生成收款码失败"); put(CoReturnFormat.PAY_ORDER_ERROR, "订单预支付失败"); - + put(CoReturnFormat.APPLY_REFUND_FAILED, "支付系统正在处理,请支付5分钟后再申请退款"); //=================================商品=================================== put(CoReturnFormat.PRODUCT_STOCK_ERROR, "商品已不可售,看看其他的吧"); @@ -583,6 +583,9 @@ public class CoReturnFormat { /** 订单预支付失败 */ public static final String PAY_ORDER_ERROR = "70006"; + /** 退款申请失败 */ + public static final String APPLY_REFUND_FAILED_LATER="70007"; + diff --git a/cereshop-commons/src/main/java/com/shop/cereshop/commons/utils/UseBCrypt.java b/cereshop-commons/src/main/java/com/shop/cereshop/commons/utils/UseBCrypt.java index f83787d..63bc30c 100644 --- a/cereshop-commons/src/main/java/com/shop/cereshop/commons/utils/UseBCrypt.java +++ b/cereshop-commons/src/main/java/com/shop/cereshop/commons/utils/UseBCrypt.java @@ -10,6 +10,9 @@ import io.jsonwebtoken.io.Encoders; import org.springframework.security.crypto.bcrypt.BCrypt; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import java.util.HashMap; +import java.util.Map; + /* * BCrypt Java实现 * BCrypt也是一种哈希算法,相比MD5更安全,速度慢 @@ -24,7 +27,21 @@ public class UseBCrypt { // } public static void main(String args[]){ - System.out.println(Encoders.BASE64.encode("chengmeicereshopchengmeicereshopchengmeicereshopchengmeicereshopchengmeicereshopchengmeicereshop".getBytes())); // true + String payInfoStr = "{timeStamp=1684478293, package=prepay_id=wx19143813475014e79ebd0407347d960000, paySign=3j457sJZxTSHv6XqKVPm6p7gdhraTpRMOLOrMxmzYndHJ8bFzjgJzVl3yCStR7AGBh7qSl3m9W3k9LmpG1CJDMavcwj671qtKuAAVGmRu91HUgbssqPstr5Du4zYyb6XC+15TwX/NrDzvBdm8D7Rx0oSFNYaBsRkDVUX37hT828MnqIzMyt98c6DPkHzNBNyzZVf21osgXrh9dZ5j0NU20TOjmSSxX6RmwS6+lNeH8+IYxpkEJKqKfekRs6WCo6tx/y03Rw6lPoc160rgLdCKObrSiV4Zk622JDsK91ENXeZywiNmcba81yEXl2yWSXai2XtzVE++EEC/0MePkLQFw==, orderId=2305191438131668209, appId=wxd7066af4ee73022d, signType=RSA, nonceStr=9d468bc02a1943b9a1f8902d07a6384b}"; + payInfoStr = payInfoStr.substring(1, payInfoStr.length() - 2); + String[] payInfoDetailArray = payInfoStr.split(","); + Map resultMap = new HashMap<>(); + for (String payInfoDetail : payInfoDetailArray) { + if(StringUtils.isNotBlank(payInfoDetail) && payInfoDetail.contains("=")){ + int firstIndex = payInfoDetail.indexOf("="); + String key = payInfoDetail.substring(0, firstIndex).trim(); + String value = payInfoDetail.substring(firstIndex + 1).trim(); + System.out.println("key:"+ key); + System.out.println("value:"+ value); + } + } + +// System.out.println(Encoders.BASE64.encode("chengmeicereshopchengmeicereshopchengmeicereshopchengmeicereshopchengmeicereshopchengmeicereshop".getBytes())); // true } }