| package com.doumee.api.web; | 
|   | 
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
| import com.baomidou.mybatisplus.core.toolkit.StringUtils; | 
| import com.doumee.core.wx.WxMiniConfig; | 
| import com.doumee.service.business.GoodsorderService; | 
| import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse; | 
| import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; | 
| import com.github.binarywang.wxpay.config.WxPayConfig; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.web.bind.annotation.CrossOrigin; | 
| import org.springframework.web.bind.annotation.PostMapping; | 
| import org.springframework.web.bind.annotation.RequestBody; | 
| import org.springframework.web.bind.annotation.RestController; | 
|   | 
| /** | 
|  * Created by IntelliJ IDEA. | 
|  * 支付回调 | 
|  * @Author : Rk | 
|  * @create 2023/2/23 13:49 | 
|  */ | 
| @Slf4j | 
| @RestController | 
| @CrossOrigin | 
| public class PaymentCallback { | 
|   | 
|     @Autowired | 
|     private GoodsorderService goodsorderService; | 
|   | 
|     /** | 
|      * 【微信支付】异步通知 | 
|      * | 
|      * @param xmlResult | 
|      * @return | 
|      */ | 
|     @PostMapping("/api/wxPayNotify") | 
|     public String wxPay_notify(@RequestBody String xmlResult) { | 
|         log.info(xmlResult); | 
|         if (StringUtils.isBlank(xmlResult)) return null; | 
|         try { | 
|             WxPayOrderNotifyResult result = WxMiniConfig.wxPayService.parseOrderNotifyResult(xmlResult); | 
|             //自定义订单号 | 
|             String outTradeNo = result.getOutTradeNo(); | 
|             //微信订单号 | 
|             String paymentNo = result.getTransactionId(); | 
|             if ("SUCCESS".equals(result.getReturnCode())) { | 
|                 // 支付成功 | 
|                 switch (result.getAttach()) { | 
|                     //家长支付订单 | 
|                     case "createGoodsOrder": { | 
|                         goodsorderService.payNotify(outTradeNo,paymentNo); | 
|                         break; | 
|                     } | 
|                 } | 
|             } else { | 
|                 // 支付失败 | 
|                 switch (result.getAttach()) { | 
|                     //家长支付订单 | 
|                     case "createOrder": { | 
|   | 
|                         break; | 
|                     } | 
|                 } | 
|                 return WxPayNotifyResponse.fail(result.getReturnMsg()); | 
|             } | 
|             return WxPayNotifyResponse.success("处理成功!"); | 
|         } catch (Exception e) { | 
|             e.printStackTrace(); | 
|             log.error("微信回调结果异常,异常原因{}", e.getLocalizedMessage()); | 
|             return WxPayNotifyResponse.fail(e.getMessage()); | 
|         } | 
|     } | 
|   | 
|   | 
| } |