|
@@ -4,27 +4,26 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
|
|
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
|
|
-import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
|
|
|
+import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
|
+import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
|
import com.hys.app.framework.exception.ServiceException;
|
|
import com.hys.app.framework.exception.ServiceException;
|
|
import com.hys.app.model.erp.dos.OrderCustomerFee;
|
|
import com.hys.app.model.erp.dos.OrderCustomerFee;
|
|
import com.hys.app.model.erp.dos.OrderDO;
|
|
import com.hys.app.model.erp.dos.OrderDO;
|
|
import com.hys.app.model.erp.dto.PayTypeUrl;
|
|
import com.hys.app.model.erp.dto.PayTypeUrl;
|
|
import com.hys.app.pay.ali.AliPayService;
|
|
import com.hys.app.pay.ali.AliPayService;
|
|
import com.hys.app.pay.ali.PayOrder;
|
|
import com.hys.app.pay.ali.PayOrder;
|
|
-import com.hys.app.pay.ali.WxService;
|
|
|
|
|
|
+import com.hys.app.pay.wx.WxPayServiceMy;
|
|
import com.hys.app.service.erp.OrderCustomerFeeManager;
|
|
import com.hys.app.service.erp.OrderCustomerFeeManager;
|
|
import com.hys.app.service.erp.OrderManager;
|
|
import com.hys.app.service.erp.OrderManager;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
+import java.net.UnknownHostException;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -38,13 +37,13 @@ import java.util.Map;
|
|
public class PayController {
|
|
public class PayController {
|
|
private OrderManager orderManager;
|
|
private OrderManager orderManager;
|
|
private AliPayService aliPayService;
|
|
private AliPayService aliPayService;
|
|
- private WxService wxService;
|
|
|
|
|
|
+ private WxPayServiceMy wxPayServiceMy;
|
|
private OrderCustomerFeeManager orderCustomerFeeManager;
|
|
private OrderCustomerFeeManager orderCustomerFeeManager;
|
|
- private WxPayService wxPayService;
|
|
|
|
|
|
+
|
|
|
|
|
|
@ApiOperation(value = "扫描完获取拉起支付的url")
|
|
@ApiOperation(value = "扫描完获取拉起支付的url")
|
|
@PostMapping("/getPayUrl")
|
|
@PostMapping("/getPayUrl")
|
|
- public Object getListByScan(@RequestBody @Validated PayTypeUrl payTypeUrl) {
|
|
|
|
|
|
+ public Object getListByScan(@RequestBody @Validated PayTypeUrl payTypeUrl) throws UnknownHostException {
|
|
OrderDO aDo = orderManager.getById(payTypeUrl.getOrderId());
|
|
OrderDO aDo = orderManager.getById(payTypeUrl.getOrderId());
|
|
if (ObjectUtil.isNull(aDo)) {
|
|
if (ObjectUtil.isNull(aDo)) {
|
|
throw new ServiceException("未查询到订单信息");
|
|
throw new ServiceException("未查询到订单信息");
|
|
@@ -52,20 +51,20 @@ public class PayController {
|
|
PayOrder payOrder = new PayOrder();
|
|
PayOrder payOrder = new PayOrder();
|
|
payOrder.setTraceNo(aDo.getId().toString());
|
|
payOrder.setTraceNo(aDo.getId().toString());
|
|
|
|
|
|
- payOrder.setSubject("租赁订单支付金额");
|
|
|
|
|
|
+ payOrder.setSubject("订单支付金额");
|
|
payOrder.setTimeExpire(LocalDateTime.now().plusMinutes(30));
|
|
payOrder.setTimeExpire(LocalDateTime.now().plusMinutes(30));
|
|
List<OrderCustomerFee> list = orderCustomerFeeManager.list(new LambdaQueryWrapper<OrderCustomerFee>().eq(OrderCustomerFee::getOrderId, payTypeUrl.getOrderId()));
|
|
List<OrderCustomerFee> list = orderCustomerFeeManager.list(new LambdaQueryWrapper<OrderCustomerFee>().eq(OrderCustomerFee::getOrderId, payTypeUrl.getOrderId()));
|
|
- if (CollectionUtil.isNotEmpty(list)){
|
|
|
|
- payOrder.setTotalAmount(new BigDecimal(aDo.getRealPrice()).add(list.stream().map(OrderCustomerFee::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add)).doubleValue());
|
|
|
|
- }else {
|
|
|
|
- payOrder.setTotalAmount(aDo.getRealPrice());
|
|
|
|
|
|
+ if (CollectionUtil.isNotEmpty(list)) {
|
|
|
|
+ payOrder.setTotalAmount(new BigDecimal(aDo.getRealPrice()).add(list.stream().map(OrderCustomerFee::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add)).multiply(new BigDecimal(1 + aDo.getTaxRate() * 0.01)).doubleValue());
|
|
|
|
+ } else {
|
|
|
|
+ payOrder.setTotalAmount(aDo.getRealPrice() * (1 + aDo.getTaxRate() * 0.01));
|
|
}
|
|
}
|
|
|
|
|
|
switch (payTypeUrl.getPayType()) {
|
|
switch (payTypeUrl.getPayType()) {
|
|
case "ali":
|
|
case "ali":
|
|
return aliPayService.pay(payOrder);
|
|
return aliPayService.pay(payOrder);
|
|
case "wx":
|
|
case "wx":
|
|
- return "暂未开通";
|
|
|
|
|
|
+ return wxPayServiceMy.pay(payOrder);
|
|
default:
|
|
default:
|
|
return "不支持的支付方式";
|
|
return "不支持的支付方式";
|
|
}
|
|
}
|
|
@@ -89,17 +88,34 @@ public class PayController {
|
|
}
|
|
}
|
|
|
|
|
|
@PostMapping("/wxpay/notify")
|
|
@PostMapping("/wxpay/notify")
|
|
- public String payNotify(@RequestBody String xmlData) throws Exception {
|
|
|
|
- WxPayOrderNotifyResult notifyResult = wxPayService.parseOrderNotifyResult(xmlData);
|
|
|
|
-
|
|
|
|
- if ("SUCCESS".equals(notifyResult.getResultCode())) {
|
|
|
|
- // 处理业务逻辑
|
|
|
|
- String outTradeNo = notifyResult.getOutTradeNo();
|
|
|
|
- String transactionId = notifyResult.getTransactionId();
|
|
|
|
- // 更新订单状态等
|
|
|
|
- return "<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>";
|
|
|
|
- } else {
|
|
|
|
- return "<xml><return_code><![CDATA[FAIL]]></return_code></xml>";
|
|
|
|
|
|
+ public String parseOrderNotify(@RequestBody String xmlData) {
|
|
|
|
+ try {
|
|
|
|
+ WxPayServiceImpl wxPayService = new WxPayServiceImpl();
|
|
|
|
+ // 解析支付通知结果
|
|
|
|
+ WxPayOrderNotifyResult notifyResult = wxPayService.parseOrderNotifyResult(xmlData);
|
|
|
|
+ // 处理订单逻辑
|
|
|
|
+ if ("SUCCESS".equals(notifyResult.getResultCode().toUpperCase())) {
|
|
|
|
+ // 支付成功
|
|
|
|
+ OrderDO aDo = orderManager.getById(notifyResult.getOutTradeNo());
|
|
|
|
+ aDo.setHasPayReturn(true);
|
|
|
|
+ orderManager.updateById(aDo);
|
|
|
|
+ // 返回成功响应给微信服务器
|
|
|
|
+ return "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
|
|
|
|
+ }
|
|
|
|
+ } catch (WxPayException e) {
|
|
|
|
+ // 处理解析异常,记录日志
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
+ return "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[解析失败]]></return_msg></xml>";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @GetMapping("getopenId")
|
|
|
|
+ public String getopenId() {
|
|
|
|
+ String appId = "wx51e98f2dee35237d";
|
|
|
|
+ String secret = "13803c1b0d911e023c7da0b300cbce89";
|
|
|
|
+
|
|
|
|
+ String accessToken = WxPayServiceMy.getAccessToken(appId, secret);
|
|
|
|
+ String openId = WxPayServiceMy.getOpenId(accessToken);
|
|
|
|
+ return openId;
|
|
}
|
|
}
|
|
}
|
|
}
|