|
|
@@ -0,0 +1,110 @@
|
|
|
+package com.dataeasy.server.pay;
|
|
|
+
|
|
|
+import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
|
|
|
+import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
|
|
|
+import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
|
|
+import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
+import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request;
|
|
|
+import com.github.binarywang.wxpay.bean.result.BaseWxPayResult;
|
|
|
+import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result;
|
|
|
+import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum;
|
|
|
+import com.github.binarywang.wxpay.constant.WxPayConstants;
|
|
|
+import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
+import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author tyuio
|
|
|
+ * @version 1.0.0
|
|
|
+ * @description TODO
|
|
|
+ * @date 2025/3/4 14:46
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class PayService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WxPayService wxPayService;
|
|
|
+
|
|
|
+ public WxPayUnifiedOrderV3Result.JsapiResult createDdzqOrder()throws WxPayException {
|
|
|
+// String endPayMoney = new BigDecimal("0.01").multiply(BigDecimal.valueOf(100)).stripTrailingZeros().toPlainString(); //将金额转换为分
|
|
|
+ WxPayUnifiedOrderRequest.WxPayUnifiedOrderRequestBuilder builder = WxPayUnifiedOrderRequest.newBuilder();
|
|
|
+ WxPayUnifiedOrderRequest wxOrder = builder
|
|
|
+ .body("测试测试商品描述") //商品描述
|
|
|
+ .openid("oaeVR7FhHMDu3iqUOhcTgJJVdOM0") //用户openid
|
|
|
+ .outTradeNo("20250304000001") //商户订单号
|
|
|
+// .spbillCreateIp("0.0.0.0") //终端IP
|
|
|
+// .totalFee(endPayMoney) // 支付收款金额 100分 注意:单位(分)
|
|
|
+ .totalFee(1) //测试时可以设置一分钱
|
|
|
+ .timeStart(DateTimeUtils.yyyyMMddHHmmssDateTime(0)) //交易起始时间
|
|
|
+ .timeExpire(DateTimeUtils.yyyyMMddHHmmssDateTime(10)) //交易结束时间
|
|
|
+ .tradeType(WxPayConstants.TradeType.JSAPI).build();
|
|
|
+ wxOrder.setSignType("MD5");
|
|
|
+// wxOrder.setNotifyUrl("http://ra36qh.natappfree.cc/pay/ddzqOrder"); //不测试时需要放开注释
|
|
|
+ WxPayUnifiedOrderV3Request wxOrderV3 = new WxPayUnifiedOrderV3Request();
|
|
|
+ wxOrderV3.setDescription("测试商品得描述书");
|
|
|
+ wxOrderV3.setOutTradeNo("20250305000001");
|
|
|
+ wxOrderV3.setTimeExpire("2025-03-05T10:34:56+08:00");
|
|
|
+ wxOrderV3.setNotifyUrl("http://ra36qh.natappfree.cc/pay/ddzqOrder");
|
|
|
+ WxPayUnifiedOrderV3Request.Amount amount = new WxPayUnifiedOrderV3Request.Amount();
|
|
|
+ WxPayUnifiedOrderV3Request.Payer payer = new WxPayUnifiedOrderV3Request.Payer();
|
|
|
+ payer.setOpenid("oSoRX7Ll01EB7XfsYt5aVrF_KfLU");
|
|
|
+ wxOrderV3.setPayer(payer);
|
|
|
+ amount.setTotal(1);
|
|
|
+ wxOrderV3.setAmount(amount);
|
|
|
+ return wxPayService.createOrderV3(TradeTypeEnum.JSAPI, wxOrderV3);
|
|
|
+// return wxPayService.createOrder(wxOrder);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String ddzqOrder(HttpServletRequest request) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ String xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
|
|
|
+ WxPayOrderNotifyResult payResult = wxPayService.parseOrderNotifyResult(xmlResult);
|
|
|
+ String masterOrderId = payResult.getOutTradeNo();//内部订单记录ID
|
|
|
+ String wxTransactionId = payResult.getTransactionId();//商户号订单ID
|
|
|
+ BigDecimal wxRealPayAmount = new BigDecimal(BaseWxPayResult.fenToYuan(payResult.getTotalFee()));//微信真实支付金额
|
|
|
+// StOrder stOrder = stOrderMapper.selectByEOrderId(masterOrderId);
|
|
|
+// Date nowTime = new Date();
|
|
|
+// if(stOrder.getPayStatus() == 1){
|
|
|
+// //下一个进程进来的时候,上一个进程已经修改了订单支付状态
|
|
|
+//
|
|
|
+// return WxPayNotifyResponse.success("处理成功!");
|
|
|
+// }
|
|
|
+// StOrder orderRequest = new StOrder();
|
|
|
+// orderRequest.setPayStatus(1);//标记已支付
|
|
|
+// orderRequest.setMasterOrderId(masterOrderId);
|
|
|
+// orderRequest.setPaymentTime(nowTime);
|
|
|
+// orderRequest.setStoreReceiveTime(nowTime);
|
|
|
+// orderRequest.setOrderStatus(10); //等待顾客取货
|
|
|
+// stOrderMapper.updateByMasterOrderIdSelective(orderRequest);
|
|
|
+// StOrderPay stOrderPay = new StOrderPay();
|
|
|
+// stOrderPay.setMasterOrderId(masterOrderId);
|
|
|
+// stOrderPay.setWxRealPayAmount(wxRealPayAmount);
|
|
|
+// stOrderPay.setWxTransactionId(wxTransactionId);
|
|
|
+// stOrderPay.setPayWay(1); //支付方式 微信支付:1 支付宝支付:2
|
|
|
+// stOrderPayMapper.insert(stOrderPay);
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 打印订单
|
|
|
+// */
|
|
|
+// List<StPrinter> stPrinterList = stPrinterMapper.selectPrintersByStoreId(stOrder.getStoreId());
|
|
|
+// for (StPrinter stPrinter:stPrinterList) {
|
|
|
+// stPrinterService.printOrder(stOrder.getEOrderId(),stOrder.getStoreId(),stPrinter.getOkPrinterSn());
|
|
|
+// }
|
|
|
+
|
|
|
+ log.info("微信支付,回调处理成功");
|
|
|
+ return WxPayNotifyResponse.success("处理成功!");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return WxPayNotifyResponse.fail(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|