liujie
2026-08-04 e9e42b621afdf6ac94f5327ee843b32b10a401b4
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
package com.tourguide.common.huifu;
 
import com.alibaba.fastjson.JSONObject;
import com.tourguide.modules.order.service.HuifuPaymentCallbackService;
import com.tourguide.modules.order.service.HuifuRefundCallbackService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
/**
 * 斗拱回调入口。
 *
 * 备注:该控制器只做参数校验、验签和日志记录,订单状态落库应在后续服务层按 req_seq_id 幂等处理。
 */
@RestController
@RequestMapping("/base/dougong")
public class DouGongNotifyController {
    private static final Logger log = LoggerFactory.getLogger(DouGongNotifyController.class);
 
    private final HuifuCallbackVerifier callbackVerifier;
    private final HuifuPaymentCallbackService paymentCallbackService;
    private final HuifuRefundCallbackService refundCallbackService;
 
    public DouGongNotifyController(HuifuCallbackVerifier callbackVerifier,
                                   HuifuPaymentCallbackService paymentCallbackService,
                                   HuifuRefundCallbackService refundCallbackService) {
        this.callbackVerifier = callbackVerifier;
        this.paymentCallbackService = paymentCallbackService;
        this.refundCallbackService = refundCallbackService;
    }
 
    @PostMapping("/pay-notify")
    public String payNotify(@RequestParam(value = "sign", required = false) String sign,
                            @RequestParam(value = "resp_data", required = false) String respData) {
        try {
            JSONObject body = callbackVerifier.verify(sign, respData);
            paymentCallbackService.handle(body);
            return "200";
        } catch (Exception exception) {
            log.warn("dougong-pay callback failed: {}", exception.getMessage());
            return "FAIL";
        }
    }
 
    @PostMapping("/refund-notify")
    public String refundNotify(@RequestParam(value = "sign", required = false) String sign,
                               @RequestParam(value = "resp_data", required = false) String respData) {
        try {
            JSONObject body = callbackVerifier.verify(sign, respData);
            refundCallbackService.handle(body);
            return "200";
        } catch (Exception exception) {
            log.warn("dougong-refund callback failed: {}", exception.getMessage());
            return "FAIL";
        }
    }
 
    @PostMapping("/refund-logistics")
    public String refundLogistics(@RequestParam(value = "sign", required = false) String sign,
                                  @RequestParam(value = "resp_data", required = false) String respData) {
        return handleNotify("dougong-refund-logistics", sign, respData);
    }
 
    @PostMapping("/refund-crosscity")
    public String refundCrossCity(@RequestParam(value = "sign", required = false) String sign,
                                  @RequestParam(value = "resp_data", required = false) String respData) {
        return handleNotify("dougong-refund-crosscity", sign, respData);
    }
 
    @PostMapping("/encashment")
    public String encashment(@RequestParam(value = "sign", required = false) String sign,
                             @RequestParam(value = "resp_data", required = false) String respData) {
        return handleNotify("dougong-encashment", sign, respData);
    }
 
    private String handleNotify(String bizName, String sign, String respData) {
        try {
            JSONObject body = callbackVerifier.verify(sign, respData);
            log.info("{} verified, req_seq_id={}, org_req_seq_id={}, trans_stat={}", bizName,
                    body.getString("req_seq_id"), body.getString("org_req_seq_id"), body.getString("trans_stat"));
            return "200";
        } catch (Exception exception) {
            log.warn("{} callback failed: {}", bizName, exception.getMessage());
            return "FAIL";
        }
    }
}