mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-28 23:55:04 +08:00
use yaml to configure lang
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -148,6 +148,11 @@
|
||||
<artifactId>jBCrypt</artifactId>
|
||||
<version>0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>1.16</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,7 +1,8 @@
|
||||
package love.sola.netsupport.config;
|
||||
|
||||
import love.sola.netsupport.sql.TableLang;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -18,8 +19,12 @@ public class Lang {
|
||||
public static Map<String, MessageFormat> format_cache = new HashMap<>(32);
|
||||
|
||||
static {
|
||||
messages = new HashMap<>();
|
||||
TableLang.getLang(messages);
|
||||
//noinspection unchecked
|
||||
InputStream in = Lang.class.getClassLoader().getResourceAsStream("lang.yml");
|
||||
messages = new Yaml().loadAs(in, Map.class);
|
||||
for (Map.Entry<String, String> entry : messages.entrySet()) {
|
||||
System.out.println(entry.getKey() + ": " + entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public static String lang(String key) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.Map;
|
||||
public class Status {
|
||||
|
||||
public static final int UNCHECKED = 0;
|
||||
public static final int UNSOLVED = 9;
|
||||
public static final int SOLVED = 9;
|
||||
|
||||
public static final Map<Integer, String> inverseMap = new HashMap<>();
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package love.sola.netsupport.sql;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/11/30.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class TableLang extends SQLCore {
|
||||
|
||||
public static void getLang(Map<String, String> lang) {
|
||||
try (Connection conn = ds.getConnection()) {
|
||||
Statement st = conn.createStatement();
|
||||
ResultSet rs = st.executeQuery("SELECT * FROM lang;");
|
||||
while (rs.next()) {
|
||||
lang.put(rs.getString("lkey"), rs.getString("lvalue"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,46 @@
|
||||
package love.sola.netsupport.wechat.handler;
|
||||
|
||||
import love.sola.netsupport.api.Authorize;
|
||||
import love.sola.netsupport.pojo.Ticket;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.sql.TableTicket;
|
||||
import love.sola.netsupport.sql.TableUser;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutNewsMessage;
|
||||
import me.chanjar.weixin.mp.bean.outxmlbuilder.NewsBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static love.sola.netsupport.config.Lang.lang;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/12/9.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class SubmitHandler {
|
||||
public class SubmitHandler implements WxMpMessageHandler {
|
||||
|
||||
@Override
|
||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
||||
User u = TableUser.getUserByWechat(wxMessage.getFromUserName());
|
||||
Ticket t = TableTicket.queryLastOpen(u);
|
||||
if (t != null) {
|
||||
return WxMpXmlOutMessage.TEXT().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName())
|
||||
.content(lang("Already_Opening_Ticket")).build();
|
||||
}
|
||||
NewsBuilder out = WxMpXmlOutMessage.NEWS().fromUser(wxMessage.getToUserName()).toUser(wxMessage.getFromUserName());
|
||||
WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
|
||||
|
||||
Authorize.fetchedTime.put(wxMessage.getFromUserName(), System.currentTimeMillis());
|
||||
Authorize.fetchedCommand.put(wxMessage.getFromUserName(), Command.QUERY);
|
||||
return out.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
14
src/main/resources/lang.yml
Normal file
14
src/main/resources/lang.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
Access_Denied: 'Access denied.'
|
||||
Already_Registered: "You've already registered. for profile modification, please type 'editprofile'."
|
||||
Event_Subscribe: "Welcome to ZSC Network Support Department (ZSCNSD) Wechat Ticket System (WTS).\nIf you have any problem, Please contact loli@sola.love."
|
||||
Illegal_Request: "Access denied.\nYou are doing a illegal request, and our system has logged your behaviors.\nYou need to take this seriously, if you do this frequently, you may be banned from our system."
|
||||
Invalid_Operation: 'Invalid operation.'
|
||||
More_Details: 'For more details, please click >'
|
||||
No_Ticket_Available: 'No tickets found.'
|
||||
Query_Title: 'Your latest ticket details'
|
||||
REGEX_QUERY: '^(?i)Query$'
|
||||
REGEX_REGISTER: '^(?i)Reg(ister)?$'
|
||||
Unknown_Encrypt_Type: 'Unknown encrypt-type.'
|
||||
User_Query_Link: 'http://topaz.sinaapp.com/nm/v1/query.php?wechatid={0}'
|
||||
User_Register_Link: "You''ve not registered, please <a href=\"http://topaz.sinaapp.com/nm/v1/reg.php?wechatid={0}\">CLICK HERE</a> to register."
|
||||
Already_Opening_Ticket: "You are holding an opening ticket right now. please type 'query' for more information"
|
||||
@@ -1,9 +1,8 @@
|
||||
package love.sola.netsupport.wechat;
|
||||
|
||||
import love.sola.netsupport.config.Lang;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/12/2.
|
||||
@@ -13,16 +12,9 @@ import java.text.MessageFormat;
|
||||
public class TestMessageFormat {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
MessageFormat format = new MessageFormat("You''ve not registered, please <a href=\"http://topaz.sinaapp.com/nm/reg.php?wechat={0}\">CLICK HERE</a> to register.");
|
||||
System.out.println(format.format(new Object[]{"wechatid"}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonp() {
|
||||
String jsonp = "...{0}...";
|
||||
MessageFormat format = new MessageFormat(jsonp);
|
||||
System.out.println(format.format(new Object[]{"{SomeData}"}));
|
||||
public void testLang() {
|
||||
assert Lang.messages != null;
|
||||
System.out.println(Lang.messages);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user