mitao
2025-11-27 d61840f8cf23015f9d2012d7231e21cdf062cd54
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
package com.stylefeng.guns.modular.huifu;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.huifu.bspay.sdk.opps.core.utils.RsaUtils;
import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity;
import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService;
import com.stylefeng.guns.modular.huifu.properties.HuiFuProperties;
import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics;
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Objects;
 
/**
 * @author mitao
 * @date 2025/11/21
 */
@Slf4j
@RestController
@RequestMapping("/base/dougong/")
public class DouGongNotifyController {
    @Autowired
    private HuiFuProperties huiFuProperties;
    @Autowired
    private IOrderCrossCityService orderCrossCityService;
    @Autowired
    private IOrderLogisticsService orderLogisticsService;
    /**
     * 斗拱主动取现接口回调
     * @param request
     * @param response
     */
    @PostMapping("/refund-logistics")
    public void refundLogistics(HttpServletRequest request, HttpServletResponse response) {
        String sign =request.getParameter("sign");
        String resp_data = request.getParameter("resp_data");
        log.info("斗拱用户提现回调响应内容:{}", resp_data);
        // 使用汇付公钥验签
        resp_data =  resp_data.replaceAll("& #40;", "(").replaceAll("& #41;",")");
        boolean verify = RsaUtils.verify(resp_data, huiFuProperties.getRsaPublicKey(), sign);
        if(verify){
            JSONObject respDataJson = JSONObject.parseObject(resp_data);
            String reqSeqId = respDataJson.getString("req_seq_id");
            String orgReqSeqId = respDataJson.getString("org_req_seq_id");
            String transStat = respDataJson.getString("trans_stat");//S:成功 F:失败 P:处理中;示例值:S
            OrderLogistics orderLogistics = orderLogisticsService.selectOne(new EntityWrapper<OrderLogistics>()
                    .eq("refundReqSeqId", reqSeqId).or().eq("outTradeNo", orgReqSeqId).last("limit 1"));
            if (Objects.isNull(orderLogistics)) {
                return;
            }
            if ("S".equalsIgnoreCase(transStat)) {
                orderLogistics.setState(10);
            }
            orderLogisticsService.updateById(orderLogistics);
            log.info("更新小件物流取消订单状态成功,更新内容“{}", JSONObject.toJSON(orderLogistics));
            PrintWriter writer = null;
            try {
                writer = response.getWriter();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            writer.print("200");
            writer.close();
        }
    }
    /**
     * 斗拱主动取现接口回调
     * @param request
     * @param response
     */
    @PostMapping("/refund-crosscity")
    public void refundCrossCity(HttpServletRequest request, HttpServletResponse response) {
        String sign =request.getParameter("sign");
        String resp_data = request.getParameter("resp_data");
        log.info("斗拱用户提现回调响应内容:{}", resp_data);
        // 使用汇付公钥验签
        resp_data =  resp_data.replaceAll("& #40;", "(").replaceAll("& #41;",")");
        boolean verify = RsaUtils.verify(resp_data, huiFuProperties.getRsaPublicKey(), sign);
        if(verify){
            JSONObject respDataJson = JSONObject.parseObject(resp_data);
            String reqSeqId = respDataJson.getString("req_seq_id");
            String orgReqSeqId = respDataJson.getString("org_req_seq_id");
            String transStat = respDataJson.getString("trans_stat");//S:成功 F:失败 P:处理中;示例值:S
            OrderCrossCity orderCrossCity = orderCrossCityService.selectOne(new EntityWrapper<OrderCrossCity>()
                    .eq("refundReqSeqId", reqSeqId).or().eq("outTradeNo", orgReqSeqId).last("limit 1"));
            if (Objects.isNull(orderCrossCity)) {
                return;
            }
            if ("S".equalsIgnoreCase(transStat)) {
                orderCrossCity.setState(10);
            }
            orderCrossCityService.updateById(orderCrossCity);
            log.info("更新跨城订单取消订单状态成功,更新内容“{}", JSONObject.toJSON(orderCrossCity));
            PrintWriter writer = null;
            try {
                writer = response.getWriter();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            writer.print("200");
            writer.close();
        }
    }
}