MrShi
2 天以前 7ee466ebc953bb5640bcf42f2b8e2a87aa471c21
server/web/src/main/java/com/doumee/api/web/PaymentCallback.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,82 @@
package com.doumee.api.web;
import com.doumee.config.wx.WxMiniConfig;
import com.doumee.core.constants.Constants;
import com.doumee.core.utils.ID;
import com.doumee.service.business.OrdersService;
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
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;
import java.util.Date;
import java.util.Objects;
/**
 * æ”¯ä»˜å›žè°ƒ
 *
 * @Author : Rk
 * @create 2023/3/24 16:57
 */
@Slf4j
@RestController
@CrossOrigin
public class PaymentCallback extends ApiController {
    @Autowired
    private OrdersService ordersService;
    @PostMapping("/web/api/wxPayNotify")
    public String wxPay_notify(@RequestBody String xmlResult) {
        String wxId = ID.nextGUID();
        log.info("支付回调信息("+wxId+") = > "  + xmlResult);
        if (StringUtils.isEmpty(xmlResult)){
            return null;
        }
        try {
            WxPayOrderNotifyResult result = WxMiniConfig.wxPayService.parseOrderNotifyResult(xmlResult);
            //自定义订单号
            String outTradeNo = result.getOutTradeNo();
            //微信订单号
            String paymentNo = result.getTransactionId();
            if (Constants.SUCCESS.equals(result.getReturnCode())) {
                // æ”¯ä»˜æˆåŠŸ
                switch (result.getAttach()) {
                    //寄存订单
                    case "storageOrder": {
                        ordersService.handleStorageOrderPayNotify(outTradeNo, paymentNo);
                        break;
                    }
                    //店铺押金订单
                    case "shopDeposit": {
                        break;
                    }
                    //逾期费用订单
                    case "overdueFee": {
                        break;
                    }
                }
                return WxPayNotifyResponse.success("处理成功!");
            }
            return WxPayNotifyResponse.fail(result.getReturnMsg());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("微信回调结果异常,异常原因{}", e.getLocalizedMessage());
            return WxPayNotifyResponse.fail(e.getMessage());
        }
    }
}