| @@ -1,24 +0,0 @@ | |||||
| package com.iformall.config; | |||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
| import org.springframework.stereotype.Component; | |||||
| /** | |||||
| * @author Stormeye | |||||
| */ | |||||
| @Component | |||||
| @ConfigurationProperties(prefix = "pay") | |||||
| public class PayProperty { | |||||
| /** | |||||
| * 真实支付 | |||||
| */ | |||||
| private boolean real; | |||||
| public boolean isReal() { | |||||
| return real; | |||||
| } | |||||
| public void setReal(boolean real) { | |||||
| this.real = real; | |||||
| } | |||||
| } | |||||
| @@ -3,7 +3,6 @@ package com.iformall.controller; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.config.PayProperty; | |||||
| import com.iformall.domain.po.WxAppinfo; | import com.iformall.domain.po.WxAppinfo; | ||||
| import com.iformall.domain.po.WxCouponOrder; | import com.iformall.domain.po.WxCouponOrder; | ||||
| import com.iformall.domain.vo.WxCouponOrderBVo; | import com.iformall.domain.vo.WxCouponOrderBVo; | ||||
| @@ -43,9 +42,6 @@ public class WxCouponOrderController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxAppinfoService wxAppinfoService; | private WxAppinfoService wxAppinfoService; | ||||
| @Autowired | |||||
| private PayProperty payProperty; | |||||
| @ApiOperation("分页列表接口") | @ApiOperation("分页列表接口") | ||||
| @GetMapping("list") | @GetMapping("list") | ||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @@ -143,7 +139,7 @@ public class WxCouponOrderController extends BaseController { | |||||
| WxAppinfo appinfo = appinfoPageInfo.getList().get(0); | WxAppinfo appinfo = appinfoPageInfo.getList().get(0); | ||||
| if (appinfo != null) { | if (appinfo != null) { | ||||
| try { | try { | ||||
| wxRefundOrderService.createRefundOrder(payProperty.isReal(), appinfo, couponOrderId, EnumPayType.PAY_ADMIN_REFUND, null); | |||||
| wxRefundOrderService.createRefundOrder(appinfo, couponOrderId, EnumPayType.PAY_ADMIN_REFUND, null); | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -70,8 +70,4 @@ mapper: | |||||
| mappers: | mappers: | ||||
| - com.iformall.common.CommonMapper | - com.iformall.common.CommonMapper | ||||
| pay: | |||||
| real: true | |||||
| version: @project.version@ | version: @project.version@ | ||||
| @@ -1,24 +0,0 @@ | |||||
| package com.iformall.config; | |||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
| import org.springframework.stereotype.Component; | |||||
| /** | |||||
| * @author Stormeye | |||||
| */ | |||||
| @Component | |||||
| @ConfigurationProperties(prefix = "pay") | |||||
| public class PayProperty { | |||||
| /** | |||||
| * 真实支付 | |||||
| */ | |||||
| private boolean real; | |||||
| public boolean isReal() { | |||||
| return real; | |||||
| } | |||||
| public void setReal(boolean real) { | |||||
| this.real = real; | |||||
| } | |||||
| } | |||||
| @@ -3,7 +3,6 @@ package com.iformall.controller; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.config.PayProperty; | |||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.enums.EnumOrderType; | import com.iformall.enums.EnumOrderType; | ||||
| import com.iformall.enums.EnumPayType; | import com.iformall.enums.EnumPayType; | ||||
| @@ -33,9 +32,6 @@ import java.util.Map; | |||||
| public class WxMicroPayController extends BaseController { | public class WxMicroPayController extends BaseController { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | |||||
| private PayProperty payProperty; | |||||
| @Autowired | @Autowired | ||||
| WxMerchantBUserService wxMerchantBUserService; | WxMerchantBUserService wxMerchantBUserService; | ||||
| @@ -98,7 +94,7 @@ public class WxMicroPayController extends BaseController { | |||||
| record.setIp(ipStr); | record.setIp(ipStr); | ||||
| try { | try { | ||||
| return wxPayOrderService.createMicroPayOrder(payProperty.isReal(), user, record, EnumPayWay.PAY_WAY_WECHAT); | |||||
| return wxPayOrderService.createMicroPayOrder(user, record, EnumPayWay.PAY_WAY_WECHAT); | |||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | ||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | return new ResultData(e.getErrorCode(), e.getMessage()); | ||||
| @@ -253,7 +249,7 @@ public class WxMicroPayController extends BaseController { | |||||
| WxMerchantBUser bUser = getUser(); | WxMerchantBUser bUser = getUser(); | ||||
| WxAppinfo appinfo = getAppInfo(bUser.getAppId()); | WxAppinfo appinfo = getAppInfo(bUser.getAppId()); | ||||
| try { | try { | ||||
| ResultData rd = wxRefundOrderService.createRefundOrderFromMicroPay(payProperty.isReal(), appinfo, orderId, EnumPayType.PAY_B_REFUND, bUser.getId()); | |||||
| ResultData rd = wxRefundOrderService.createRefundOrderFromMicroPay(appinfo, orderId, EnumPayType.PAY_B_REFUND, bUser.getId()); | |||||
| return rd; | return rd; | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error("退款 1:" + e.getMessage()); | logger.error("退款 1:" + e.getMessage()); | ||||
| @@ -3,7 +3,6 @@ package com.iformall.controller; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.config.PayProperty; | |||||
| import com.iformall.domain.po.WxAppinfo; | import com.iformall.domain.po.WxAppinfo; | ||||
| import com.iformall.domain.po.WxPayBill; | import com.iformall.domain.po.WxPayBill; | ||||
| import com.iformall.enums.EnumPayStatus; | import com.iformall.enums.EnumPayStatus; | ||||
| @@ -31,9 +30,6 @@ import java.util.Map; | |||||
| public class WxPayBillController extends BaseController { | public class WxPayBillController extends BaseController { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | |||||
| private PayProperty payProperty; | |||||
| @Autowired | @Autowired | ||||
| private WxPayBillService wxPayBillService; | private WxPayBillService wxPayBillService; | ||||
| @@ -83,7 +79,7 @@ public class WxPayBillController extends BaseController { | |||||
| record.setTenantId(appInfo.getTenantId()); | record.setTenantId(appInfo.getTenantId()); | ||||
| try { | try { | ||||
| record.setIp(IPUtil.getIpAddr(request)); | record.setIp(IPUtil.getIpAddr(request)); | ||||
| return wxPayBillService.createPayBill(payProperty.isReal(), appInfo, record, EnumPayWay.PAY_WAY_WECHAT); | |||||
| return wxPayBillService.createPayBill(appInfo, record, EnumPayWay.PAY_WAY_WECHAT); | |||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | ||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | return new ResultData(e.getErrorCode(), e.getMessage()); | ||||
| @@ -4,12 +4,9 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.config.PayProperty; | |||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.enums.EnumPayType; | import com.iformall.enums.EnumPayType; | ||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.service.WxCouponOrderService; | |||||
| import com.iformall.service.WxOrderService; | |||||
| import com.iformall.service.WxRefundOrderService; | import com.iformall.service.WxRefundOrderService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| @@ -29,9 +26,6 @@ import java.util.Map; | |||||
| public class WxRefundOrderController extends BaseController { | public class WxRefundOrderController extends BaseController { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | |||||
| private PayProperty payProperty; | |||||
| @Autowired | @Autowired | ||||
| private WxRefundOrderService wxRefundOrderService; | private WxRefundOrderService wxRefundOrderService; | ||||
| @@ -57,7 +51,7 @@ public class WxRefundOrderController extends BaseController { | |||||
| WxMerchantBUser bUser = getUser(); | WxMerchantBUser bUser = getUser(); | ||||
| WxAppinfo appinfo = getAppInfo(bUser.getAppId()); | WxAppinfo appinfo = getAppInfo(bUser.getAppId()); | ||||
| try { | try { | ||||
| ResultData rd = wxRefundOrderService.createRefundOrder(payProperty.isReal(), appinfo, couponOrderId, EnumPayType.PAY_B_REFUND, bUser.getId()); | |||||
| ResultData rd = wxRefundOrderService.createRefundOrder(appinfo, couponOrderId, EnumPayType.PAY_B_REFUND, bUser.getId()); | |||||
| return rd; | return rd; | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -49,8 +49,4 @@ mapper: | |||||
| mappers: | mappers: | ||||
| - com.iformall.common.CommonMapper | - com.iformall.common.CommonMapper | ||||
| pay: | |||||
| real: true | |||||
| version: @project.version@ | version: @project.version@ | ||||
| @@ -1,24 +0,0 @@ | |||||
| package com.iformall.config; | |||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
| import org.springframework.stereotype.Component; | |||||
| /** | |||||
| * @author Stormeye | |||||
| */ | |||||
| @Component | |||||
| @ConfigurationProperties(prefix = "pay") | |||||
| public class PayProperty { | |||||
| /** | |||||
| * 真实支付 | |||||
| */ | |||||
| private boolean real; | |||||
| public boolean isReal() { | |||||
| return real; | |||||
| } | |||||
| public void setReal(boolean real) { | |||||
| this.real = real; | |||||
| } | |||||
| } | |||||
| @@ -4,7 +4,6 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.config.PayProperty; | |||||
| import com.iformall.domain.po.WxAppinfo; | import com.iformall.domain.po.WxAppinfo; | ||||
| import com.iformall.domain.po.WxCUser; | import com.iformall.domain.po.WxCUser; | ||||
| import com.iformall.domain.po.WxOrder; | import com.iformall.domain.po.WxOrder; | ||||
| @@ -34,9 +33,6 @@ import java.util.Map; | |||||
| public class WxPayOrderController extends BaseController { | public class WxPayOrderController extends BaseController { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | |||||
| private PayProperty payProperty; | |||||
| @Autowired | @Autowired | ||||
| private WxPayOrderService wxPayOrderService; | private WxPayOrderService wxPayOrderService; | ||||
| @@ -70,7 +66,7 @@ public class WxPayOrderController extends BaseController { | |||||
| try { | try { | ||||
| record.setIp(IPUtil.getIpAddr(request)); | record.setIp(IPUtil.getIpAddr(request)); | ||||
| return wxPayOrderService.createPayOrder(payProperty.isReal(), appInfo, user, record, EnumPayWay.PAY_WAY_WECHAT); | |||||
| return wxPayOrderService.createPayOrder(appInfo, user, record, EnumPayWay.PAY_WAY_WECHAT); | |||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | ||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | return new ResultData(e.getErrorCode(), e.getMessage()); | ||||
| @@ -49,8 +49,4 @@ mapper: | |||||
| mappers: | mappers: | ||||
| - com.iformall.common.CommonMapper | - com.iformall.common.CommonMapper | ||||
| pay: | |||||
| real: true | |||||
| version: @project.version@ | version: @project.version@ | ||||
| @@ -1,24 +0,0 @@ | |||||
| package com.iformall.config; | |||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
| import org.springframework.stereotype.Component; | |||||
| /** | |||||
| * @author Stormeye | |||||
| */ | |||||
| @Component | |||||
| @ConfigurationProperties(prefix = "pay") | |||||
| public class PayProperty { | |||||
| /** | |||||
| * 真实支付 | |||||
| */ | |||||
| private boolean real; | |||||
| public boolean isReal() { | |||||
| return real; | |||||
| } | |||||
| public void setReal(boolean real) { | |||||
| this.real = real; | |||||
| } | |||||
| } | |||||
| @@ -66,8 +66,4 @@ mapper: | |||||
| mappers: | mappers: | ||||
| - com.iformall.common.CommonMapper | - com.iformall.common.CommonMapper | ||||
| pay: | |||||
| real: true | |||||
| version: @project.version@ | version: @project.version@ | ||||
| @@ -1,24 +0,0 @@ | |||||
| package com.iformall.config; | |||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
| import org.springframework.stereotype.Component; | |||||
| /** | |||||
| * @author Stormeye | |||||
| */ | |||||
| @Component | |||||
| @ConfigurationProperties(prefix = "pay") | |||||
| public class PayProperty { | |||||
| /** | |||||
| * 真实支付 | |||||
| */ | |||||
| private boolean real; | |||||
| public boolean isReal() { | |||||
| return real; | |||||
| } | |||||
| public void setReal(boolean real) { | |||||
| this.real = real; | |||||
| } | |||||
| } | |||||
| @@ -1,15 +1,11 @@ | |||||
| package com.iformall.schedule; | package com.iformall.schedule; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.config.PayProperty; | |||||
| import com.iformall.domain.dto.WxSharingOrderDto; | import com.iformall.domain.dto.WxSharingOrderDto; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.enums.*; | import com.iformall.enums.*; | ||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.mapper.*; | import com.iformall.mapper.*; | ||||
| import com.iformall.service.WxOrderService; | import com.iformall.service.WxOrderService; | ||||
| import com.iformall.service.WxPayOrderService; | |||||
| import com.iformall.service.WxProfitSharingOrderService; | import com.iformall.service.WxProfitSharingOrderService; | ||||
| import com.iformall.service.WxRefundOrderService; | import com.iformall.service.WxRefundOrderService; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -27,13 +23,9 @@ import java.util.List; | |||||
| public class CouponOrderExpiringSchedule { | public class CouponOrderExpiringSchedule { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | @Autowired | ||||
| private WxCouponOrderMapper wxCouponOrderMapper; | private WxCouponOrderMapper wxCouponOrderMapper; | ||||
| @Autowired | |||||
| private PayProperty payProperty; | |||||
| @Autowired | @Autowired | ||||
| private WxRefundOrderService wxRefundOrderService; | private WxRefundOrderService wxRefundOrderService; | ||||
| @@ -127,7 +119,7 @@ public class CouponOrderExpiringSchedule { | |||||
| appinfo = wxAppinfoMapper.findList(appinfo).get(0); | appinfo = wxAppinfoMapper.findList(appinfo).get(0); | ||||
| try { | try { | ||||
| wxRefundOrderService.createRefundOrder(payProperty.isReal(), appinfo, co.getId(), EnumPayType.PAY_AUTO_REFUND, null); | |||||
| wxRefundOrderService.createRefundOrder(appinfo, co.getId(), EnumPayType.PAY_AUTO_REFUND, null); | |||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error("退款失败:"+e.getMessage()+"couponOrderId="+co.getId()); | logger.error("退款失败:"+e.getMessage()+"couponOrderId="+co.getId()); | ||||
| throw new MallinkException(e.getErrorCode(), e.getMessage()); | throw new MallinkException(e.getErrorCode(), e.getMessage()); | ||||
| @@ -66,8 +66,4 @@ mapper: | |||||
| mappers: | mappers: | ||||
| - com.iformall.common.CommonMapper | - com.iformall.common.CommonMapper | ||||
| pay: | |||||
| real: true | |||||
| version: @project.version@ | version: @project.version@ | ||||
| @@ -19,7 +19,7 @@ public interface WxPayBillService { | |||||
| * @param payWay | * @param payWay | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| ResultData createPayBill(boolean isReal, WxAppinfo appInfo, WxPayBill record, EnumPayWay payWay); | |||||
| ResultData createPayBill(WxAppinfo appInfo, WxPayBill record, EnumPayWay payWay); | |||||
| /** | /** | ||||
| * 微信支付订单查询 | * 微信支付订单查询 | ||||
| @@ -19,7 +19,7 @@ public interface WxPayOrderService { | |||||
| * @param payWay | * @param payWay | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| ResultData createPayOrder(boolean isReal, WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay); | |||||
| ResultData createPayOrder(WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay); | |||||
| /** | /** | ||||
| * 刷卡支付订单 | * 刷卡支付订单 | ||||
| @@ -28,7 +28,7 @@ public interface WxPayOrderService { | |||||
| * @param payWay | * @param payWay | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| ResultData createMicroPayOrder(boolean isReal, WxMerchantBUser user, WxPayOrder record, EnumPayWay payWay); | |||||
| ResultData createMicroPayOrder(WxMerchantBUser user, WxPayOrder record, EnumPayWay payWay); | |||||
| /** | /** | ||||
| * 微信支付订单查询 | * 微信支付订单查询 | ||||
| @@ -14,25 +14,23 @@ public interface WxRefundOrderService { | |||||
| /** | /** | ||||
| * 创建退款订单 | * 创建退款订单 | ||||
| * @param isReal | |||||
| * @param appInfo | * @param appInfo | ||||
| * @param couponOrderId 券包Id | * @param couponOrderId 券包Id | ||||
| * @param payType 退款来源 | * @param payType 退款来源 | ||||
| * @param bUserId b端退款Id,auto,admin,self可为null | * @param bUserId b端退款Id,auto,admin,self可为null | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| ResultData createRefundOrder(boolean isReal, WxAppinfo appInfo, Long couponOrderId, EnumPayType payType, Long bUserId); | |||||
| ResultData createRefundOrder(WxAppinfo appInfo, Long couponOrderId, EnumPayType payType, Long bUserId); | |||||
| /** | /** | ||||
| * 创建退款订单 | * 创建退款订单 | ||||
| * @param isReal | |||||
| * @param appInfo | * @param appInfo | ||||
| * @param orderId 订单Id | * @param orderId 订单Id | ||||
| * @param payType 退款来源 | * @param payType 退款来源 | ||||
| * @param bUserId b端退款Id,auto,admin,self可为null | * @param bUserId b端退款Id,auto,admin,self可为null | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| ResultData createRefundOrderFromMicroPay(boolean isReal, WxAppinfo appInfo, Long orderId, EnumPayType payType, Long bUserId); | |||||
| ResultData createRefundOrderFromMicroPay(WxAppinfo appInfo, Long orderId, EnumPayType payType, Long bUserId); | |||||
| /** | /** | ||||
| * 退款订单查询 | * 退款订单查询 | ||||
| @@ -81,7 +81,7 @@ public class WxPayBillServiceImpl implements WxPayBillService { | |||||
| "\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"reason\":\"请检查XML参数格式是否正确\"}}"); | "\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"reason\":\"请检查XML参数格式是否正确\"}}"); | ||||
| @Override | @Override | ||||
| public ResultData createPayBill(boolean isReal, WxAppinfo appInfo, WxPayBill record, EnumPayWay payWay) { | |||||
| public ResultData createPayBill(WxAppinfo appInfo, WxPayBill record, EnumPayWay payWay) { | |||||
| final IdWorker idworker = IdWorker.get(); | final IdWorker idworker = IdWorker.get(); | ||||
| EnumPayShare isShare = EnumPayShare.NO; | EnumPayShare isShare = EnumPayShare.NO; | ||||
| @@ -109,7 +109,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| "\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"reason\":\"请检查XML参数格式是否正确\"}}"); | "\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"reason\":\"请检查XML参数格式是否正确\"}}"); | ||||
| @Override | @Override | ||||
| public ResultData createPayOrder(boolean isReal, WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay) { | |||||
| public ResultData createPayOrder(WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay) { | |||||
| final IdWorker idworker = IdWorker.get(); | final IdWorker idworker = IdWorker.get(); | ||||
| EnumPayShare isShare = EnumPayShare.NO; | EnumPayShare isShare = EnumPayShare.NO; | ||||
| @@ -134,7 +134,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| throw new MallinkException(ErrorCode.COUPON_CHANNEL_IS_TAKE_OFF); | throw new MallinkException(ErrorCode.COUPON_CHANNEL_IS_TAKE_OFF); | ||||
| } | } | ||||
| if(order.getPressEndDate() == null) { | |||||
| if (order.getPressEndDate() == null) { | |||||
| // 非砍价券 | // 非砍价券 | ||||
| if (order.getOrderStatus() == EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()) { | if (order.getOrderStatus() == EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()) { | ||||
| logger.error("订单已支付: " + order.toString() + " , payWay: " + payWay.toString()); | logger.error("订单已支付: " + order.toString() + " , payWay: " + payWay.toString()); | ||||
| @@ -143,12 +143,12 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| logger.error("订单已取消: " + order.toString() + " , payWay: " + payWay.toString()); | logger.error("订单已取消: " + order.toString() + " , payWay: " + payWay.toString()); | ||||
| throw new MallinkException(ErrorCode.ORDER_HAD_CANCEL); | throw new MallinkException(ErrorCode.ORDER_HAD_CANCEL); | ||||
| } else { | } else { | ||||
| if(order.getOrderStatus() != EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()) { | |||||
| if (order.getOrderStatus() != EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()) { | |||||
| logger.error("订单已支付: " + order.toString() + " , payWay: " + payWay.toString()); | logger.error("订单已支付: " + order.toString() + " , payWay: " + payWay.toString()); | ||||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_PAY); | throw new MallinkException(ErrorCode.ORDER_IS_NOT_PAY); | ||||
| } | } | ||||
| } | } | ||||
| } else if(order.getPressEndDate() != null) { | |||||
| } else if (order.getPressEndDate() != null) { | |||||
| // 砍价券,只有在过期时无法支付 | // 砍价券,只有在过期时无法支付 | ||||
| // 砍价中,原价购买 | // 砍价中,原价购买 | ||||
| // 砍价完成,低价购买 | // 砍价完成,低价购买 | ||||
| @@ -221,184 +221,159 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| } | } | ||||
| } | } | ||||
| if (isReal) { | |||||
| // 微信实际支付 | |||||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||||
| // 统一下单 普通商户模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxPayOrderP wxPayOrderP = new WxPayOrderP(); | |||||
| wxPayOrderP.setOpenid(user.getOpenId()); | |||||
| wxPayOrderP.setAppid(user.getAppId()); | |||||
| wxPayOrderP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderP.setNonce_str(noncestr); | |||||
| wxPayOrderP.setBody(order.getDetail()); | |||||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| wxPayOrderP.setGoods_tag(String.valueOf(order.getProductId())); | |||||
| wxPayOrderP.setNotify_url(payAccount.getPayNotifyUrl()); | |||||
| wxPayOrderP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | |||||
| wxPayOrderP.setProduct_id(String.valueOf(order.getId())); // 订单ID | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderP); | |||||
| wxPayOrderP.setSign(WxPayment.createSign(payOrderMap, payAccount.getApiKey())); | |||||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderP)); | |||||
| logger.info("pay order, wechat pushOrder, " + wxPayOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| String prepay_id = returnMap.get("prepay_id"); | |||||
| // update payOrder with prepay_id | |||||
| record.setPrepayId(prepay_id); | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); | |||||
| Map<String, String> sighMap = MapUtil.getOrderMap(); | |||||
| sighMap.put("appId", returnMap.get("appid")); | |||||
| sighMap.put("timeStamp", timestamp); | |||||
| sighMap.put("nonceStr", noncestr); | |||||
| sighMap.put("package", "prepay_id=" + prepay_id); | |||||
| sighMap.put("signType", "MD5"); | |||||
| String signAgent = WxPayment.createSign(sighMap, payAccount.getApiKey()); | |||||
| returnMap.put("timeStamp", timestamp); | |||||
| returnMap.put("nonceStr", noncestr); | |||||
| returnMap.put("package", "prepay_id=" + prepay_id); | |||||
| returnMap.put("paySign", signAgent); | |||||
| logger.info("back to UI: " + returnMap.toString()); | |||||
| return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); | |||||
| } else { | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorMap.getJSONObject(result_code); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } else { | |||||
| // 统一下单 // 服务商模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxPayOrderSP wxPayOrderSP = new WxPayOrderSP(); | |||||
| wxPayOrderSP.setSub_openid(user.getOpenId()); | |||||
| wxPayOrderSP.setAppid(appInfo.getParentAppId()); | |||||
| wxPayOrderSP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderSP.setSub_appid(user.getAppId()); | |||||
| wxPayOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||||
| wxPayOrderSP.setNonce_str(noncestr); | |||||
| wxPayOrderSP.setBody(order.getDetail()); | |||||
| wxPayOrderSP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderSP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderSP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| wxPayOrderSP.setGoods_tag(String.valueOf(order.getProductId())); // 券ID | |||||
| wxPayOrderSP.setNotify_url(payAccount.getPayNotifyUrl()); | |||||
| wxPayOrderSP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | |||||
| wxPayOrderSP.setProduct_id(String.valueOf(order.getProductId())); // 券ID | |||||
| wxPayOrderSP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||||
| wxPayOrderSP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| wxPayOrderSP.setSign_type("HMAC-SHA256"); | |||||
| wxPayOrderSP.setProfit_sharing(null); | |||||
| if (isShare == EnumPayShare.YES) { | |||||
| wxPayOrderSP.setProfit_sharing("Y"); | |||||
| } | |||||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderSP); | |||||
| wxPayOrderSP.setSign(WxPayment.createSignHMAC(payOrderMap, payAccount.getApiKey())); | |||||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderSP)); | |||||
| logger.info("pay order, wechat pushOrder, " + wxPayOrderSP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| String prepay_id = returnMap.get("prepay_id"); | |||||
| // update payOrder with prepay_id | |||||
| record.setPrepayId(prepay_id); | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); | |||||
| Map<String, String> sighMap = MapUtil.getOrderMap(); | |||||
| sighMap.put("appId", appInfo.getAppId()); | |||||
| sighMap.put("timeStamp", timestamp); | |||||
| sighMap.put("nonceStr", noncestr); | |||||
| sighMap.put("package", "prepay_id=" + prepay_id); | |||||
| sighMap.put("signType", "HMAC-SHA256"); | |||||
| String signAgent = WxPayment.createSignHMAC(sighMap, payAccount.getApiKey()); | |||||
| returnMap.put("timeStamp", timestamp); | |||||
| returnMap.put("nonceStr", noncestr); | |||||
| returnMap.put("package", "prepay_id=" + prepay_id); | |||||
| returnMap.put("paySign", signAgent); | |||||
| returnMap.put("signType", "HMAC-SHA256"); | |||||
| logger.info("back to UI: " + returnMap.toString()); | |||||
| return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); | |||||
| } else { | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorMap.getJSONObject(result_code); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } | |||||
| } else { | |||||
| // 虚拟支付 | |||||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||||
| // 统一下单 普通商户模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxPayOrderP wxPayOrderP = new WxPayOrderP(); | WxPayOrderP wxPayOrderP = new WxPayOrderP(); | ||||
| wxPayOrderP.setOpenid(user.getOpenId()); | wxPayOrderP.setOpenid(user.getOpenId()); | ||||
| wxPayOrderP.setAppid(user.getAppId()); | wxPayOrderP.setAppid(user.getAppId()); | ||||
| wxPayOrderP.setMch_id(payAccount.getMchId()); | wxPayOrderP.setMch_id(payAccount.getMchId()); | ||||
| wxPayOrderP.setNonce_str(noncestr); | |||||
| wxPayOrderP.setBody(order.getDetail()); | wxPayOrderP.setBody(order.getDetail()); | ||||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | ||||
| wxPayOrderP.setTotal_fee(order.getPayment()); | wxPayOrderP.setTotal_fee(order.getPayment()); | ||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | ||||
| wxPayOrderP.setGoods_tag(String.valueOf(order.getProductId())); // 券ID | |||||
| wxPayOrderP.setGoods_tag(String.valueOf(order.getProductId())); | |||||
| wxPayOrderP.setNotify_url(payAccount.getPayNotifyUrl()); | wxPayOrderP.setNotify_url(payAccount.getPayNotifyUrl()); | ||||
| wxPayOrderP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | wxPayOrderP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | ||||
| wxPayOrderP.setProduct_id(String.valueOf(order.getProductId())); // 券ID | |||||
| wxPayOrderP.setProduct_id(String.valueOf(order.getId())); // 订单ID | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | ||||
| Date futureDate = new Date(); | Date futureDate = new Date(); | ||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | ||||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | ||||
| wxPayOrderP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxPayOrderP), payAccount.getApiKey())); | |||||
| Map<String, String> returnMap = BeanUtils.toStringMap(wxPayOrderP); | |||||
| return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); | |||||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderP); | |||||
| wxPayOrderP.setSign(WxPayment.createSign(payOrderMap, payAccount.getApiKey())); | |||||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderP)); | |||||
| logger.info("pay order, wechat pushOrder, " + wxPayOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| String prepay_id = returnMap.get("prepay_id"); | |||||
| // update payOrder with prepay_id | |||||
| record.setPrepayId(prepay_id); | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); | |||||
| Map<String, String> sighMap = MapUtil.getOrderMap(); | |||||
| sighMap.put("appId", returnMap.get("appid")); | |||||
| sighMap.put("timeStamp", timestamp); | |||||
| sighMap.put("nonceStr", noncestr); | |||||
| sighMap.put("package", "prepay_id=" + prepay_id); | |||||
| sighMap.put("signType", "MD5"); | |||||
| String signAgent = WxPayment.createSign(sighMap, payAccount.getApiKey()); | |||||
| returnMap.put("timeStamp", timestamp); | |||||
| returnMap.put("nonceStr", noncestr); | |||||
| returnMap.put("package", "prepay_id=" + prepay_id); | |||||
| returnMap.put("paySign", signAgent); | |||||
| logger.info("back to UI: " + returnMap.toString()); | |||||
| return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); | |||||
| } else { | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorMap.getJSONObject(result_code); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } else { | |||||
| // 统一下单 // 服务商模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxPayOrderSP wxPayOrderSP = new WxPayOrderSP(); | |||||
| wxPayOrderSP.setSub_openid(user.getOpenId()); | |||||
| wxPayOrderSP.setAppid(appInfo.getParentAppId()); | |||||
| wxPayOrderSP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderSP.setSub_appid(user.getAppId()); | |||||
| wxPayOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||||
| wxPayOrderSP.setNonce_str(noncestr); | |||||
| wxPayOrderSP.setBody(order.getDetail()); | |||||
| wxPayOrderSP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderSP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderSP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| wxPayOrderSP.setGoods_tag(String.valueOf(order.getProductId())); // 券ID | |||||
| wxPayOrderSP.setNotify_url(payAccount.getPayNotifyUrl()); | |||||
| wxPayOrderSP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | |||||
| wxPayOrderSP.setProduct_id(String.valueOf(order.getProductId())); // 券ID | |||||
| wxPayOrderSP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||||
| wxPayOrderSP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| wxPayOrderSP.setSign_type("HMAC-SHA256"); | |||||
| wxPayOrderSP.setProfit_sharing(null); | |||||
| if (isShare == EnumPayShare.YES) { | |||||
| wxPayOrderSP.setProfit_sharing("Y"); | |||||
| } | |||||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderSP); | |||||
| wxPayOrderSP.setSign(WxPayment.createSignHMAC(payOrderMap, payAccount.getApiKey())); | |||||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderSP)); | |||||
| logger.info("pay order, wechat pushOrder, " + wxPayOrderSP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| String prepay_id = returnMap.get("prepay_id"); | |||||
| // update payOrder with prepay_id | |||||
| record.setPrepayId(prepay_id); | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| String timestamp = String.valueOf(Utility.getCurrentTimeStamp()); | |||||
| Map<String, String> sighMap = MapUtil.getOrderMap(); | |||||
| sighMap.put("appId", appInfo.getAppId()); | |||||
| sighMap.put("timeStamp", timestamp); | |||||
| sighMap.put("nonceStr", noncestr); | |||||
| sighMap.put("package", "prepay_id=" + prepay_id); | |||||
| sighMap.put("signType", "HMAC-SHA256"); | |||||
| String signAgent = WxPayment.createSignHMAC(sighMap, payAccount.getApiKey()); | |||||
| returnMap.put("timeStamp", timestamp); | |||||
| returnMap.put("nonceStr", noncestr); | |||||
| returnMap.put("package", "prepay_id=" + prepay_id); | |||||
| returnMap.put("paySign", signAgent); | |||||
| returnMap.put("signType", "HMAC-SHA256"); | |||||
| logger.info("back to UI: " + returnMap.toString()); | |||||
| return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); | |||||
| } else { | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorMap.getJSONObject(result_code); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } | } | ||||
| } catch (RuntimeException e) { | } catch (RuntimeException e) { | ||||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | ||||
| @@ -408,7 +383,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public ResultData createMicroPayOrder(boolean isReal, WxMerchantBUser user, WxPayOrder record, EnumPayWay payWay) { | |||||
| public ResultData createMicroPayOrder(WxMerchantBUser user, WxPayOrder record, EnumPayWay payWay) { | |||||
| final IdWorker idworker = IdWorker.get(); | final IdWorker idworker = IdWorker.get(); | ||||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(user.getTenantId()); | WxAppinfo appInfo = wxAppinfoService.getCAppInfo(user.getTenantId()); | ||||
| @@ -493,62 +468,47 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| payOrderNo = String.valueOf(record.getId()); | payOrderNo = String.valueOf(record.getId()); | ||||
| } | } | ||||
| if (isReal) { | |||||
| // 微信实际支付 | |||||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||||
| // 刷卡支付 普通商户模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxMicroPayOrderP wxPayOrderP = new WxMicroPayOrderP(); | |||||
| wxPayOrderP.setAppid(user.getAppId()); | |||||
| wxPayOrderP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderP.setDevice_info(user.getPhone()); | |||||
| wxPayOrderP.setNonce_str(noncestr); | |||||
| wxPayOrderP.setBody(order.getDetail()); | |||||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| wxPayOrderP.setAuth_code(record.getAuthCode()); | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderP); | |||||
| wxPayOrderP.setSign(WxPayment.createSign(payOrderMap, payAccount.getApiKey())); | |||||
| String response = WxPay.micropay(BeanUtils.toStringMap(wxPayOrderP)); | |||||
| logger.info("pay order, wechat micropay, " + wxPayOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| returnMap.put("orderId", orderNo); | |||||
| String return_code = returnMap.get("return_code"); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| String openId = returnMap.get("openid"); | |||||
| String isSubscribe = returnMap.get("is_subscribe"); | |||||
| String transactionId = returnMap.get("transaction_id"); | |||||
| record.setTransactionId(transactionId); | |||||
| record.setUpdateTime(new Date()); | |||||
| handleMicroOrderPaySuccess(record, transactionId, openId, isSubscribe); | |||||
| return new ResultData(Result.SUCCESS, "刷卡支付成功", returnMap); | |||||
| } else { | |||||
| String err_code = returnMap.get("err_code"); | |||||
| String errMsg = returnMap.get("err_code_des"); | |||||
| if (errMsg.length() <= 0) { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| } | |||||
| record.setFailReason(errMsg); | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||||
| // 刷卡支付 普通商户模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxMicroPayOrderP wxPayOrderP = new WxMicroPayOrderP(); | |||||
| wxPayOrderP.setAppid(user.getAppId()); | |||||
| wxPayOrderP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderP.setDevice_info(user.getPhone()); | |||||
| wxPayOrderP.setNonce_str(noncestr); | |||||
| wxPayOrderP.setBody(order.getDetail()); | |||||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| wxPayOrderP.setAuth_code(record.getAuthCode()); | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderP); | |||||
| wxPayOrderP.setSign(WxPayment.createSign(payOrderMap, payAccount.getApiKey())); | |||||
| String response = WxPay.micropay(BeanUtils.toStringMap(wxPayOrderP)); | |||||
| logger.info("pay order, wechat micropay, " + wxPayOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| returnMap.put("orderId", orderNo); | |||||
| String return_code = returnMap.get("return_code"); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| String openId = returnMap.get("openid"); | |||||
| String isSubscribe = returnMap.get("is_subscribe"); | |||||
| String transactionId = returnMap.get("transaction_id"); | |||||
| record.setTransactionId(transactionId); | |||||
| record.setUpdateTime(new Date()); | |||||
| handleMicroOrderPaySuccess(record, transactionId, openId, isSubscribe); | |||||
| return new ResultData(Result.SUCCESS, "刷卡支付成功", returnMap); | |||||
| } else { | } else { | ||||
| String errMsg = returnMap.get("return_msg"); | |||||
| String err_code = returnMap.get("err_code"); | |||||
| String errMsg = returnMap.get("err_code_des"); | |||||
| if (errMsg.length() <= 0) { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| } | |||||
| record.setFailReason(errMsg); | record.setFailReason(errMsg); | ||||
| record.setUpdateTime(new Date()); | record.setUpdateTime(new Date()); | ||||
| try { | try { | ||||
| @@ -560,66 +520,66 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | ||||
| } | } | ||||
| } else { | } else { | ||||
| // 统一下单 // 服务商模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxMicroPayOrderSP wxPayOrderSP = new WxMicroPayOrderSP(); | |||||
| wxPayOrderSP.setAppid(appInfo.getParentAppId()); | |||||
| wxPayOrderSP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderSP.setSub_appid(appInfo.getAppId()); | |||||
| wxPayOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||||
| wxPayOrderSP.setDevice_info(user.getPhone()); | |||||
| wxPayOrderSP.setNonce_str(noncestr); | |||||
| wxPayOrderSP.setBody(order.getDetail()); | |||||
| wxPayOrderSP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderSP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderSP.setSpbill_create_ip(record.getIp()); | |||||
| wxPayOrderSP.setAuth_code(record.getAuthCode()); | |||||
| wxPayOrderSP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||||
| wxPayOrderSP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| wxPayOrderSP.setSign_type("HMAC-SHA256"); | |||||
| wxPayOrderSP.setProfit_sharing(null); | |||||
| if (isShare == EnumPayShare.YES) { | |||||
| wxPayOrderSP.setProfit_sharing("Y"); | |||||
| String errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | } | ||||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderSP); | |||||
| wxPayOrderSP.setSign(WxPayment.createSignHMAC(payOrderMap, payAccount.getApiKey())); | |||||
| String response = WxPay.micropay(BeanUtils.toStringMap(wxPayOrderSP)); | |||||
| logger.info("pay order, wechat micropay, " + wxPayOrderSP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| returnMap.put("orderId", orderNo); | |||||
| String return_code = returnMap.get("return_code"); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| String openId = returnMap.get("sub_openid"); | |||||
| String isSubscribe = returnMap.get("sub_is_subscribe"); | |||||
| String transactionId = returnMap.get("transaction_id"); | |||||
| record.setTransactionId(transactionId); | |||||
| record.setUpdateTime(new Date()); | |||||
| handleMicroOrderPaySuccess(record, transactionId, openId, isSubscribe); | |||||
| return new ResultData(Result.SUCCESS, "刷卡支付成功", returnMap); | |||||
| } else { | |||||
| String err_code = returnMap.get("err_code"); | |||||
| String errMsg = returnMap.get("err_code_des"); | |||||
| if (errMsg.length() <= 0) { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| } | |||||
| record.setFailReason(errMsg); | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } else { | |||||
| // 统一下单 // 服务商模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxMicroPayOrderSP wxPayOrderSP = new WxMicroPayOrderSP(); | |||||
| wxPayOrderSP.setAppid(appInfo.getParentAppId()); | |||||
| wxPayOrderSP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderSP.setSub_appid(appInfo.getAppId()); | |||||
| wxPayOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||||
| wxPayOrderSP.setDevice_info(user.getPhone()); | |||||
| wxPayOrderSP.setNonce_str(noncestr); | |||||
| wxPayOrderSP.setBody(order.getDetail()); | |||||
| wxPayOrderSP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderSP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderSP.setSpbill_create_ip(record.getIp()); | |||||
| wxPayOrderSP.setAuth_code(record.getAuthCode()); | |||||
| wxPayOrderSP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||||
| wxPayOrderSP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| wxPayOrderSP.setSign_type("HMAC-SHA256"); | |||||
| wxPayOrderSP.setProfit_sharing(null); | |||||
| if (isShare == EnumPayShare.YES) { | |||||
| wxPayOrderSP.setProfit_sharing("Y"); | |||||
| } | |||||
| Map<String, String> payOrderMap = BeanUtils.toStringMap(wxPayOrderSP); | |||||
| wxPayOrderSP.setSign(WxPayment.createSignHMAC(payOrderMap, payAccount.getApiKey())); | |||||
| String response = WxPay.micropay(BeanUtils.toStringMap(wxPayOrderSP)); | |||||
| logger.info("pay order, wechat micropay, " + wxPayOrderSP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| returnMap.put("orderId", orderNo); | |||||
| String return_code = returnMap.get("return_code"); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| String openId = returnMap.get("sub_openid"); | |||||
| String isSubscribe = returnMap.get("sub_is_subscribe"); | |||||
| String transactionId = returnMap.get("transaction_id"); | |||||
| record.setTransactionId(transactionId); | |||||
| record.setUpdateTime(new Date()); | |||||
| handleMicroOrderPaySuccess(record, transactionId, openId, isSubscribe); | |||||
| return new ResultData(Result.SUCCESS, "刷卡支付成功", returnMap); | |||||
| } else { | } else { | ||||
| String errMsg = returnMap.get("return_msg"); | |||||
| String err_code = returnMap.get("err_code"); | |||||
| String errMsg = returnMap.get("err_code_des"); | |||||
| if (errMsg.length() <= 0) { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| } | |||||
| record.setFailReason(errMsg); | record.setFailReason(errMsg); | ||||
| record.setUpdateTime(new Date()); | record.setUpdateTime(new Date()); | ||||
| try { | try { | ||||
| @@ -630,25 +590,18 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| } | } | ||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | ||||
| } | } | ||||
| } else { | |||||
| String errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| record.setUpdateTime(new Date()); | |||||
| try { | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay order update error: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | } | ||||
| } else { | |||||
| // 虚拟支付 | |||||
| WxMicroPayOrderP wxPayOrderP = new WxMicroPayOrderP(); | |||||
| wxPayOrderP.setAppid(user.getAppId()); | |||||
| wxPayOrderP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderP.setBody(order.getDetail()); | |||||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| wxPayOrderP.setDevice_info(user.getPhone()); | |||||
| wxPayOrderP.setAuth_code(record.getAuthCode()); | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000); | |||||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| wxPayOrderP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxPayOrderP), payAccount.getApiKey())); | |||||
| Map<String, String> returnMap = BeanUtils.toStringMap(wxPayOrderP); | |||||
| return new ResultData(Result.SUCCESS, "创建刷卡支付订单成功", returnMap); | |||||
| } | } | ||||
| } catch (RuntimeException e) { | } catch (RuntimeException e) { | ||||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | ||||
| @@ -1363,7 +1316,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| wxCouponOrderService.sendCouponAfterMicroPay(record.getTenantId(), record.getOrderId(), record.getcUserId()); | wxCouponOrderService.sendCouponAfterMicroPay(record.getTenantId(), record.getOrderId(), record.getcUserId()); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("订单刷卡发券失败: orderId: {}, payOrderId: {}", record.getOrderId(), record.getId()); | logger.error("订单刷卡发券失败: orderId: {}, payOrderId: {}", record.getOrderId(), record.getId()); | ||||
| logger.error("订单刷卡发券失败: " +e.getMessage()); | |||||
| logger.error("订单刷卡发券失败: " + e.getMessage()); | |||||
| } | } | ||||
| logger.info("订单刷卡发券 结束"); | logger.info("订单刷卡发券 结束"); | ||||
| @@ -1384,7 +1337,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| wxOrderService.shareForMicroPay(tenantId, orderId, payOrderId); | wxOrderService.shareForMicroPay(tenantId, orderId, payOrderId); | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error("订单分账失败: orderId: {}, payOrderId: {}", orderId, payOrderId); | logger.error("订单分账失败: orderId: {}, payOrderId: {}", orderId, payOrderId); | ||||
| logger.error("订单分账失败: " +e.getMessage()); | |||||
| logger.error("订单分账失败: " + e.getMessage()); | |||||
| } | } | ||||
| logger.info("订单分账结束: orderId: {}, payOrderId: {}", orderId, payOrderId); | logger.info("订单分账结束: orderId: {}, payOrderId: {}", orderId, payOrderId); | ||||
| }).start(); | }).start(); | ||||
| @@ -234,26 +234,26 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| private boolean isMerchantOrder(WxOrder wxOrder, Long merchantId) { | private boolean isMerchantOrder(WxOrder wxOrder, Long merchantId) { | ||||
| if (wxOrder.getType().equals(EnumOrderType.COUPON.getCode())){ | |||||
| if (wxOrder.getType().equals(EnumOrderType.COUPON.getCode())) { | |||||
| WxCoupon wxCoupon = wxCouponMapper.selectByPrimaryKey(wxOrder.getProductId()); | WxCoupon wxCoupon = wxCouponMapper.selectByPrimaryKey(wxOrder.getProductId()); | ||||
| if (wxCoupon != null) { | if (wxCoupon != null) { | ||||
| WxCouponMerchant wxCouponMerchant = new WxCouponMerchant(); | WxCouponMerchant wxCouponMerchant = new WxCouponMerchant(); | ||||
| wxCouponMerchant.setProductId(wxCoupon.getId()); | wxCouponMerchant.setProductId(wxCoupon.getId()); | ||||
| wxCouponMerchant.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | wxCouponMerchant.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | ||||
| List<WxCouponMerchant> couponMerchantList = wxCouponMerchantMapper.findList(wxCouponMerchant); | |||||
| if (couponMerchantList.stream().anyMatch(cm->cm.getMerchantId().equals(merchantId))){ | |||||
| List<WxCouponMerchant> couponMerchantList = wxCouponMerchantMapper.findList(wxCouponMerchant); | |||||
| if (couponMerchantList.stream().anyMatch(cm -> cm.getMerchantId().equals(merchantId))) { | |||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| }else if(wxOrder.getType().equals(EnumOrderType.MICROPAY.getCode())) { | |||||
| } else if (wxOrder.getType().equals(EnumOrderType.MICROPAY.getCode())) { | |||||
| WxMerchantBUser wxMerchantBUser = wxMerchantBUserMapper.selectByPrimaryKey(wxOrder.getProductId()); | WxMerchantBUser wxMerchantBUser = wxMerchantBUserMapper.selectByPrimaryKey(wxOrder.getProductId()); | ||||
| if (wxMerchantBUser != null && wxMerchantBUser.equals(merchantId)) { | if (wxMerchantBUser != null && wxMerchantBUser.equals(merchantId)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| }else if(wxOrder.getType().equals(EnumOrderType.NATIVEPAY.getCode())) { | |||||
| } else if (wxOrder.getType().equals(EnumOrderType.NATIVEPAY.getCode())) { | |||||
| }else if(wxOrder.getType().equals(EnumOrderType.PREPAIDCARD.getCode())) { | |||||
| } else if (wxOrder.getType().equals(EnumOrderType.PREPAIDCARD.getCode())) { | |||||
| } | } | ||||
| @@ -263,7 +263,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| @Override | @Override | ||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
| public ResultData createRefundOrder(boolean isReal, WxAppinfo appInfo, Long couponOrderId, EnumPayType payType, Long bUserId) { | |||||
| public ResultData createRefundOrder(WxAppinfo appInfo, Long couponOrderId, EnumPayType payType, Long bUserId) { | |||||
| WxCouponOrder wxCouponOrder = wxCouponOrderMapper.selectByPrimaryKey(couponOrderId); | WxCouponOrder wxCouponOrder = wxCouponOrderMapper.selectByPrimaryKey(couponOrderId); | ||||
| if (wxCouponOrder == null) { | if (wxCouponOrder == null) { | ||||
| logger.error("券ID不存在:" + couponOrderId); | logger.error("券ID不存在:" + couponOrderId); | ||||
| @@ -342,14 +342,14 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| } | } | ||||
| // 更改 couponOrder 状态 | // 更改 couponOrder 状态 | ||||
| if(wxCouponOrder.getCouponType().equals(EnumCouponType.CARD_MULTIMCH.getCode())) { | |||||
| if (wxCouponOrder.getCouponType().equals(EnumCouponType.CARD_MULTIMCH.getCode())) { | |||||
| wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.CARD_RETURNED.getCode()); // 卡线下退款 | wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.CARD_RETURNED.getCode()); // 卡线下退款 | ||||
| } else { | } else { | ||||
| wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_INVALID.getCode()); //3退款,券作废 | wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_INVALID.getCode()); //3退款,券作废 | ||||
| } | } | ||||
| if (payType == EnumPayType.PAY_B_REFUND) { | if (payType == EnumPayType.PAY_B_REFUND) { | ||||
| wxCouponOrder.setbUserId(bUserId); | wxCouponOrder.setbUserId(bUserId); | ||||
| } else{ | |||||
| } else { | |||||
| wxCouponOrder.setbUserId(payType.getCode().longValue());//其他退款模式将退款方式存入BUSERID | wxCouponOrder.setbUserId(payType.getCode().longValue());//其他退款模式将退款方式存入BUSERID | ||||
| } | } | ||||
| wxCouponOrder.setUpdateDate(currentDate); | wxCouponOrder.setUpdateDate(currentDate); | ||||
| @@ -430,169 +430,10 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| logger.error("退款订单已存在, 无法再提交退款申请"); | logger.error("退款订单已存在, 无法再提交退款申请"); | ||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_EXIST.getCode(), "退款订单已存在, 无法再提交退款申请"); | throw new MallinkException(ErrorCode.REFUND_ORDER_EXIST.getCode(), "退款订单已存在, 无法再提交退款申请"); | ||||
| } | } | ||||
| if (isReal) { | |||||
| // 实际支付 | |||||
| // 向微信提交退款申请 | |||||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||||
| // 普通商户模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxRefundOrderP wxRefundOrderP = new WxRefundOrderP(); | |||||
| wxRefundOrderP.setAppid(appInfo.getAppId()); | |||||
| wxRefundOrderP.setMch_id(payAccount.getMchId()); | |||||
| wxRefundOrderP.setNonce_str(noncestr); | |||||
| // 微信内部订单号 | |||||
| if (record.getTransactionId() != null) | |||||
| wxRefundOrderP.setTransaction_id(record.getTransactionId()); | |||||
| // 支付订单号 | |||||
| wxRefundOrderP.setOut_trade_no(payOrder.getPayOrderNo()); | |||||
| // 退款支付订单号 | |||||
| wxRefundOrderP.setOut_refund_no(out_refund_id); | |||||
| wxRefundOrderP.setTotal_fee(record.getTotalFee()); | |||||
| wxRefundOrderP.setRefund_fee(record.getRefundFee()); | |||||
| if (payType == EnumPayType.PAY_B_REFUND) { | |||||
| wxRefundOrderP.setRefund_desc("B端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_ADMIN_REFUND) { | |||||
| wxRefundOrderP.setRefund_desc("管理端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_AUTO_REFUND) { | |||||
| wxRefundOrderP.setRefund_desc("超期自动退款"); | |||||
| } else { | |||||
| wxRefundOrderP.setRefund_desc("用户自己退款"); | |||||
| } | |||||
| wxRefundOrderP.setNotify_url(payAccount.getRefundNotifyUrl()); | |||||
| Map signMap = null; | |||||
| try { | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderP); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款命令生辰: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | |||||
| } | |||||
| String signAgent = WxPayment.createSign(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = null; | |||||
| try { | |||||
| response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); | |||||
| } | |||||
| logger.info("微信退款订单:" + wxRefundOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| record.setRefundVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.info("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + response); | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(ErrorCode.REFUND_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } else { | |||||
| // 服务商模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxRefundOrderSP wxRefundOrderSP = new WxRefundOrderSP(); | |||||
| wxRefundOrderSP.setAppid(appInfo.getParentAppId()); | |||||
| wxRefundOrderSP.setSub_appid(appInfo.getAppId()); | |||||
| wxRefundOrderSP.setMch_id(payAccount.getMchId()); | |||||
| wxRefundOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||||
| wxRefundOrderSP.setNonce_str(noncestr); | |||||
| // 微信内部订单号 | |||||
| if (record.getTransactionId() != null) | |||||
| wxRefundOrderSP.setTransaction_id(record.getTransactionId()); | |||||
| // 支付订单号 | |||||
| wxRefundOrderSP.setOut_trade_no(payOrder.getPayOrderNo()); | |||||
| // 退款支付订单号 | |||||
| wxRefundOrderSP.setOut_refund_no(out_refund_id); | |||||
| wxRefundOrderSP.setTotal_fee(record.getTotalFee()); | |||||
| wxRefundOrderSP.setRefund_fee(record.getRefundFee()); | |||||
| if (payType == EnumPayType.PAY_B_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("B端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_ADMIN_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("管理端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_AUTO_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("超期自动退款"); | |||||
| } else { | |||||
| wxRefundOrderSP.setRefund_desc("用户自己退款"); | |||||
| } | |||||
| wxRefundOrderSP.setNotify_url(payAccount.getRefundNotifyUrl()); | |||||
| wxRefundOrderSP.setSign_type("HMAC-SHA256"); | |||||
| Map signMap = null; | |||||
| try { | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderSP); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款命令生辰: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | |||||
| } | |||||
| String signAgent = WxPayment.createSignHMAC(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = null; | |||||
| try { | |||||
| response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); | |||||
| } | |||||
| logger.info("微信退款订单:" + wxRefundOrderSP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| record.setRefundVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.info("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "订单状态更新失败"); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + response); | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), errMsg); | |||||
| } | |||||
| } | |||||
| } else { | |||||
| // 虚拟支付 | |||||
| // 向微信提交退款申请 | |||||
| // 实际支付 | |||||
| // 向微信提交退款申请 | |||||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||||
| // 普通商户模式 | |||||
| String noncestr = Utility.generate32UUID(); | String noncestr = Utility.generate32UUID(); | ||||
| WxRefundOrderP wxRefundOrderP = new WxRefundOrderP(); | WxRefundOrderP wxRefundOrderP = new WxRefundOrderP(); | ||||
| wxRefundOrderP.setAppid(appInfo.getAppId()); | wxRefundOrderP.setAppid(appInfo.getAppId()); | ||||
| @@ -618,27 +459,140 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| } | } | ||||
| wxRefundOrderP.setNotify_url(payAccount.getRefundNotifyUrl()); | wxRefundOrderP.setNotify_url(payAccount.getRefundNotifyUrl()); | ||||
| Map returnMap = null; | |||||
| Map signMap = null; | |||||
| try { | try { | ||||
| returnMap = BeanUtils.toStringMap(wxRefundOrderP); | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderP); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("退款签名异常"); | |||||
| logger.error("退款命令生辰: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | ||||
| } | } | ||||
| String signAgent = WxPayment.createSign(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = null; | |||||
| try { | try { | ||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); | |||||
| } | |||||
| logger.info("微信退款订单:" + wxRefundOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| record.setRefundVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.info("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + response); | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | wxRefundOrderMapper.updateByPrimaryKeySelective(record); | ||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| return new ResultData(ErrorCode.REFUND_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } else { | |||||
| // 服务商模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxRefundOrderSP wxRefundOrderSP = new WxRefundOrderSP(); | |||||
| wxRefundOrderSP.setAppid(appInfo.getParentAppId()); | |||||
| wxRefundOrderSP.setSub_appid(appInfo.getAppId()); | |||||
| wxRefundOrderSP.setMch_id(payAccount.getMchId()); | |||||
| wxRefundOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||||
| wxRefundOrderSP.setNonce_str(noncestr); | |||||
| // 微信内部订单号 | |||||
| if (record.getTransactionId() != null) | |||||
| wxRefundOrderSP.setTransaction_id(record.getTransactionId()); | |||||
| // 支付订单号 | |||||
| wxRefundOrderSP.setOut_trade_no(payOrder.getPayOrderNo()); | |||||
| // 退款支付订单号 | |||||
| wxRefundOrderSP.setOut_refund_no(out_refund_id); | |||||
| wxRefundOrderSP.setTotal_fee(record.getTotalFee()); | |||||
| wxRefundOrderSP.setRefund_fee(record.getRefundFee()); | |||||
| if (payType == EnumPayType.PAY_B_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("B端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_ADMIN_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("管理端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_AUTO_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("超期自动退款"); | |||||
| } else { | |||||
| wxRefundOrderSP.setRefund_desc("用户自己退款"); | |||||
| } | |||||
| wxRefundOrderSP.setNotify_url(payAccount.getRefundNotifyUrl()); | |||||
| wxRefundOrderSP.setSign_type("HMAC-SHA256"); | |||||
| Map signMap = null; | |||||
| try { | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderSP); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||||
| logger.error("退款命令生辰: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | |||||
| } | |||||
| String signAgent = WxPayment.createSignHMAC(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = null; | |||||
| try { | |||||
| response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); | |||||
| } | |||||
| logger.info("微信退款订单:" + wxRefundOrderSP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| record.setRefundVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.info("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "订单状态更新失败"); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + response); | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), errMsg); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @Override | @Override | ||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
| public ResultData createRefundOrderFromMicroPay(boolean isReal, WxAppinfo appInfo, Long orderId, EnumPayType payType, Long bUserId) { | |||||
| public ResultData createRefundOrderFromMicroPay(WxAppinfo appInfo, Long orderId, EnumPayType payType, Long bUserId) { | |||||
| WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(orderId); | WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(orderId); | ||||
| if (payType == EnumPayType.PAY_B_REFUND) { | if (payType == EnumPayType.PAY_B_REFUND) { | ||||
| @@ -766,168 +720,9 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_EXIST.getCode(), "退款订单已存在, 无法再提交退款申请"); | throw new MallinkException(ErrorCode.REFUND_ORDER_EXIST.getCode(), "退款订单已存在, 无法再提交退款申请"); | ||||
| } | } | ||||
| if (isReal) { | |||||
| // 实际支付 | |||||
| // 向微信提交退款申请 | |||||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||||
| // 普通商户模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxRefundOrderP wxRefundOrderP = new WxRefundOrderP(); | |||||
| wxRefundOrderP.setAppid(appInfo.getAppId()); | |||||
| wxRefundOrderP.setMch_id(payAccount.getMchId()); | |||||
| wxRefundOrderP.setNonce_str(noncestr); | |||||
| // 微信内部订单号 | |||||
| if (record.getTransactionId() != null) | |||||
| wxRefundOrderP.setTransaction_id(record.getTransactionId()); | |||||
| // 支付订单号 | |||||
| wxRefundOrderP.setOut_trade_no(payOrder.getPayOrderNo()); | |||||
| // 退款支付订单号 | |||||
| wxRefundOrderP.setOut_refund_no(out_refund_id); | |||||
| wxRefundOrderP.setTotal_fee(record.getTotalFee()); | |||||
| wxRefundOrderP.setRefund_fee(record.getRefundFee()); | |||||
| if (payType == EnumPayType.PAY_B_REFUND) { | |||||
| wxRefundOrderP.setRefund_desc("B端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_ADMIN_REFUND) { | |||||
| wxRefundOrderP.setRefund_desc("管理端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_AUTO_REFUND) { | |||||
| wxRefundOrderP.setRefund_desc("超期自动退款"); | |||||
| } else { | |||||
| wxRefundOrderP.setRefund_desc("用户自己退款"); | |||||
| } | |||||
| wxRefundOrderP.setNotify_url(payAccount.getRefundNotifyUrl()); | |||||
| Map signMap = null; | |||||
| try { | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderP); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款命令生辰: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | |||||
| } | |||||
| String signAgent = WxPayment.createSign(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = null; | |||||
| try { | |||||
| response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); | |||||
| } | |||||
| logger.info("微信退款订单:" + wxRefundOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| record.setRefundVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.info("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + response); | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(ErrorCode.REFUND_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } else { | |||||
| // 服务商模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxRefundOrderSP wxRefundOrderSP = new WxRefundOrderSP(); | |||||
| wxRefundOrderSP.setAppid(appInfo.getParentAppId()); | |||||
| wxRefundOrderSP.setSub_appid(appInfo.getAppId()); | |||||
| wxRefundOrderSP.setMch_id(payAccount.getMchId()); | |||||
| wxRefundOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||||
| wxRefundOrderSP.setNonce_str(noncestr); | |||||
| // 微信内部订单号 | |||||
| if (record.getTransactionId() != null) | |||||
| wxRefundOrderSP.setTransaction_id(record.getTransactionId()); | |||||
| // 支付订单号 | |||||
| wxRefundOrderSP.setOut_trade_no(payOrder.getPayOrderNo()); | |||||
| // 退款支付订单号 | |||||
| wxRefundOrderSP.setOut_refund_no(out_refund_id); | |||||
| wxRefundOrderSP.setTotal_fee(record.getTotalFee()); | |||||
| wxRefundOrderSP.setRefund_fee(record.getRefundFee()); | |||||
| if (payType == EnumPayType.PAY_B_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("B端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_ADMIN_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("管理端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_AUTO_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("超期自动退款"); | |||||
| } else { | |||||
| wxRefundOrderSP.setRefund_desc("用户自己退款"); | |||||
| } | |||||
| wxRefundOrderSP.setNotify_url(payAccount.getRefundNotifyUrl()); | |||||
| wxRefundOrderSP.setSign_type("HMAC-SHA256"); | |||||
| Map signMap = null; | |||||
| try { | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderSP); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款命令生辰: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | |||||
| } | |||||
| String signAgent = WxPayment.createSignHMAC(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = null; | |||||
| try { | |||||
| response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); | |||||
| } | |||||
| logger.info("微信退款订单:" + wxRefundOrderSP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| record.setRefundVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.info("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "订单状态更新失败"); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + response); | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), errMsg); | |||||
| } | |||||
| } | |||||
| } else { | |||||
| // 虚拟支付 | |||||
| // 向微信提交退款申请 | |||||
| // 向微信提交退款申请 | |||||
| if (payAccount.getType() == EnumPayMode.MCH.getCode()) { | |||||
| // 普通商户模式 | |||||
| String noncestr = Utility.generate32UUID(); | String noncestr = Utility.generate32UUID(); | ||||
| WxRefundOrderP wxRefundOrderP = new WxRefundOrderP(); | WxRefundOrderP wxRefundOrderP = new WxRefundOrderP(); | ||||
| wxRefundOrderP.setAppid(appInfo.getAppId()); | wxRefundOrderP.setAppid(appInfo.getAppId()); | ||||
| @@ -953,20 +748,133 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| } | } | ||||
| wxRefundOrderP.setNotify_url(payAccount.getRefundNotifyUrl()); | wxRefundOrderP.setNotify_url(payAccount.getRefundNotifyUrl()); | ||||
| Map returnMap = null; | |||||
| Map signMap = null; | |||||
| try { | try { | ||||
| returnMap = BeanUtils.toStringMap(wxRefundOrderP); | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderP); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("退款签名异常"); | |||||
| logger.error("退款命令生辰: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | ||||
| } | } | ||||
| String signAgent = WxPayment.createSign(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = null; | |||||
| try { | try { | ||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); | |||||
| } | |||||
| logger.info("微信退款订单:" + wxRefundOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| record.setRefundVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.info("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + response); | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | wxRefundOrderMapper.updateByPrimaryKeySelective(record); | ||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| return new ResultData(ErrorCode.REFUND_ORDER_ERROR.getCode(), errMsg, returnMap); | |||||
| } | |||||
| } else { | |||||
| // 服务商模式 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxRefundOrderSP wxRefundOrderSP = new WxRefundOrderSP(); | |||||
| wxRefundOrderSP.setAppid(appInfo.getParentAppId()); | |||||
| wxRefundOrderSP.setSub_appid(appInfo.getAppId()); | |||||
| wxRefundOrderSP.setMch_id(payAccount.getMchId()); | |||||
| wxRefundOrderSP.setSub_mch_id(payAccount.getSubMchId()); | |||||
| wxRefundOrderSP.setNonce_str(noncestr); | |||||
| // 微信内部订单号 | |||||
| if (record.getTransactionId() != null) | |||||
| wxRefundOrderSP.setTransaction_id(record.getTransactionId()); | |||||
| // 支付订单号 | |||||
| wxRefundOrderSP.setOut_trade_no(payOrder.getPayOrderNo()); | |||||
| // 退款支付订单号 | |||||
| wxRefundOrderSP.setOut_refund_no(out_refund_id); | |||||
| wxRefundOrderSP.setTotal_fee(record.getTotalFee()); | |||||
| wxRefundOrderSP.setRefund_fee(record.getRefundFee()); | |||||
| if (payType == EnumPayType.PAY_B_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("B端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_ADMIN_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("管理端商户退款"); | |||||
| } else if (payType == EnumPayType.PAY_AUTO_REFUND) { | |||||
| wxRefundOrderSP.setRefund_desc("超期自动退款"); | |||||
| } else { | |||||
| wxRefundOrderSP.setRefund_desc("用户自己退款"); | |||||
| } | |||||
| wxRefundOrderSP.setNotify_url(payAccount.getRefundNotifyUrl()); | |||||
| wxRefundOrderSP.setSign_type("HMAC-SHA256"); | |||||
| Map signMap = null; | |||||
| try { | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderSP); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||||
| logger.error("退款命令生辰: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | |||||
| } | |||||
| String signAgent = WxPayment.createSignHMAC(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = null; | |||||
| try { | |||||
| response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getMchId()); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "退款异常"); | |||||
| } | |||||
| logger.info("微信退款订单:" + wxRefundOrderSP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| record.setRefundVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.info("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), "订单状态更新失败"); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + response); | |||||
| String errMsg = ""; | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| if (errObj != null) { | |||||
| errMsg = errObj.toJSONString(); | |||||
| record.setFailReason(errMsg); | |||||
| } else { | |||||
| errMsg = returnMap.get("return_msg"); | |||||
| record.setFailReason(errMsg); | |||||
| } | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(record); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), errMsg); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||