微信消息推送
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.6 KiB

4 years ago
package com.ynxbd.push.config;
import com.ynxbd.push.helper.IPHelper;
import com.ynxbd.push.helper.ProperHelper;
import lombok.extern.slf4j.Slf4j;
import org.ini4j.Wini;
import org.springframework.util.ResourceUtils;
import java.io.IOException;
import java.io.InputStream;
/**
* 获取有关appId跟secret等相关配置信息
*
* @author 李进才
* 单例模式-静态代码块
*/
@Slf4j
public class IniConfig {
private IniConfig() {
}
private static final Wini WINI;
private static final String IP;
// 静态内部类保证Wini只实例化一次
static {
WINI = initConfig();
IP = IPHelper.getIp();
log.info("IP:{}", IP);
}
/**
* 获取项目的配置信息
*/
public synchronized static Wini initConfig() {
try {
Wini wini = new Wini();
try (InputStream in = IniConfig.class.getClassLoader().getResourceAsStream("weChat.ini")) {
wini.load(in);
} catch (IOException e) {
e.printStackTrace();
}
return wini;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 获取项目的配置信息
*
* @param key 配置信息的关键词
*/
public static String getInstance(String key) {
return WINI.fetch(IP, key);
}
/**
* 测试是否读取成功
*
*/
public static String test() {
return WINI.fetch("10.20.10.60", "name");
}
public static void main(String[] args) {
System.out.println(test());
}
}