admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
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
package com.yeshi.fanli.controller;
 
import com.ks.vip.pojo.DO.VipOrder;
import com.yeshi.fanli.lijin.manager.UserLijinMnager;
import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yeshi.utils.StringUtil;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
 
@RequestMapping("wx")
public class WXController {
 
    @Resource
    private UserLijinMnager userLijinMnager;
 
 
    /**
     * 处理通知结果
     *
     * @param request
     * @throws Exception
     */
    private void process(HttpServletRequest request) throws Exception {
 
        //验证证书序列号
        String mchSerialNo = request.getHeader("Wechatpay-Serial");
 
        String timeStamp = request.getHeader("Wechatpay-Timestamp");
        String nonce = request.getHeader("Wechatpay-Nonce");
        String signature = request.getHeader("Wechatpay-Signature");
        String data = null;
 
        try {
            if (request.getInputStream() != null) {
                String entity = IOUtils.toString(request.getInputStream(), "UTF-8");
                data = entity;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
 
 
        if (StringUtil.isNullOrEmpty(data)) {
            throw new Exception("通知的内容为空");
        }
 
 
        String outOrderNo = userLijinMnager.getWXPaySuccessOutOrderNo(data);
        VipOrder vipOrder = userLijinMnager.selectVipOrderByThreeOrderId(outOrderNo);
        if (vipOrder != null) {
            userLijinMnager.checkPay(vipOrder.getId());
        }
 
    }
 
 
    /**
     * 微信支付结果通知
     *
     * @param request
     * @param response
     */
    @RequestMapping("pay/lijinvip")
    public void vipPay(HttpServletRequest request, HttpServletResponse response) throws IOException {
        try {
            process(request);
            JSONObject data = new JSONObject();
            data.put("code", "SUCCESS");
            data.put("message", "处理成功");
            response.sendError(200, data.toString());
        } catch (Exception e) {
            e.printStackTrace();
            JSONObject data = new JSONObject();
            data.put("code", "FAIL");
            data.put("message", e.getMessage());
            response.sendError(500, data.toString());
        }
 
    }
}