yeg
2026-09-28 85bfb9351803d97a33329d507f30a2f78bf1fc75
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
package com.talentcard.server.business.payment;
 
import java.util.LinkedHashMap;
import java.util.Map;
 
import com.talentcard.server.business.payment.huifu.HuifuPaymentProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
 
/**
 * 启动时把五个回调地址念一遍:哪个配了、哪个没配。
 *
 * <p>为什么需要它:回调地址为空时系统原先什么都不说,于是很容易出现「以为回调在跑、其实指向一个不可达
 * 地址」或者「这个回调从来没在通道侧注册过」的错觉。把结论写进日志与报告,让缺失在启动那一刻就看得见,
 * 而不是等某笔支付卡住才发现。
 */
@Component
public class HuifuCallbackUrlAudit implements ApplicationRunner {
 
    private static final Logger log = LoggerFactory.getLogger(HuifuCallbackUrlAudit.class);
    /** 回调端点名(与 {@code PaymentCallbackController} 的路径一致)。 */
    static final String PAYMENT = "notify";
    static final String BANK_CARD = "merchant-business-notify";
    static final String ONBOARDING = "merchant-onboarding-notify";
    static final String WECHAT_CONFIG = "merchant-wechat-config-notify";
    static final String BUSINESS_OPEN = "merchant-business-open-notify";
 
    private final HuifuPaymentProperties properties;
 
    public HuifuCallbackUrlAudit(HuifuPaymentProperties properties) {
        this.properties = properties;
    }
 
    @Override
    public void run(ApplicationArguments args) {
        Map<String, String> report = report();
        for (Map.Entry<String, String> entry : report.entrySet()) {
            if (entry.getValue().isBlank()) {
                log.warn("Huifu callback {} is not enabled: the callback URL is empty,"
                        + " so nothing will be delivered there", entry.getKey());
            } else {
                log.info("Huifu callback {} is registered at {}", entry.getKey(), entry.getValue());
            }
        }
    }
 
    /** 每个回调端点的落地地址;空串表示「回调未启用」。 */
    public Map<String, String> report() {
        Map<String, String> report = new LinkedHashMap<>();
        report.put(PAYMENT, trimmed(properties.getNotifyUrl()));
        report.put(BANK_CARD, trimmed(properties.getMerchantBusinessNotifyUrl()));
        report.put(ONBOARDING, trimmed(properties.getMerchantOnboardingNotifyUrl()));
        report.put(WECHAT_CONFIG, trimmed(properties.getMerchantWechatConfigNotifyUrl()));
        report.put(BUSINESS_OPEN, trimmed(properties.getMerchantBusinessOpenNotifyUrl()));
        return report;
    }
 
    private String trimmed(String value) {
        return value == null ? "" : value.trim();
    }
}