| | |
| | | import com.ruoyi.common.security.utils.CodeFactoryUtil; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.order.domain.dto.*; |
| | | import com.ruoyi.order.domain.pojo.account.OrderPayment; |
| | | import com.ruoyi.order.domain.pojo.account.OrderRefund; |
| | | import com.ruoyi.order.domain.pojo.account.PaymentMessage; |
| | | import com.ruoyi.order.domain.pojo.order.ConsumerGoods; |
| | | import com.ruoyi.order.domain.pojo.order.Order; |
| | | import com.ruoyi.order.domain.pojo.order.OrderGoods; |
| | |
| | | import com.ruoyi.order.service.order.OrderGoodsService; |
| | | import com.ruoyi.order.service.order.OrderService; |
| | | import com.ruoyi.order.service.order.UserServiceRecordService; |
| | | import com.ruoyi.order.tools.request.ecommerce.profitsharing.ProfitSharingApplyRequest; |
| | | import com.ruoyi.order.tools.request.pay.combine.CombineTransactionsJsRequest; |
| | | import com.ruoyi.order.tools.service.ProfitsSharingService; |
| | | import com.ruoyi.system.api.constant.AppErrorConstant; |
| | | import com.ruoyi.system.api.constant.DelayTaskEnum; |
| | | import com.ruoyi.system.api.constant.SecurityConstant; |
| | |
| | | import com.ruoyi.system.api.domain.poji.sys.SysUser; |
| | | import com.ruoyi.system.api.domain.vo.*; |
| | | import com.ruoyi.system.api.service.*; |
| | | import com.wechat.pay.java.service.partnerpayments.jsapi.model.Transaction; |
| | | import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; |
| | | import com.wechat.pay.java.service.payments.jsapi.model.*; |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.wechat.pay.java.core.Config; |
| | | import com.wechat.pay.java.core.RSAConfig; |
| | | import com.wechat.pay.java.service.payments.jsapi.JsapiService; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | @Resource |
| | | private ProfitsSharingService profitsSharingService; |
| | | |
| | | @Autowired |
| | | private RedissonClient redissonClient; |
| | | |
| | | /** 商户号 */ |
| | | public static String merchantId = ""; |
| | | /** 商户API私钥路径 */ |
| | | public static String privateKeyPath = ""; |
| | | /** 商户证书序列号 */ |
| | | public static String merchantSerialNumber = ""; |
| | | /** 微信支付平台证书路径 */ |
| | | public static String wechatPayCertificatePath = ""; |
| | | /** 微信支付 APIv3 密钥 */ |
| | | public static String apiV3Key = ""; |
| | | /** 微信支付APPID */ |
| | | public static String appId=""; |
| | | /** 微信支付商户ID */ |
| | | public static String mchId=""; |
| | | /** 通知地址 */ |
| | | public static String notifyUrl=""; |
| | | |
| | | /** |
| | | * @description: buyGoods |
| | |
| | | appPlaceOrderVo.setOrderId(orderId); |
| | | appPlaceOrderVo.setOrderNo(orderNo); |
| | | // 调用支付 |
| | | /* CombineTransactionsJsRequest request=new CombineTransactionsJsRequest(); |
| | | request.setCombineAppid(); |
| | | request.setCombineMchid(); |
| | | profitsSharingService.combineTransactions(request);*/ |
| | | |
| | | //构建预下单支付对象 |
| | | PrepayRequest request = new PrepayRequest(); |
| | | Amount amount = new Amount(); |
| | | amount.setTotal(Integer.parseInt(order.getPayMoney().multiply(new BigDecimal(100)).toString())); |
| | | request.setAmount(amount); |
| | | request.setAppid(this.appId); |
| | | request.setMchid(this.mchId); |
| | | request.setDescription(order.getGoodsInfo()); |
| | | request.setNotifyUrl(this.notifyUrl); |
| | | request.setOutTradeNo(order.getOrderId()); |
| | | Payer payer = new Payer(); payer.setOpenid("oLTPCuN5a-nBD4rAL_fa********"); |
| | | |
| | | request.setPayer(payer); |
| | | |
| | | //设置订单允许分账 秒杀活动才允许分账 |
| | | /* if(order.getOrderFrom()==2){ |
| | | SettleInfo settleInfo=new SettleInfo(); |
| | | settleInfo.setProfitSharing(true); |
| | | request.setSettleInfo(settleInfo); |
| | | }*/ |
| | | |
| | | |
| | | //返回前端唤醒支付结果信息 |
| | | PrepayWithRequestPaymentResponse res = this.getJsApIResponse(request); |
| | | |
| | | appPlaceOrderVo.setAppId(this.appId); |
| | | appPlaceOrderVo.setTimeStamp(res.getTimeStamp()); |
| | | appPlaceOrderVo.setNonceStr(res.getNonceStr()); |
| | | appPlaceOrderVo.setPackageStr(res.getPackageVal()); |
| | | appPlaceOrderVo.setTradeType(res.getSignType()); |
| | | appPlaceOrderVo.setPaySign(res.getPaySign()); |
| | | |
| | | |
| | | //减去优惠券 |
| | | if(memberCouponSJ!=null){ |
| | | remoteCouponService.useMemberCoupon(memberCouponSJ.toString()); |
| | |
| | | appPlaceOrderVo.setPayDeadlineTime(DateUtils.addMinutes(order.getCreateTime(),delayTime)); |
| | | return appPlaceOrderVo; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * 功能描述: 预下单,返回支付数据prePayId |
| | | * |
| | | * 构建对象参考 |
| | | * PrepayRequest request = new PrepayRequest(); |
| | | * Amount amount = new Amount(); |
| | | * amount.setTotal(100); |
| | | * request.setAmount(amount); |
| | | * request.setAppid("wxa9d9651ae******"); |
| | | * request.setMchid("190000****"); |
| | | * request.setDescription("测试商品标题"); |
| | | * request.setNotifyUrl("https://notify_url"); |
| | | * request.setOutTradeNo("out_trade_no_001"); |
| | | * Payer payer = new Payer(); |
| | | * payer.setOpenid("oLTPCuN5a-nBD4rAL_fa********"); |
| | | * request.setPayer(payer); |
| | | * |
| | | * @auther: linqingsong |
| | | * @date: 2023/7/22 16:13 |
| | | */ |
| | | /*public String getPrePayId(PrepayRequest request) { |
| | | Config config = |
| | | new RSAConfig.Builder() |
| | | .merchantId(merchantId) |
| | | .privateKeyFromPath(privateKeyPath) |
| | | .merchantSerialNumber(merchantSerialNumber) |
| | | .wechatPayCertificatesFromPath(wechatPayCertificatePath) |
| | | .build(); |
| | | JsapiService service = new JsapiService.Builder().config(config).build(); |
| | | PrepayResponse response = service.prepay(request); |
| | | return response.getPrepayId(); |
| | | }*/ |
| | | |
| | | |
| | | /** |
| | | * |
| | | * 功能描述: 预下单,并返回前端需要换起支付的字符串 |
| | | * |
| | | * 构建对象参考 |
| | | * * PrepayRequest request = new PrepayRequest(); |
| | | * * Amount amount = new Amount(); |
| | | * * amount.setTotal(100); |
| | | * * request.setAmount(amount); |
| | | * * request.setAppid("wxa9d9651ae******"); |
| | | * * request.setMchid("190000****"); |
| | | * * request.setDescription("测试商品标题"); |
| | | * * request.setNotifyUrl("https://notify_url"); |
| | | * * request.setOutTradeNo("out_trade_no_001"); |
| | | * * Payer payer = new Payer(); |
| | | * * payer.setOpenid("oLTPCuN5a-nBD4rAL_fa********"); |
| | | * * request.setPayer(payer); |
| | | * |
| | | * |
| | | * @auther: linqingsong |
| | | * @date: 2023/7/22 16:53 |
| | | */ |
| | | public PrepayWithRequestPaymentResponse getJsApIResponse(PrepayRequest request){ |
| | | Config config = |
| | | new RSAConfig.Builder() |
| | | .merchantId(merchantId) |
| | | .privateKeyFromPath(privateKeyPath) |
| | | .merchantSerialNumber(merchantSerialNumber) |
| | | .wechatPayCertificatesFromPath(wechatPayCertificatePath) |
| | | .build(); |
| | | JsapiServiceExtension service = new JsapiServiceExtension.Builder().config(config).build(); |
| | | |
| | | PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request); |
| | | |
| | | return response; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @param appPlaceActivityDto |
| | |
| | | agStockChangeDto.setUserId(order.getUserId()); |
| | | remoteActivityService.changeActivityStock(agStockChangeDto); |
| | | // 调用支付 |
| | | PrepayRequest request = new PrepayRequest(); |
| | | Amount amount = new Amount(); |
| | | amount.setTotal(Integer.parseInt(order.getPayMoney().multiply(new BigDecimal(100)).toString())); |
| | | request.setAmount(amount); |
| | | request.setAppid(this.appId); |
| | | request.setMchid(this.mchId); |
| | | request.setDescription(order.getGoodsInfo()); |
| | | request.setNotifyUrl(this.notifyUrl); |
| | | request.setOutTradeNo(order.getOrderId()); |
| | | Payer payer = new Payer(); |
| | | // TODO 获取openID |
| | | payer.setOpenid("oLTPCuN5a-nBD4rAL_fa********"); |
| | | |
| | | request.setPayer(payer); |
| | | |
| | | //设置订单允许分账 秒杀活动才允许分账 |
| | | if(order.getOrderFrom()==2){ |
| | | SettleInfo settleInfo=new SettleInfo(); |
| | | settleInfo.setProfitSharing(true); |
| | | request.setSettleInfo(settleInfo); |
| | | } |
| | | |
| | | |
| | | //返回前端唤醒支付结果信息 |
| | | PrepayWithRequestPaymentResponse res = this.getJsApIResponse(request); |
| | | |
| | | appPlaceOrderVo.setAppId(this.appId); |
| | | appPlaceOrderVo.setTimeStamp(res.getTimeStamp()); |
| | | appPlaceOrderVo.setNonceStr(res.getNonceStr()); |
| | | appPlaceOrderVo.setPackageStr(res.getPackageVal()); |
| | | appPlaceOrderVo.setTradeType(res.getSignType()); |
| | | appPlaceOrderVo.setPaySign(res.getPaySign()); |
| | | |
| | | |
| | | //生成自动取消订单延时任务 |
| | | Integer delayTime = 30; |
| | | if(redisService.hasKey(SecurityConstant.AUTO_CANCEL_ORDER_TIME)){ |
| | |
| | | SysUser sysUser = remoteUserService.getSysUser(order.getUserId()).getData(); |
| | | merVerifyOrderVo.setUserName(sysUser.getNickName()); |
| | | merVerifyOrderVo.setUserMobile(sysUser.getPhonenumber()); |
| | | // |
| | | if(order.getOrderFrom()==2){ |
| | | |
| | | //profitsSharingService.applyProfitSharing(); |
| | | } |
| | | return merVerifyOrderVo; |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | * @description 订单支付回调 |
| | | * @author jqs |
| | | * @date 2023/7/13 17:57 |
| | | * @param orderId |
| | | * @param Transaction |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void payBack(String orderId) { |
| | | public void payBack(Transaction transaction) { |
| | | // 更新订单状态 |
| | | String orderId=transaction.getOutTradeNo(); |
| | | Order order = this.getById(orderId); |
| | | order.setOrderStatus(2); |
| | | order.setPayTime(new Date()); |
| | |
| | | } |
| | | activityTotalChangeDto.setUserId(order.getUserId()); |
| | | remoteActivityService.changeActivityTotal(activityTotalChangeDto); |
| | | |
| | | |
| | | //活动订单进行分账 |
| | | ProfitSharingApplyRequest request=new ProfitSharingApplyRequest(); |
| | | request.setAppid(this.appId); |
| | | request.setSubMchid(""); |
| | | request.setTransactionId(transaction.getTransactionId()); |
| | | profitsSharingService.applyProfitSharing(request); |
| | | } |
| | | //生成支付记录 |
| | | OrderPayment orderPayment = new OrderPayment(); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | /** |