111
k94314517
2023-11-08 51c6a9ec1f79df040a93cb56d78041d8ba22a2d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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 "createGoodsOrder": {
 
                        break;
                    }
                }
                return WxPayNotifyResponse.fail(result.getReturnMsg());
            }
            return WxPayNotifyResponse.success("处理成功!");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("微信回调结果异常,异常原因{}", e.getLocalizedMessage());
            return WxPayNotifyResponse.fail(e.getMessage());
        }
    }
 
 
}