mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-28 23:55:04 +08:00
Compare commits
9 Commits
1.4-Conver
...
feature/ea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
56acb22bea | ||
|
|
0a966eb0f0 | ||
|
|
0aec02ee7f | ||
|
|
1ee1bb607d | ||
|
|
782f923763 | ||
|
|
f11d343c4e | ||
|
|
c43117b7db | ||
|
|
a4244f64b8 | ||
|
|
2334cf6d68 |
@@ -1,11 +1,15 @@
|
||||
package love.sola.netsupport.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
@@ -16,12 +20,16 @@ import java.util.Map;
|
||||
public class Lang {
|
||||
|
||||
public static Map<String, String> messages;
|
||||
public static Map<String, AutoReply> replies;
|
||||
public static Map<String, MessageFormat> format_cache = new HashMap<>(32);
|
||||
|
||||
static {
|
||||
//noinspection unchecked
|
||||
InputStream in = Lang.class.getClassLoader().getResourceAsStream("lang.yml");
|
||||
messages = new Yaml().loadAs(in, Map.class);
|
||||
try (InputStream in = Lang.class.getClassLoader().getResourceAsStream("lang.yml")) {
|
||||
//noinspection unchecked
|
||||
messages = new Yaml().loadAs(in, Map.class);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String lang(String key) {
|
||||
@@ -40,4 +48,21 @@ public class Lang {
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadReplies() {
|
||||
try (InputStream in = Lang.class.getClassLoader().getResourceAsStream("replies.yml")) {
|
||||
Map<String, Object> yaml = (Map<String, Object>) new Yaml().load(in);
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public static class AutoReply {
|
||||
Pattern[] regex;
|
||||
String[] replies;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ package love.sola.netsupport.wechat;
|
||||
|
||||
import love.sola.netsupport.config.Settings;
|
||||
import love.sola.netsupport.wechat.handler.RegisterHandler;
|
||||
import love.sola.netsupport.wechat.matcher.CheckSpamMatcher;
|
||||
import love.sola.netsupport.wechat.handler.SpamHandler;
|
||||
import love.sola.netsupport.wechat.matcher.SpamMatcher;
|
||||
import love.sola.netsupport.wechat.matcher.RegisterMatcher;
|
||||
import me.chanjar.weixin.common.util.StringUtils;
|
||||
import me.chanjar.weixin.mp.api.*;
|
||||
@@ -31,7 +32,6 @@ public class WxMpServlet extends HttpServlet {
|
||||
protected WxMpInMemoryConfigStorage config;
|
||||
protected WxMpService wxMpService;
|
||||
protected WxMpMessageRouter wxMpMessageRouter;
|
||||
protected CheckSpamMatcher checkSpamMatcher;
|
||||
|
||||
public WxMpServlet() {
|
||||
instance = this;
|
||||
@@ -50,7 +50,6 @@ public class WxMpServlet extends HttpServlet {
|
||||
wxMpService = new WxMpServiceImpl();
|
||||
wxMpService.setWxMpConfigStorage(config);
|
||||
|
||||
checkSpamMatcher = new CheckSpamMatcher();
|
||||
wxMpMessageRouter = new WxMpMessageRouter(wxMpService);
|
||||
wxMpMessageRouter.rule()
|
||||
.async(false)
|
||||
@@ -65,12 +64,8 @@ public class WxMpServlet extends HttpServlet {
|
||||
wxMpMessageRouter.rule()
|
||||
.async(false)
|
||||
.msgType("text")
|
||||
.matcher(new CheckSpamMatcher())
|
||||
.handler((wxMessage, context, wxMpService1, sessionManager)
|
||||
-> WxMpXmlOutMessage.TEXT()
|
||||
.fromUser(wxMessage.getToUserName())
|
||||
.toUser(wxMessage.getFromUserName())
|
||||
.content(lang("Message_Spam")).build())
|
||||
.matcher(new SpamMatcher())
|
||||
.handler(new SpamHandler())
|
||||
.end();
|
||||
wxMpMessageRouter.rule()
|
||||
.async(false)
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package love.sola.netsupport.wechat.handler;
|
||||
|
||||
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.outxmlbuilder.TextBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/12/17.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class SpamHandler implements WxMpMessageHandler {
|
||||
|
||||
@Override
|
||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
|
||||
TextBuilder out = WxMpXmlOutMessage.TEXT()
|
||||
.fromUser(wxMessage.getToUserName())
|
||||
.toUser(wxMessage.getFromUserName());
|
||||
|
||||
return out.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class CheckSpamMatcher implements WxMpMessageMatcher {
|
||||
public class SpamMatcher implements WxMpMessageMatcher {
|
||||
|
||||
private class ValueLoader extends CacheLoader<String, Long> {
|
||||
@Override
|
||||
@@ -1,12 +1,19 @@
|
||||
package love.sola.netsupport.wechat;
|
||||
|
||||
import com.google.gson.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import love.sola.netsupport.config.Lang;
|
||||
import love.sola.netsupport.enums.ISP;
|
||||
import org.junit.Test;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
@@ -40,4 +47,23 @@ public class TestMessageFormat {
|
||||
assert "15838838438".equals(MessageFormat.format("{0,number,#}", 15838838438L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testYaml() {
|
||||
assert new Yaml().loadAs("array: \n - \"err\"\n - \"ee\"", TestArray.class).array.length == 2;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testYamlDump() {
|
||||
Map<String, TestArray> map = new HashMap<>();
|
||||
map.put("fuck", new TestArray(new String[]{"one", "two", "three"}));
|
||||
map.put("you", new TestArray(new String[]{"one", "two", "three"}));
|
||||
System.out.println(new Yaml().dumpAs(map, new Tag(map.getClass()), DumperOptions.FlowStyle.BLOCK));
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public static class TestArray {
|
||||
String[] array;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user