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();
|
}
|
}
|