package com.ruoyi.message.config;
|
|
import org.springframework.boot.context.properties.bind.Bindable;
|
import org.springframework.boot.context.properties.bind.Binder;
|
import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
|
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
|
import org.springframework.boot.env.YamlPropertySourceLoader;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.PropertySource;
|
import org.springframework.core.env.StandardEnvironment;
|
import org.springframework.core.io.FileSystemResource;
|
|
import java.util.List;
|
|
/**
|
* 用「各站点真实的 application-*.yml」逐站点校验存量扁平 key 的绑定。
|
* <p>
|
* 只关心短信/公众号相关 key,其余 key 即使带占位符也不影响。
|
*/
|
public final class PerSiteBindingCheck {
|
|
private static int failed = 0;
|
|
private PerSiteBindingCheck() {
|
}
|
|
public static void main(String[] args) throws Exception {
|
String resDir = args.length > 0 ? args[0]
|
: "ruoyi-admin/src/main/resources";
|
|
checkSite(resDir, "xh", "新华",
|
new String[]{"http://192.16.4.220:8092/sms", "911124", "zW5eXe", "1069055"},
|
null, null);
|
checkSite(resDir, "hzszlyy", "市一",
|
new String[]{"http://192.169.140.240:8001/sms/api/sendMessageMass", "300044", "qj0NHDegxWhj", "1069055"},
|
null, null);
|
checkSite(resDir, "sltd", "省立同德",
|
new String[]{"", "", "", ""},
|
null, null);
|
checkSite(resDir, "nhfy", "南华附一",
|
new String[]{"", "", "", ""},
|
new String[]{"S200232", "lD94Yo", "http://open.nhyfy.cn/kapi/gw-api/hntypt/ucpmsg/send",
|
"1069100020341", "PUSH", "ak-BFq4NN0TMf92J7KAioNYGz74", "【南华大学附属第一医院】"},
|
null);
|
|
System.out.println();
|
if (failed == 0) {
|
System.out.println("===== 逐站点绑定校验全部通过 =====");
|
} else {
|
System.out.println("===== 逐站点绑定校验失败 " + failed + " 项 =====");
|
System.exit(1);
|
}
|
}
|
|
private static void checkSite(String resDir, String profile, String siteName,
|
String[] xhsms, String[] mt, String[] aliyun) throws Exception {
|
String file = resDir + "/application-" + profile + ".yml";
|
System.out.println("========== " + siteName + "(" + file + ")==========");
|
|
ConfigurableEnvironment environment = new StandardEnvironment();
|
environment.getPropertySources()
|
.remove(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
|
environment.getPropertySources()
|
.remove(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
|
List<PropertySource<?>> sources = new YamlPropertySourceLoader()
|
.load(file, new FileSystemResource(file));
|
for (PropertySource<?> source : sources) {
|
environment.getPropertySources().addLast(source);
|
}
|
|
Binder binder = new Binder(ConfigurationPropertySources.get(environment));
|
RootMessageProperties root = binder
|
.bind(ConfigurationPropertyName.EMPTY, Bindable.of(RootMessageProperties.class))
|
.orElseGet(RootMessageProperties::new);
|
MessageProperties p = new MessageProperties(root);
|
|
if (xhsms != null) {
|
check(siteName + ".xhsmsPath", xhsms[0], p.getSms().getXhsms().getPath());
|
check(siteName + ".xhsmsAccount", xhsms[1], p.getSms().getXhsms().getAccount());
|
check(siteName + ".xhsmsPwd", xhsms[2], p.getSms().getXhsms().getPwd());
|
check(siteName + ".xhsmsjrm", xhsms[3], p.getSms().getXhsms().getExtno());
|
}
|
if (mt != null) {
|
check(siteName + ".sms_accountName", mt[0], p.getSms().getMt().getAccountName());
|
check(siteName + ".sms_password", mt[1], p.getSms().getMt().getPassword());
|
check(siteName + ".sms_url", mt[2], p.getSms().getMt().getUrl());
|
check(siteName + ".sms_sourceAddr", mt[3], p.getSms().getMt().getSourceAddr());
|
check(siteName + ".sms_serviceCode", mt[4], p.getSms().getMt().getServiceCode());
|
check(siteName + ".sms_appkey", mt[5], p.getSms().getMt().getAppkey());
|
check(siteName + ".sms_flag", mt[6], p.getSms().getMt().getFlag());
|
}
|
if (aliyun != null) {
|
check(siteName + ".accessKeyId", aliyun[0], p.getSms().getAliyun().getAccessKeyId());
|
}
|
System.out.println();
|
}
|
|
private static void check(String key, String expected, String actual) {
|
boolean ok = expected == null ? actual == null : expected.equals(actual);
|
if (!ok) {
|
failed++;
|
}
|
System.out.println((ok ? " [OK] " : " [FAIL] ") + key
|
+ " 期望=[" + expected + "] 实际=[" + actual + "]");
|
}
|
}
|