rk
2025-12-15 12d724c247e4f7dcb77b3a94891ccf4d86b53cfa
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package com.doumee.api.web.mall;
 
import com.doumee.api.web.ApiController;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.ID;
import com.doumee.core.wx.WxMiniConfig;
import com.doumee.dao.business.model.ActivitySign;
import com.doumee.dao.business.model.Fund;
import com.doumee.dao.business.model.Goodsorder;
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.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 {
 
 
    @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_STR.equals(result.getReturnCode())) {
                // 支付成功
                switch (result.getAttach()) {
                    //活动参与支付
                    case "ActivitySign": {
                        ActivitySign activitySign = activitySignService.findById(Integer.valueOf(outTradeNo));
                        if(Objects.isNull(activitySign)){
                            return WxPayNotifyResponse.fail( "支付回调信息("+ wxId + ") = > 未查询到支付对象信息!");
                        }
                        if(activitySign.getStatus().equals(Constants.ONE)){
                            return WxPayNotifyResponse.success("处理成功!");
                        }
                        activitySign.setPayStatus(Constants.ONE);
                        activitySign.setPayDate(new Date());
                        activitySign.setPayOrderId(paymentNo);
                        activitySign.setStatus(Constants.ONE);
                        activitySignService.updateById(activitySign);
                        break;
                    }
                    case "terraceMall": {
                        Goodsorder DBGoodsOrder = new Goodsorder();
                        DBGoodsOrder.setCode(Long.valueOf(outTradeNo));
                        Goodsorder goodsOrder = goodsorderService.findOne(DBGoodsOrder);
                        if(Objects.isNull(goodsOrder)){
                            return WxPayNotifyResponse.fail( "支付回调信息("+ wxId + ") = > 未查询到支付对象信息!");
                        }
                        if(goodsOrder.getStatus().equals(Constants.ONE)){
                            return WxPayNotifyResponse.success("处理成功!");
                        }
                        goodsOrder.setPayStatus(Constants.ONE);
                        goodsOrder.setPayDate(new Date());
                        goodsOrder.setPayOrderId(paymentNo);
                        goodsOrder.setStatus(Constants.OrderStatus.PAY_DONE.getKey());
                        goodsOrder.setPayMethod(Constants.ZERO);
                        goodsorderService.updateById(goodsOrder);
                        //生成 咖啡计划订单明细表
                        if(goodsOrder.getType().equals(Constants.TWO)){
                            planorderDetailService.createPlanOrderDetail(goodsOrder);
                        }
                        Fund fund = new Fund();
                        fund.setOrderCode(goodsOrder.getPayOrderId());
                        fund.setCreator(goodsOrder.getMemberId());
                        fund.setCreateDate(new Date());
                        fund.setIsdeleted(Constants.ZERO);
                        fund.setRemark(goodsOrder.getCode().toString());
                        fund.setMemberId(goodsOrder.getMemberId());
                        fund.setTitle("订单支付");
                        fund.setContent("订单支付");
                        fund.setObjId(goodsOrder.getId());
                        fund.setObjType(Constants.ONE);
                        fund.setType(Constants.ZERO);
                        fund.setNum(goodsOrder.getPrice());
                        fundService.create(fund);
                        break;
                    }
                    case "shopGoods": {
                        Goodsorder DBGoodsOrder = new Goodsorder();
                        DBGoodsOrder.setCode(Long.valueOf(outTradeNo));
                        Goodsorder goodsOrder = goodsorderService.findOne(DBGoodsOrder);
                        if(Objects.isNull(goodsOrder)){
                            return WxPayNotifyResponse.fail( "支付回调信息("+ wxId + ") = > 未查询到支付对象信息!");
                        }
                        if(goodsOrder.getStatus().equals(Constants.ONE)){
                            return WxPayNotifyResponse.success("处理成功!");
                        }
                        goodsOrder.setPayStatus(Constants.ONE);
                        goodsOrder.setPayDate(new Date());
                        goodsOrder.setPayOrderId(paymentNo);
                        goodsOrder.setStatus(Constants.equalsInteger(goodsOrder.getReceiveType(),Constants.ZERO)?Constants.OrderStatus.PAY_DONE.getKey():Constants.OrderStatus.WAIT_RECEIVE.getKey());
                        goodsOrder.setPayMethod(Constants.ZERO);
                        goodsorderService.updateById(goodsOrder);
                        Fund fund = new Fund();
                        fund.setOrderCode(goodsOrder.getPayOrderId());
                        fund.setCreator(goodsOrder.getMemberId());
                        fund.setCreateDate(new Date());
                        fund.setIsdeleted(Constants.ZERO);
                        fund.setRemark(goodsOrder.getCode().toString());
                        fund.setMemberId(goodsOrder.getMemberId());
                        fund.setTitle("订单支付");
                        fund.setContent("订单支付");
                        fund.setObjId(goodsOrder.getId());
                        fund.setObjType(Constants.ONE);
                        fund.setType(Constants.ZERO);
                        fund.setNum(goodsOrder.getPrice());
                        fundService.create(fund);
                        break;
                    }
 
                }
                return WxPayNotifyResponse.success("处理成功!");
            }
            return WxPayNotifyResponse.fail(result.getReturnMsg());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("微信回调结果异常,异常原因{}", e.getLocalizedMessage());
            return WxPayNotifyResponse.fail(e.getMessage());
        }
    }
 
 
 
}