linwe
2024-05-29 c10d6358b9f014375a13821465bc978d0c0da22e
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
150
151
152
package org.springblade.modules.pay.controller;
 
import com.google.gson.Gson;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springblade.common.utils.HttpUtils;
import org.springblade.common.utils.WechatPay2ValidatorForRequest;
import org.springblade.core.tool.api.R;
import org.springblade.modules.pay.entity.WxPayInfo;
import org.springblade.modules.pay.service.IWxPayService;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
 
@CrossOrigin //跨域
@RestController
@RequestMapping("/wxPay")
@Api(tags = "网站微信支付APIv3")
@Slf4j
public class WxPayController {
 
    @Resource
    private IWxPayService wxPayService;
 
 
    @PostMapping("/save")
    public R save(@RequestBody WxPayInfo wxPayInfo) {
        return R.status(wxPayService.save(wxPayInfo));
    }
 
    @PostMapping("/update")
    public R update(@RequestBody WxPayInfo wxPayInfo) {
        return R.status(wxPayService.updateById(wxPayInfo));
    }
 
    @PostMapping("saveOrUpdate")
    public R saveOrUpdate(@RequestBody WxPayInfo wxPayInfo) {
        return R.status(wxPayService.saveOrUpdate(wxPayInfo));
    }
 
 
    /**
     * jsapi下单
     *
     * @param properChargeRecordId
     * @return
     * @throws Exception
     */
    @ApiOperation("调用jsapi统一下单API")
    @GetMapping("/jsapiPay")
    public R jsapiPay(@RequestParam("properChargeRecordId") Long properChargeRecordId) throws Exception {
 
        log.info("发起支付请求 v3");
 
        //返回支付二维码连接和订单号
        Map<String, String> map = wxPayService.jsapiPay(properChargeRecordId);
 
        return R.data(map);
    }
 
    /**
     * 支付通知
     * 微信支付通过支付通知接口将用户支付成功消息通知给商户
     */
    @ApiOperation("支付通知")
    @PostMapping("/native/notify")
    public String nativeNotify(HttpServletRequest request, HttpServletResponse response) {
        return wxPayService.nativeNotify(request, response);
    }
 
    /**
     * 用户取消订单
     *
     * @param orderNo
     * @return
     * @throws Exception
     */
    @ApiOperation("用户取消订单")
    @PostMapping("/cancel/{orderNo}")
    public R cancel(@PathVariable String orderNo) throws Exception {
 
        log.info("取消订单");
 
        wxPayService.cancelOrder(orderNo);
        return R.data("订单已取消");
    }
 
    /**
     * 查询订单
     *
     * @param orderNo
     * @return
     * @throws Exception
     */
    @ApiOperation("查询订单")
    @GetMapping("/query/{orderNo}")
    public R queryOrder(@PathVariable String orderNo) throws Exception {
 
        log.info("查询订单");
 
        String result = wxPayService.queryOrder(orderNo);
        return R.data("result", result);
 
    }
 
 
    @ApiOperation("申请退款")
    @PostMapping("/refunds/{orderNo}/{reason}")
    public R refunds(@PathVariable String orderNo, @PathVariable String reason) throws Exception {
 
        log.info("申请退款");
        wxPayService.refund(orderNo, reason);
        return R.success("退款申请成功");
    }
 
    /**
     * 查询退款
     *
     * @param refundNo
     * @return
     * @throws Exception
     */
    @ApiOperation("查询退款")
    @GetMapping("/query-refund/{refundNo}")
    public R queryRefund(@PathVariable String refundNo) throws Exception {
 
        log.info("查询退款");
 
        String result = wxPayService.queryRefund(refundNo);
        return R.data("result", result);
    }
 
 
    /**
     * 退款结果通知
     * 退款状态改变后,微信会把相关退款结果发送给商户。
     */
    @ApiOperation("退款结果通知")
    @PostMapping("/refunds/notify")
    public String refundsNotify(HttpServletRequest request, HttpServletResponse response) {
 
        log.info("退款通知执行");
        return wxPayService.refundsNotify(request, response);
    }
 
 
}