|
@@ -2,20 +2,28 @@ package com.yami.shop.api.controller;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
|
|
+import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
+import com.github.binarywang.wxpay.config.WxPayConfig;
|
|
|
+import com.github.binarywang.wxpay.constant.WxPayConstants;
|
|
|
+import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
+import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
|
|
import com.yami.shop.bean.app.param.PayParam;
|
|
|
import com.yami.shop.bean.model.Order;
|
|
|
import com.yami.shop.bean.model.RefundDelivery;
|
|
|
import com.yami.shop.bean.pay.PayInfoDto;
|
|
|
-import com.yami.shop.common.exception.GlobalException;
|
|
|
import com.yami.shop.common.util.Arith;
|
|
|
+import com.yami.shop.common.util.IPHelper;
|
|
|
import com.yami.shop.security.api.model.YamiUser;
|
|
|
import com.yami.shop.security.api.util.SecurityUtils;
|
|
|
import com.yami.shop.service.OrderService;
|
|
|
import com.yami.shop.service.PayService;
|
|
|
import com.yami.shop.service.RefundDeliveryService;
|
|
|
+import com.yami.shop.wx.config.WechatPayServiceConfig;
|
|
|
import com.yami.shop.wx.po.JsapiPayInfoPo;
|
|
|
import com.yami.shop.wx.service.WxProviderService;
|
|
|
import com.yami.shop.wx.utils.CullenUtils;
|
|
|
+import com.yami.shop.wx.utils.OrderUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
@@ -36,16 +44,45 @@ public class PayController {
|
|
|
private final RefundDeliveryService refundDeliveryService;
|
|
|
private final WxProviderService wxProviderService;
|
|
|
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ //@PostMapping("/doPay")
|
|
|
+ @ApiOperation(value = "ApiV2版本的服务商支付")
|
|
|
+ public ResponseEntity<?> doPay() {
|
|
|
+ WechatPayServiceConfig wxConfig = wxProviderService.getWxConfig();
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
+ payConfig.setAppId(wxConfig.getSpAppId());
|
|
|
+ payConfig.setMchId(wxConfig.getSpMchId());
|
|
|
+ payConfig.setSubAppId(wxConfig.getSubAppId());
|
|
|
+ payConfig.setSubMchId(wxConfig.getSubMchId());
|
|
|
+ payConfig.setMchKey(wxConfig.getApiV3Key());
|
|
|
+ payConfig.setKeyPath(wxConfig.getKeyPemPath());
|
|
|
+ WxPayService wxPayService = new WxPayServiceImpl();
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
+
|
|
|
+ WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
+ orderRequest.setBody("商城下单");
|
|
|
+ orderRequest.setOutTradeNo(OrderUtils.getOrderNo(""));
|
|
|
+ orderRequest.setTotalFee(1);
|
|
|
+ orderRequest.setSpbillCreateIp(IPHelper.getIpAddr());
|
|
|
+ orderRequest.setSubOpenid("owrSr6y0TGPHBU2tgMVoCO13Gjww");
|
|
|
+ orderRequest.setNotifyUrl("http://localhost:8112");
|
|
|
+ orderRequest.setTradeType(WxPayConstants.TradeType.JSAPI);
|
|
|
+ WxPayMpOrderResult wxPayMpOrderResult = wxPayService.createOrder(orderRequest);
|
|
|
+ return ResponseEntity.ok(wxPayMpOrderResult);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@SneakyThrows
|
|
|
@PostMapping("/pay")
|
|
|
@ApiOperation(value = "根据订单号进行支付", notes = "根据订单号进行支付")
|
|
|
public ResponseEntity<?> pay(@Valid @RequestBody PayParam payParam) {
|
|
|
- YamiUser user = SecurityUtils.getUser();
|
|
|
- String userId = user.getUserId();
|
|
|
- if (!user.isEnabled()) {
|
|
|
- throw new GlobalException("您已被禁用,不能购买,请联系平台客服");
|
|
|
- }
|
|
|
- PayInfoDto payInfo = payService.pay(userId, payParam);
|
|
|
+// YamiUser user = SecurityUtils.getUser();
|
|
|
+// String userId = user.getUserId();
|
|
|
+// if (!user.isEnabled()) {
|
|
|
+// throw new GlobalException("您已被禁用,不能购买,请联系平台客服");
|
|
|
+// }
|
|
|
+ PayInfoDto payInfo = payService.pay("204d3502c98a4b0c9d0904492edccf61", payParam);
|
|
|
|
|
|
if (payInfo.getPayAmount() < 0.01 && payInfo.getIsScore() == 1) {
|
|
|
return ResponseEntity.ok().build();
|
|
@@ -56,7 +93,7 @@ public class PayController {
|
|
|
po.setDescription(payInfo.getBody());
|
|
|
//po.setTotal((int) Arith.mul(payInfo.getPayAmount(), 100));
|
|
|
po.setTotal(1);
|
|
|
- po.setOpenId(user.getBizUserId());
|
|
|
+ po.setOpenId("owrSr6y0TGPHBU2tgMVoCO13Gjww");
|
|
|
po.setOutTradeNo(payInfo.getPayNo());
|
|
|
po.setNotifyUrl(getNotifyUrl("http://localhost:8112"));
|
|
|
return ResponseEntity.ok(wxProviderService.subJsapi(po));
|