|
|
|
|
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.ObjectUtils;
|
|
|
|
|
import org.springframework.util.ResourceUtils;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取有关appId跟secret等相关配置信息
|
|
|
|
|
*
|
|
|
|
|
* @author 李进才
|
|
|
|
|
* 单例模式-静态代码块
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class IniConfig {
|
|
|
|
|
private IniConfig() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final Wini WINI;
|
|
|
|
|
private static final String IP;
|
|
|
|
|
public static final Boolean TEMPLATE_VERSION;
|
|
|
|
|
public static final String WECHAT_UI_PATH;
|
|
|
|
|
public static final String DOMAIN;
|
|
|
|
|
public static final String TOKEN_URL;
|
|
|
|
|
public static final String LEADER_TIME;
|
|
|
|
|
public static final String TODAY_REG_TIME_MOM;
|
|
|
|
|
public static final String TODAY_REG_TIME_NOON;
|
|
|
|
|
public static final String NAME;
|
|
|
|
|
|
|
|
|
|
// 静态内部类保证Wini只实例化一次
|
|
|
|
|
static {
|
|
|
|
|
WINI = initConfig();
|
|
|
|
|
IP = IPHelper.getIp();
|
|
|
|
|
log.info("IP:{}", IP);
|
|
|
|
|
TEMPLATE_VERSION = Objects.equals(getInstance("templateVersion"), "new");
|
|
|
|
|
WECHAT_UI_PATH = getInstance("weChatUIPath");
|
|
|
|
|
DOMAIN = getInstance("domain");
|
|
|
|
|
TOKEN_URL = getInstance("token_url");
|
|
|
|
|
LEADER_TIME = getInstance("leaderTime");
|
|
|
|
|
TODAY_REG_TIME_MOM = getInstance("todayRegTimeMom");
|
|
|
|
|
TODAY_REG_TIME_NOON = getInstance("todayRegTimeNoon");
|
|
|
|
|
NAME = getInstance("name");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取项目的配置信息
|
|
|
|
|
*/
|
|
|
|
|
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());
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取微信页面链接
|
|
|
|
|
*
|
|
|
|
|
* @param isSuffix 是否需要后缀/
|
|
|
|
|
*/
|
|
|
|
|
public static String getWxWebPath(boolean isSuffix) {
|
|
|
|
|
String domain = IniConfig.DOMAIN;
|
|
|
|
|
if (!ObjectUtils.isEmpty(domain)) {
|
|
|
|
|
String suffix = domain.substring(domain.length() - 1);
|
|
|
|
|
if (suffix.equals("/")) {
|
|
|
|
|
domain = domain.substring(0, domain.length() - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String weChatUIPath = IniConfig.WECHAT_UI_PATH;
|
|
|
|
|
if (!ObjectUtils.isEmpty(weChatUIPath) && weChatUIPath.length() > 1) {
|
|
|
|
|
String prefix = weChatUIPath.substring(0, 1);
|
|
|
|
|
String suffix = weChatUIPath.substring(weChatUIPath.length() - 1);
|
|
|
|
|
if (!prefix.equals("/")) {
|
|
|
|
|
weChatUIPath = "/" + weChatUIPath;
|
|
|
|
|
}
|
|
|
|
|
if (suffix.equals("/")) {
|
|
|
|
|
weChatUIPath = weChatUIPath.substring(0, weChatUIPath.length() - 1);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
weChatUIPath = "";
|
|
|
|
|
}
|
|
|
|
|
return domain + "/wx" + weChatUIPath + (isSuffix ? "/" : "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
String wxWebPath = getWxWebPath(true);
|
|
|
|
|
System.out.println(wxWebPath);
|
|
|
|
|
}
|
|
|
|
|
}
|