liusheng
2026-10-12 26d1f59f0266672398975ba0337bb3d8267c2d95
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
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 + "]");
    }
}