From 43bf516613ce5c9a869460fdc3eaf64558b44dde Mon Sep 17 00:00:00 2001 From: limqhz Date: Tue, 9 Feb 2021 08:55:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B9=E7=9B=AE=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=B8=B8=E6=88=8F=E7=A0=B4=E8=A7=A3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/qn/DemoApplication.java | 2 + common/pom.xml | 17 +- .../main/java/com/qn/dwonline/BaseAction.java | 117 +++++ .../main/java/com/qn/dwonline/DwOnline.java | 22 + .../java/com/qn/dwonline/common/CmdList.java | 12 + .../java/com/qn/dwonline/common/FindType.java | 7 + .../java/com/qn/dwonline/commond/BaseCMD.java | 46 ++ .../com/qn/dwonline/commond/BlackWind.java | 42 ++ .../java/com/qn/dwonline/commond/DangKou.java | 49 ++ .../com/qn/dwonline/commond/EatPeople.java | 47 ++ .../com/qn/dwonline/commond/GaoTreasury.java | 59 +++ .../com/qn/dwonline/commond/IceStone.java | 115 +++++ .../qn/dwonline/commond/JiangduWangfu.java | 47 ++ .../com/qn/dwonline/commond/ShaoHuaShan.java | 53 +++ .../com/qn/dwonline/commond/ShiJiaZhuang.java | 69 +++ .../java/com/qn/dwonline/commond/Test.java | 15 + .../qn/dwonline/commond/pick/DaBaiCai.java | 31 ++ .../com/qn/dwonline/dojbo/FuBenAction.java | 39 ++ .../com/qn/dwonline/dojbo/PickAction.java | 19 + .../com/qn/dwonline/dojbo/TestAction.java | 14 + .../{ => com/qn}/model/wx/TextMessage.java | 2 +- .../com/qn/test/event/EventSourceObject.java | 37 ++ .../java/com/qn/test/event/MainEventTest.java | 21 + .../main/java/com/qn/test/event/MyEvent.java | 15 + .../com/qn/test/event/MyEventListener.java | 12 + .../main/java/com/qn/test/sort/SortDemo.java | 43 ++ .../src/main/java/com/qn/utils/AesUtil.java | 60 +++ common/src/main/java/com/qn/utils/Base64.java | 285 ++++++++++++ .../src/main/java/com/qn/utils/BeanUtil.java | 423 ++++++++++++++++++ .../utils/{HTTPUtils.java => HttpUtils.java} | 2 +- .../java/com/qn/utils/JacksonJsonUtil.java | 167 +++++++ common/src/main/java/com/qn/utils/Pager.java | 113 +++++ .../src/main/java/com/qn/utils/Pageutils.java | 36 ++ .../main/java/com/qn/utils/Pagination.java | 86 ++++ .../main/java/com/qn/utils/UUIDGenerator.java | 41 ++ pom.xml | 7 + .../com/qn/controller/TestController.java | 9 + .../com/qn/controller/WXTokenController.java | 2 +- .../com/qn/controller/utils/MessageUtils.java | 2 +- 39 files changed, 2180 insertions(+), 5 deletions(-) create mode 100644 common/src/main/java/com/qn/dwonline/BaseAction.java create mode 100644 common/src/main/java/com/qn/dwonline/DwOnline.java create mode 100644 common/src/main/java/com/qn/dwonline/common/CmdList.java create mode 100644 common/src/main/java/com/qn/dwonline/common/FindType.java create mode 100644 common/src/main/java/com/qn/dwonline/commond/BaseCMD.java create mode 100644 common/src/main/java/com/qn/dwonline/commond/BlackWind.java create mode 100644 common/src/main/java/com/qn/dwonline/commond/DangKou.java create mode 100644 common/src/main/java/com/qn/dwonline/commond/EatPeople.java create mode 100644 common/src/main/java/com/qn/dwonline/commond/GaoTreasury.java create mode 100644 common/src/main/java/com/qn/dwonline/commond/IceStone.java create mode 100644 common/src/main/java/com/qn/dwonline/commond/JiangduWangfu.java create mode 100644 common/src/main/java/com/qn/dwonline/commond/ShaoHuaShan.java create mode 100644 common/src/main/java/com/qn/dwonline/commond/ShiJiaZhuang.java create mode 100644 common/src/main/java/com/qn/dwonline/commond/Test.java create mode 100644 common/src/main/java/com/qn/dwonline/commond/pick/DaBaiCai.java create mode 100644 common/src/main/java/com/qn/dwonline/dojbo/FuBenAction.java create mode 100644 common/src/main/java/com/qn/dwonline/dojbo/PickAction.java create mode 100644 common/src/main/java/com/qn/dwonline/dojbo/TestAction.java rename common/src/main/java/{ => com/qn}/model/wx/TextMessage.java (97%) create mode 100644 common/src/main/java/com/qn/test/event/EventSourceObject.java create mode 100644 common/src/main/java/com/qn/test/event/MainEventTest.java create mode 100644 common/src/main/java/com/qn/test/event/MyEvent.java create mode 100644 common/src/main/java/com/qn/test/event/MyEventListener.java create mode 100644 common/src/main/java/com/qn/test/sort/SortDemo.java create mode 100644 common/src/main/java/com/qn/utils/AesUtil.java create mode 100644 common/src/main/java/com/qn/utils/Base64.java create mode 100644 common/src/main/java/com/qn/utils/BeanUtil.java rename common/src/main/java/com/qn/utils/{HTTPUtils.java => HttpUtils.java} (99%) create mode 100644 common/src/main/java/com/qn/utils/JacksonJsonUtil.java create mode 100644 common/src/main/java/com/qn/utils/Pager.java create mode 100644 common/src/main/java/com/qn/utils/Pageutils.java create mode 100644 common/src/main/java/com/qn/utils/Pagination.java create mode 100644 common/src/main/java/com/qn/utils/UUIDGenerator.java diff --git a/bootstrap/src/main/java/com/qn/DemoApplication.java b/bootstrap/src/main/java/com/qn/DemoApplication.java index ece70be..e935eb8 100644 --- a/bootstrap/src/main/java/com/qn/DemoApplication.java +++ b/bootstrap/src/main/java/com/qn/DemoApplication.java @@ -2,8 +2,10 @@ package com.qn; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ImportResource; @SpringBootApplication +@ImportResource({"classpath*:spring/web-*.xml"}) public class DemoApplication { public static void main(String[] args) { diff --git a/common/pom.xml b/common/pom.xml index d4f9194..face3c3 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -17,6 +17,21 @@ org.apache.httpcomponents httpclient + + commons-logging + commons-logging + 1.2 + + + org.codehaus.jackson + jackson-xc + 1.9.12 + + + org.slf4j + slf4j-api + 1.7.25 + - \ No newline at end of file + diff --git a/common/src/main/java/com/qn/dwonline/BaseAction.java b/common/src/main/java/com/qn/dwonline/BaseAction.java new file mode 100644 index 0000000..ed8d5ad --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/BaseAction.java @@ -0,0 +1,117 @@ +package com.qn.dwonline; + +import com.qn.dwonline.common.CmdList; +import com.qn.dwonline.common.FindType; +import com.qn.dwonline.commond.BaseCMD; +import com.qn.utils.HttpUtils; + +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class BaseAction { + + private String SEND_URL = "http://111.230.193.166:1880/gCmd.do?cmd="; + private String APPEND_SID = "&sid="; + private String SID = ""; + private String currentUrl = ""; + protected final String FIGHT = "Fight"; + private String currentMsg; + private Map target = new HashMap<>(); + + public BaseAction(String sid){ + SID = sid; + currentUrl = SEND_URL + 00 + APPEND_SID + SID; + } + + public void doJob(BaseCMD cmd){ + CmdList cmdList = cmd.getCmdMap(); + cmdList.forEach((cmdStr) -> { + try { + String[] split = cmdStr.split("&"); + System.out.println("下一个命令是" + split[0]); + if (FIGHT.equals(split[0])){ + fight(); + }else { + sendNewRequest(split[0], FindType.valueOf(split[1])); + } + } catch (InterruptedException e) { + System.err.println("错误了!!!"); + e.printStackTrace(); + } + }); + } + + private void sendNewRequest(String cmdStr, FindType type) throws InterruptedException { + Thread.sleep(800); + String next = ""; + if (type == FindType.ALL){ + next = target.get(cmdStr); + }else { + for (String temp : target.keySet()){ + if (temp.contains(cmdStr)){ + next = target.get(temp); + } + } + } + if(next == null || "".equals(next)){ + next = "00"; + } + System.out.println(cmdStr + "Next CMD ID ===" + next); + if (next != null) { + currentUrl = SEND_URL + next + APPEND_SID + SID; + } + String result = HttpUtils.doGet(currentUrl); + if (result != null && !"".equals(result)){ + String substring = result.substring(result.indexOf("

")+3, result.indexOf("").matcher(result); + while (matcher.find()){ + String group = matcher.group(0); + int cmdEnd = group.indexOf("&"); + int first = group.indexOf(">"); + int last = group.indexOf("<"); + String key = group.substring(first+1, last); + String cmd = group.substring(4, cmdEnd); + target.put(key,cmd); + } + } + + private void fight() throws InterruptedException { + if (!target.containsKey("雁翎刀法")){ + return; + } + while (!"战斗已经结束!".equals(currentMsg)){ + if (currentMsg.contains("成功闯过")){ + break; + } + if (target.containsKey("雁翎刀法")){ + String next = target.get("雁翎刀法"); + if (next != null) { + sendNewRequest("雁翎刀法",FindType.ALL); + } + } + } + List list = new ArrayList<>(); + for (String t : needThings){ + target.forEach((x,y) -> { + if (x.contains(t)){ + list.add(t); + } + }); + } + for (String str : list){ + sendNewRequest(str,FindType.CONT); + } + sendNewRequest("返回游戏",FindType.ALL); + } + + String [] needThings = new String[]{ + "山谷灵芝","毒蛇胆","食人怪鱼鱼鳞","食人谷","魄力丹","蛇筋","马","训练书","必杀技","冰珠","冰魄珠","太尉秘图","龙鳞","大白菜", + "牛皮" + }; + +} diff --git a/common/src/main/java/com/qn/dwonline/DwOnline.java b/common/src/main/java/com/qn/dwonline/DwOnline.java new file mode 100644 index 0000000..1a4ad8d --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/DwOnline.java @@ -0,0 +1,22 @@ +package com.qn.dwonline; + +public class DwOnline{ + + + private static String SEND_URL = "http://111.230.193.166:1880/gCmd.do?cmd="; + private static String APPEND = "&sid="; + private static String CURRENT_SID = "pvfw1h50ybuljdeopt6rn"; + + + public static void main(String[] args) throws InterruptedException { + String url = SEND_URL + "00" + APPEND + CURRENT_SID; + // 循环(死循环) + while (true){ +// url = sendNewRequest(url,"升级",FindType.ALL); +// url = sendNewRequest(url,"确定升级",FindType.ALL); +// url = sendNewRequest(url,"加速",FindType.ALL); +// url = sendNewRequest(url,"加速全部",FindType.CONT); + } + } + +} diff --git a/common/src/main/java/com/qn/dwonline/common/CmdList.java b/common/src/main/java/com/qn/dwonline/common/CmdList.java new file mode 100644 index 0000000..7853b0a --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/common/CmdList.java @@ -0,0 +1,12 @@ +package com.qn.dwonline.common; + +import java.util.ArrayList; + +public class CmdList extends ArrayList { + + public void put(String cmd,FindType findType){ + String type = cmd + "&" + findType; + this.add((E) type); + } + +} diff --git a/common/src/main/java/com/qn/dwonline/common/FindType.java b/common/src/main/java/com/qn/dwonline/common/FindType.java new file mode 100644 index 0000000..91e8aa6 --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/common/FindType.java @@ -0,0 +1,7 @@ +package com.qn.dwonline.common; + +public enum FindType { + ALL, + CONT, + IF_EXIST_LOOP +} diff --git a/common/src/main/java/com/qn/dwonline/commond/BaseCMD.java b/common/src/main/java/com/qn/dwonline/commond/BaseCMD.java new file mode 100644 index 0000000..d3a77c0 --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/commond/BaseCMD.java @@ -0,0 +1,46 @@ +package com.qn.dwonline.commond; + +import com.qn.dwonline.common.CmdList; +import com.qn.dwonline.common.FindType; + +public abstract class BaseCMD { + + protected CmdList cmd = new CmdList(); + + protected final String FIGHT = "Fight"; + + public int times; + + public CmdList getCmdMap(){ + cmd.put("INIT SEND REQUEST",FindType.ALL); + preCmd(); + return cmd; + } + + protected abstract void preCmd(); + + protected void fight(String fightWith){ + cmd.put(fightWith,FindType.ALL); + cmd.put("攻击" + fightWith,FindType.ALL); + cmd.put(FIGHT,FindType.ALL); + } + + protected void fight(String fightWith,String match){ + cmd.put(fightWith,FindType.CONT); + cmd.put("攻击" + fightWith,FindType.CONT); + cmd.put(FIGHT,FindType.ALL); + } + + protected void clickFight(String fightWith){ + cmd.put(fightWith,FindType.CONT); + cmd.put(FIGHT,FindType.CONT); + } + + public int getTimes() { + return times; + } + + public void setTimes(int times) { + this.times = times; + } +} diff --git a/common/src/main/java/com/qn/dwonline/commond/BlackWind.java b/common/src/main/java/com/qn/dwonline/commond/BlackWind.java new file mode 100644 index 0000000..a04e432 --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/commond/BlackWind.java @@ -0,0 +1,42 @@ +package com.qn.dwonline.commond; + +import com.qn.dwonline.common.FindType; + +public class BlackWind extends BaseCMD{ + + @Override + public void preCmd() { + this.times = 3; + cmd.put("黑风岭砍柴老者",FindType.ALL); + cmd.put("进入黑风岭副本",FindType.ALL); + cmd.put("继续",FindType.ALL); + cmd.put("右:黑松林→",FindType.ALL); + cmd.put("右:黑松林→",FindType.ALL); + cmd.put("右:黑松林→",FindType.ALL); + cmd.put("右:乱石河边→",FindType.ALL); + cmd.put("进入乱石河",FindType.ALL); + fight("巨型鲤鱼"); + cmd.put("进入猛虎坡",FindType.ALL); + fight("病大虫"); + cmd.put("进入猛虎洞",FindType.ALL); + fight("黑风虎"); + cmd.put("进入洞穴",FindType.ALL); + fight("黑风雌虎"); + fight("黑风雌虎"); +// cmd.put("右:干草洞穴→",FindType.ALL); +// fight("幼虎"); +// fight("幼虎"); +// cmd.put("左:洞穴←",FindType.ALL); + cmd.put("进入窄路",FindType.ALL); + fight("黑风雄虎"); + cmd.put("右:大洞穴→",FindType.ALL); + fight("狮虎兽"); + cmd.put("左:窄路←",FindType.ALL); + cmd.put("进入潮湿小路",FindType.ALL); + cmd.put("左:内洞←",FindType.ALL); + fight("巨型猛虎"); + cmd.put("右:潮湿小路→",FindType.ALL); + cmd.put("进入巨型洞穴",FindType.ALL); + fight("虎王"); + } +} diff --git a/common/src/main/java/com/qn/dwonline/commond/DangKou.java b/common/src/main/java/com/qn/dwonline/commond/DangKou.java new file mode 100644 index 0000000..a887858 --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/commond/DangKou.java @@ -0,0 +1,49 @@ +package com.qn.dwonline.commond; + +import com.qn.dwonline.common.FindType; + +public class DangKou extends BaseCMD{ + + @Override + public void preCmd() { + cmd.put("下:草原↓", FindType.ALL); + cmd.put("下:草原↓", FindType.ALL); + cmd.put("右:草原→", FindType.ALL); + cmd.put("下:绿洲↓", FindType.ALL); + cmd.put("下:绿洲↓", FindType.ALL); + cmd.put("右:红帐篷→", FindType.ALL); + fight("波斯人入侵者"); + cmd.put("左:绿洲←",FindType.ALL); + cmd.put("左:绿洲←",FindType.ALL); + cmd.put("下:黑帐篷↓",FindType.ALL); + fight("叛乱喇嘛"); + fight("叛乱喇嘛"); + cmd.put("进入密道",FindType.ALL); + cmd.put("确定进入",FindType.ALL); + cmd.put(FIGHT,FindType.ALL); + cmd.put("右:密道→",FindType.ALL); + cmd.put(FIGHT,FindType.ALL); + cmd.put("右:密道→",FindType.ALL); + cmd.put(FIGHT,FindType.ALL); + cmd.put("右:密道→",FindType.ALL); + cmd.put(FIGHT,FindType.ALL); + cmd.put("下:密道↓",FindType.ALL); + cmd.put(FIGHT,FindType.ALL); + cmd.put("右:密道→",FindType.ALL); + cmd.put(FIGHT,FindType.ALL); + cmd.put("下:密道↓",FindType.ALL); + cmd.put(FIGHT,FindType.ALL); + cmd.put("下:密道↓",FindType.ALL); + cmd.put(FIGHT,FindType.ALL); + cmd.put("下:毒虫殿↓",FindType.ALL); + fight("恶毒蝎子王"); + fight("巨型青蛙王"); + fight("奇异毒蛇王"); + fight("吸血蝙蝠王"); + cmd.put("进入巫婆殿",FindType.ALL); + fight("叶比亚",""); + + + + } +} diff --git a/common/src/main/java/com/qn/dwonline/commond/EatPeople.java b/common/src/main/java/com/qn/dwonline/commond/EatPeople.java new file mode 100644 index 0000000..e0e8738 --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/commond/EatPeople.java @@ -0,0 +1,47 @@ +package com.qn.dwonline.commond; + +import com.qn.dwonline.common.FindType; + +public class EatPeople extends BaseCMD{ + + @Override + public void preCmd() { + cmd.put("进入食人谷副本",FindType.ALL); + fight("守谷小喽罗"); + cmd.put("进入悬崖大树",FindType.ALL); + fight("大吼猴"); + cmd.put("下:食人谷口↓",FindType.ALL); + cmd.put("进入一线天",FindType.ALL); + fight("剧毒奇寒蛇"); + cmd.put("进入狭小石门",FindType.ALL); + fight("食人谷守卫"); + fight("食人谷守卫"); + cmd.put("进入小河边",FindType.ALL); + fight("食人谷力士"); + cmd.put("进入河底",FindType.ALL); + fight("食人怪鱼"); + cmd.put("左:小河边←",FindType.ALL); + cmd.put("上:小路↑",FindType.ALL); + cmd.put("右:巨型峡谷→",FindType.ALL); + fight("食人谷护法"); + cmd.put("上:奇异果园↑",FindType.ALL); + cmd.put("食人谷果农",FindType.ALL); + cmd.put("配置狂暴一",FindType.ALL); + cmd.put("返回食人谷果农",FindType.ALL); + cmd.put("返回游戏",FindType.ALL); + cmd.put("下:巨型峡谷↓",FindType.ALL); + cmd.put("进入谷内小屋",FindType.ALL); + cmd.put("继续",FindType.ALL); + fight("食人谷五当家"); + cmd.put("右:大堂→",FindType.ALL); + fight("食人谷四当家"); + cmd.put("上:北偏厅↑",FindType.ALL); + fight("食人谷三当家"); + cmd.put("下:大堂↓",FindType.ALL); + cmd.put("下:南偏厅↓",FindType.ALL); + fight("食人谷二当家"); + cmd.put("上:大堂↑",FindType.ALL); + cmd.put("进入暗室",FindType.ALL); + fight("食人谷大当家"); + } +} diff --git a/common/src/main/java/com/qn/dwonline/commond/GaoTreasury.java b/common/src/main/java/com/qn/dwonline/commond/GaoTreasury.java new file mode 100644 index 0000000..d4b9ed4 --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/commond/GaoTreasury.java @@ -0,0 +1,59 @@ +package com.qn.dwonline.commond; + +import com.qn.dwonline.common.FindType; + +public class GaoTreasury extends BaseCMD{ + + @Override + public void preCmd() { + this.times = 2; + cmd.put("进入太尉宝库副本",FindType.ALL); + fight("宝库铁甲兵"); + cmd.put("进入下.一石阶",FindType.ALL); + cmd.put("返回游戏",FindType.ALL); + fight("宝库精甲兵"); + cmd.put("上:石室↑",FindType.ALL); + fight("宝库铁甲守将"); + cmd.put("下:石阶↓",FindType.ALL); + cmd.put("下:石室↓",FindType.ALL); + fight("宝库精甲守将"); + cmd.put("上:石阶↑",FindType.ALL); + cmd.put("进入过道",FindType.ALL); + fight("宝库钢甲兵"); + cmd.put("进入下.一过道",FindType.ALL); + cmd.put("返回游戏",FindType.ALL); + fight("宝库银甲兵"); + cmd.put("上:铁屋↑",FindType.ALL); + fight("黄将军","true"); + cmd.put("右:铁屋→",FindType.ALL); + fight("李将军","true"); + cmd.put("左:铁屋←",FindType.ALL); + cmd.put("下:过道↓",FindType.ALL); + cmd.put("下:铁屋↓",FindType.ALL); + fight("史将军","true"); + cmd.put("右:铁屋→",FindType.ALL); + fight("封将军","true"); + cmd.put("左:铁屋←",FindType.ALL); + cmd.put("上:过道↑",FindType.ALL); + cmd.put("进入秘道",FindType.ALL); + fight("宝库白银守将"); + cmd.put("进入下.一秘道",FindType.ALL); + fight("宝库黄金守将"); + cmd.put("进入下.一秘道",FindType.ALL); + cmd.put("下:秘道↓",FindType.ALL); + cmd.put("左:秘道←",FindType.ALL); + cmd.put("左:秘道←",FindType.ALL); + cmd.put("下:秘道↓",FindType.ALL); + cmd.put("下:秘道↓",FindType.ALL); + cmd.put("右:秘道→",FindType.ALL); + cmd.put("下:秘道↓",FindType.ALL); + cmd.put("右:秘道→",FindType.ALL); + cmd.put("右:藏宝库巨门→",FindType.ALL); + fight("高不低","true"); + cmd.put("进入太尉宝库",FindType.ALL); + fight("高破风","true"); + } + + + +} diff --git a/common/src/main/java/com/qn/dwonline/commond/IceStone.java b/common/src/main/java/com/qn/dwonline/commond/IceStone.java new file mode 100644 index 0000000..addad43 --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/commond/IceStone.java @@ -0,0 +1,115 @@ +package com.qn.dwonline.commond; + +import com.qn.dwonline.common.FindType; + +public class IceStone extends BaseCMD{ + + @Override + public void preCmd() { + setTimes(2); + cmd.put("冰封老人",FindType.ALL); + cmd.put("进入冰魄洞副本",FindType.ALL); + cmd.put("传送进冰魄洞",FindType.ALL); + cmd.put("返回游戏",FindType.ALL); + cmd.put("返回游戏",FindType.ALL); + + fight("水洞守卫"); + cmd.put("上:水洞↑",FindType.ALL); + fight("水洞守卫"); + cmd.put("右:水洞→",FindType.ALL); + fight("水洞守卫"); + cmd.put("下:水洞↓",FindType.ALL); + fight("水洞守卫"); + cmd.put("下:水洞↓",FindType.ALL); + fight("水洞守卫"); + cmd.put("左:水洞←",FindType.ALL); + fight("水洞守卫"); + cmd.put("上:水洞↑",FindType.ALL); + cmd.put("右:水洞→",FindType.ALL); + cmd.put("右:水洞→",FindType.ALL); + fight("水洞守卫"); + fight("水灵怪兽"); + + // 木洞 + cmd.put("进入木洞",FindType.ALL); + cmd.put("返回游戏",FindType.ALL); + fight("木洞守卫"); + cmd.put("上:木洞↑",FindType.ALL); + fight("木洞守卫"); + cmd.put("上:木洞↑",FindType.ALL); + fight("木洞守卫"); + cmd.put("右:木洞→",FindType.ALL); + fight("木洞守卫"); + cmd.put("下:木洞↓",FindType.ALL); + fight("木洞守卫"); + cmd.put("下:木洞↓",FindType.ALL); + fight("木洞守卫"); + cmd.put("下:木洞↓",FindType.ALL); + fight("木洞守卫"); + cmd.put("下:木洞↓",FindType.ALL); + fight("木洞守卫"); + cmd.put("左:木洞←",FindType.ALL); + fight("木洞守卫"); + cmd.put("上:木洞↑",FindType.ALL); + fight("木洞守卫"); + cmd.put("上:木洞↑",FindType.ALL); + cmd.put("右:木洞→",FindType.ALL); + cmd.put("右:木洞→",FindType.ALL); + fight("木洞守卫"); + fight("木灵怪兽"); + + // 冰洞 + cmd.put("进入冰洞",FindType.ALL); + cmd.put("返回游戏",FindType.ALL); + fight("冰洞守卫"); + cmd.put("上:冰洞↑",FindType.ALL); + fight("冰洞守卫"); + cmd.put("上:冰洞↑",FindType.ALL); + fight("冰洞守卫"); + cmd.put("右:冰洞→",FindType.ALL); + fight("冰洞守卫"); + cmd.put("右:冰洞→",FindType.ALL); + fight("冰洞守卫"); + cmd.put("下:冰洞↓",FindType.ALL); + fight("冰洞守卫"); + cmd.put("左:冰洞←",FindType.ALL); + fight("冰洞守卫"); + cmd.put("下:冰洞↓",FindType.ALL); + fight("冰洞守卫"); + cmd.put("下:冰洞↓",FindType.ALL); + fight("冰洞守卫"); + cmd.put("左:冰洞←",FindType.ALL); + fight("冰洞守卫"); + cmd.put("下:冰洞↓",FindType.ALL); + fight("冰洞守卫"); + cmd.put("右:冰洞→",FindType.ALL); + fight("冰洞守卫"); + cmd.put("右:冰洞→",FindType.ALL); + fight("冰洞守卫"); + cmd.put("上:冰洞↑",FindType.ALL); + fight("冰洞守卫"); + cmd.put("上:冰洞↑",FindType.ALL); + fight("冰洞守卫"); + cmd.put("右:冰洞→",FindType.ALL); + fight("冰洞守卫"); + fight("冰灵怪兽"); + + //收尾了 + cmd.put("进入黑金桥",FindType.ALL); + fight("黑金使者"); + cmd.put("进入紫土桥",FindType.ALL); + fight("紫土使者"); + cmd.put("进入铁木桥",FindType.ALL); + fight("铁木使者"); + cmd.put("进入寒水桥",FindType.ALL); + fight("寒水使者"); + cmd.put("进入烈焰桥",FindType.ALL); + fight("烈焰使者"); + cmd.put("进入冰魄洞",FindType.ALL); + fight("天怒神兽"); + fight("冰魄异兽"); + } + + + +} diff --git a/common/src/main/java/com/qn/dwonline/commond/JiangduWangfu.java b/common/src/main/java/com/qn/dwonline/commond/JiangduWangfu.java new file mode 100644 index 0000000..7704339 --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/commond/JiangduWangfu.java @@ -0,0 +1,47 @@ +package com.qn.dwonline.commond; + +import com.qn.dwonline.common.FindType; + +public class JiangduWangfu extends BaseCMD{ + @Override + public void preCmd() { + cmd.put("王生妻子.佩蓉", FindType.ALL); + cmd.put("传送到九霄洞副本", FindType.ALL); + cmd.put("我愿意", FindType.ALL); + cmd.put("下:沙漠↓", FindType.ALL); + fight("沙漠蜥蜴"); + cmd.put("下:沙漠↓", FindType.ALL); + fight("沙漠蜥蜴"); + cmd.put("下:沙漠↓", FindType.ALL); + fight("沙漠蜥蜴"); + cmd.put("下:沙漠↓", FindType.ALL); + fight("沙漠蜥蜴"); + cmd.put("下:沙漠↓", FindType.ALL); + fight("沙漠蜥蜴"); + cmd.put("右:沙漠→", FindType.ALL); + fight("沙漠蜥蜴"); + cmd.put("上:沙漠↑", FindType.ALL); + fight("沙漠蜥蜴"); + cmd.put("上:沙漠↑", FindType.ALL); + fight("沙漠蜥蜴"); + cmd.put("上:沙漠↑", FindType.ALL); + fight("沙漠蜥蜴"); + cmd.put("上:沙漠↑", FindType.ALL); + fight("沙漠蜥蜴"); + cmd.put("右:沙漠→", FindType.ALL); + fight("沙漠蜥蜴"); + cmd.put("下:沙漠↓", FindType.ALL); + fight("沙漠蜥蜴"); + cmd.put("下:沙漠↓", FindType.ALL); + fight("沙漠蜥蜴"); + cmd.put("下:沙漠↓", FindType.ALL); + fight("沙漠蜥蜴"); + cmd.put("下:沙漠↓", FindType.ALL); + fight("沙漠蜥蜴"); + cmd.put("进入峭壁",FindType.ALL); + fight("小易",""); + cmd.put("进入九霄洞",FindType.ALL); +// fight("小唯",""); + + } +} diff --git a/common/src/main/java/com/qn/dwonline/commond/ShaoHuaShan.java b/common/src/main/java/com/qn/dwonline/commond/ShaoHuaShan.java new file mode 100644 index 0000000..cdbbcdc --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/commond/ShaoHuaShan.java @@ -0,0 +1,53 @@ +package com.qn.dwonline.commond; + +import com.qn.dwonline.common.FindType; + +public class ShaoHuaShan extends BaseCMD{ + + + @Override + public void preCmd() { + cmd.put("少华山石匠", FindType.ALL); + cmd.put("传送至落雪山副本", FindType.ALL); + fight("落雪山草寇"); + cmd.put("进入雪地", FindType.ALL); + cmd.put("左:雪地←",FindType.ALL); + cmd.put("左:雪地←",FindType.ALL); + cmd.put("下:冰窟↓",FindType.ALL); + fight("冰原毒蛇"); + cmd.put("上:雪地↑",FindType.ALL); + cmd.put("右:雪地→",FindType.ALL); + cmd.put("右:雪地→",FindType.ALL); + cmd.put("右:雪地→",FindType.ALL); + cmd.put("右:雪地→",FindType.ALL); + cmd.put("上:雪地↑",FindType.ALL); + cmd.put("右:冰河→",FindType.ALL); + fight("冰河巨鱼"); + cmd.put("左:雪地←",FindType.ALL); + cmd.put("下:雪地↓",FindType.ALL); + cmd.put("下:雪地↓",FindType.ALL); + cmd.put("右:雪地机关一→",FindType.ALL); + cmd.put("打开机关",FindType.ALL); + cmd.put("返回游戏",FindType.ALL); + cmd.put("左:雪地←",FindType.ALL); + cmd.put("左:雪地←",FindType.ALL); + cmd.put("上:雪地↑",FindType.ALL); + cmd.put("上:白雪地↑",FindType.ALL); + cmd.put("上:冰原↑",FindType.ALL); + fight("落雪山小首领"); + cmd.put("进入雪原",FindType.ALL); + fight("落雪山首领"); + cmd.put("进入白雪河",FindType.ALL); + fight("落雪山七当家"); + cmd.put("进入寒冰路",FindType.ALL); + fight("落雪山六当家"); + cmd.put("进入寒冰坡",FindType.ALL); + fight("落雪山五当家"); + cmd.put("进入白雪路",FindType.ALL); + fight("落雪山四当家"); + cmd.put("进入落雪山顶",FindType.ALL); + fight("落雪山三当家"); + cmd.put("右:落雪洞一→",FindType.ALL); + fight("落雪山二当家"); + } +} diff --git a/common/src/main/java/com/qn/dwonline/commond/ShiJiaZhuang.java b/common/src/main/java/com/qn/dwonline/commond/ShiJiaZhuang.java new file mode 100644 index 0000000..3737833 --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/commond/ShiJiaZhuang.java @@ -0,0 +1,69 @@ +package com.qn.dwonline.commond; + +import com.qn.dwonline.common.FindType; + +public class ShiJiaZhuang extends BaseCMD{ + + + @Override + public void preCmd() { + cmd.put("史家庄童仆", FindType.ALL); + cmd.put("传送至云树山副本", FindType.ALL); + fight("云树林守卫"); + cmd.put("进入云树林", FindType.ALL); + fight("小红虫"); + fight("小红虫"); + fight("大红虫"); + cmd.put("左:云树林←",FindType.ALL); + fight("小红虫"); + fight("小红虫"); + fight("大红虫"); + cmd.put("上:云树林↑",FindType.ALL); + fight("小红虫"); + fight("小红虫"); + fight("大红虫"); + cmd.put("下:云树林↓",FindType.ALL); + cmd.put("右:云树林→",FindType.ALL); + cmd.put("右:云树林→",FindType.ALL); + fight("小红虫"); + fight("小红虫"); + fight("大红虫"); + cmd.put("右:云树林→",FindType.ALL); + fight("小红虫"); + fight("小红虫"); + fight("大红虫"); + cmd.put("右:云树林→",FindType.ALL); + fight("小红虫"); + fight("小红虫"); + fight("大红虫"); + cmd.put("左:云树林←",FindType.ALL); + cmd.put("下:云树林↓",FindType.ALL); + fight("小红虫"); + fight("小红虫"); + fight("大红虫"); + cmd.put("上:云树林↑",FindType.ALL); + cmd.put("左:云树林←",FindType.ALL); + cmd.put("上:云树林↑",FindType.ALL); + fight("小红虫"); + fight("小红虫"); + fight("大红虫"); + cmd.put("下:云树林↓",FindType.ALL); + cmd.put("左:云树林←",FindType.ALL); + cmd.put("进入小河",FindType.ALL); + fight("大河鱼"); + cmd.put("进入小路",FindType.ALL); + cmd.put("上:土路↑",FindType.ALL); + fight("大土狗"); + cmd.put("进入石子路",FindType.ALL); + fight("大土狼"); + cmd.put("进入云树山脚",FindType.ALL); + fight("云树山守卫"); + cmd.put("进入山坡",FindType.ALL); + fight("云树山守将"); + cmd.put("进入云树山顶",FindType.ALL); + fight("云树山二当家"); + cmd.put("进入小草屋",FindType.ALL); + fight("云树山大当家"); + + } +} diff --git a/common/src/main/java/com/qn/dwonline/commond/Test.java b/common/src/main/java/com/qn/dwonline/commond/Test.java new file mode 100644 index 0000000..1e7d845 --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/commond/Test.java @@ -0,0 +1,15 @@ +package com.qn.dwonline.commond; + +public class Test extends BaseCMD{ + + private String fightFor; + + public Test(String fightFor) { + this.fightFor = fightFor; + } + + @Override + public void preCmd() { + fight(fightFor); + } +} diff --git a/common/src/main/java/com/qn/dwonline/commond/pick/DaBaiCai.java b/common/src/main/java/com/qn/dwonline/commond/pick/DaBaiCai.java new file mode 100644 index 0000000..1dcdc50 --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/commond/pick/DaBaiCai.java @@ -0,0 +1,31 @@ +package com.qn.dwonline.commond.pick; + +import com.qn.dwonline.common.FindType; +import com.qn.dwonline.commond.BaseCMD; + +public class DaBaiCai extends BaseCMD { + @Override + protected void preCmd() { + clickFight("偷菜盗贼"); + cmd.put("左:菜畦←", FindType.ALL); + clickFight("偷菜盗贼"); + cmd.put("上:菜畦↑", FindType.ALL); + clickFight("偷菜盗贼"); + cmd.put("左:菜畦←", FindType.ALL); + clickFight("偷菜盗贼"); + cmd.put("左:菜畦←", FindType.ALL); + clickFight("偷菜盗贼"); + cmd.put("下:菜畦↓", FindType.ALL); + clickFight("偷菜盗贼"); + cmd.put("右:菜畦→", FindType.ALL); + clickFight("偷菜盗贼"); + cmd.put("下:菜畦↓", FindType.ALL); + clickFight("偷菜盗贼"); + cmd.put("右:菜畦→", FindType.ALL); + clickFight("偷菜盗贼"); + cmd.put("上:菜畦↑", FindType.ALL); + clickFight("偷菜盗贼"); + cmd.put("右:菜畦→", FindType.ALL); + clickFight("偷菜盗贼"); + } +} diff --git a/common/src/main/java/com/qn/dwonline/dojbo/FuBenAction.java b/common/src/main/java/com/qn/dwonline/dojbo/FuBenAction.java new file mode 100644 index 0000000..f5091be --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/dojbo/FuBenAction.java @@ -0,0 +1,39 @@ +package com.qn.dwonline.dojbo; + +import com.qn.dwonline.BaseAction; +import com.qn.dwonline.commond.*; + +public class FuBenAction { + + public static void main(String[] args) { + BaseCMD baseCMD = doWhichOne(3); + int times = baseCMD.getTimes(); + BaseAction baseAction = new BaseAction("i5gnhu51jtbicraw5t8pl"); +// for (int i = 0; i < times; i++){ + baseAction.doJob(baseCMD); +// } + } + + static BaseCMD doWhichOne(int i){ + switch (i){ + case 1: + return new ShiJiaZhuang(); + case 2: + return new ShaoHuaShan(); + case 3: + return new EatPeople(); + case 4: + return new GaoTreasury(); + case 5: + return new IceStone(); + case 6: + return new JiangduWangfu(); + case 7: + return new DangKou(); + default: + return new BlackWind(); + } + } + + +} diff --git a/common/src/main/java/com/qn/dwonline/dojbo/PickAction.java b/common/src/main/java/com/qn/dwonline/dojbo/PickAction.java new file mode 100644 index 0000000..08bfdc7 --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/dojbo/PickAction.java @@ -0,0 +1,19 @@ +package com.qn.dwonline.dojbo; + +import com.qn.dwonline.BaseAction; +import com.qn.dwonline.commond.*; +import com.qn.dwonline.commond.pick.DaBaiCai; + +public class PickAction { + + public static void main(String[] args) { + BaseCMD baseCMD = new DaBaiCai(); + BaseAction baseAction = new BaseAction("xq31ce51i2vqwn8t8qglo"); + int i=0; + while (true){ + System.out.println("第"+(++i)+"次循环"); + baseAction.doJob(baseCMD); + } + } + +} diff --git a/common/src/main/java/com/qn/dwonline/dojbo/TestAction.java b/common/src/main/java/com/qn/dwonline/dojbo/TestAction.java new file mode 100644 index 0000000..29a8464 --- /dev/null +++ b/common/src/main/java/com/qn/dwonline/dojbo/TestAction.java @@ -0,0 +1,14 @@ +package com.qn.dwonline.dojbo; + +import com.qn.dwonline.BaseAction; +import com.qn.dwonline.commond.*; + +public class TestAction { + public static void main(String[] args) { + BaseCMD baseCMD = new Test("老黄牛"); + BaseAction baseAction = new BaseAction("dzh5xd51kaeiq0b2b0zqn"); + while (true){ + baseAction.doJob(baseCMD); + } + } +} diff --git a/common/src/main/java/model/wx/TextMessage.java b/common/src/main/java/com/qn/model/wx/TextMessage.java similarity index 97% rename from common/src/main/java/model/wx/TextMessage.java rename to common/src/main/java/com/qn/model/wx/TextMessage.java index 96f298b..8781ae0 100644 --- a/common/src/main/java/model/wx/TextMessage.java +++ b/common/src/main/java/com/qn/model/wx/TextMessage.java @@ -1,4 +1,4 @@ -package model.wx; +package com.qn.model.wx; import java.io.Serializable; diff --git a/common/src/main/java/com/qn/test/event/EventSourceObject.java b/common/src/main/java/com/qn/test/event/EventSourceObject.java new file mode 100644 index 0000000..b148efa --- /dev/null +++ b/common/src/main/java/com/qn/test/event/EventSourceObject.java @@ -0,0 +1,37 @@ +package com.qn.test.event; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +public class EventSourceObject { + private String name; + private Set listener; + + public EventSourceObject() { + this.name = "zhangsan"; + this.listener = new HashSet(); + } + + public void addMyListener(MyEventListener l){ + listener.add(l); + } + + protected void notifies(){ + System.out.println("事件源发生了,需要进行事件回调"); + Iterator iterator = listener.iterator(); + while (iterator.hasNext()){ + MyEventListener next = (MyEventListener) iterator.next(); + next.fire(new MyEvent(this)); + } + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + notifies(); + } +} diff --git a/common/src/main/java/com/qn/test/event/MainEventTest.java b/common/src/main/java/com/qn/test/event/MainEventTest.java new file mode 100644 index 0000000..c606ed6 --- /dev/null +++ b/common/src/main/java/com/qn/test/event/MainEventTest.java @@ -0,0 +1,21 @@ +package com.qn.test.event; + +import java.util.Timer; +import java.util.TimerTask; + +public class MainEventTest { + public static void main(String[] args) { + // 事件源 + EventSourceObject eventSourceObject = new EventSourceObject(); + eventSourceObject.addMyListener(new MyEventListener()); + eventSourceObject.setName("lisi"); + + Timer timer = new Timer(); + timer.schedule(new TimerTask() { + @Override + public void run() { + + } + },1000); + } +} diff --git a/common/src/main/java/com/qn/test/event/MyEvent.java b/common/src/main/java/com/qn/test/event/MyEvent.java new file mode 100644 index 0000000..53ae98e --- /dev/null +++ b/common/src/main/java/com/qn/test/event/MyEvent.java @@ -0,0 +1,15 @@ +package com.qn.test.event; + +import java.util.EventObject; + +public class MyEvent extends EventObject { + /** + * Constructs a prototypical Event. + * + * @param source The object on which the Event initially occurred. + * @throws IllegalArgumentException if source is null. + */ + public MyEvent(Object source) { + super(source); + } +} diff --git a/common/src/main/java/com/qn/test/event/MyEventListener.java b/common/src/main/java/com/qn/test/event/MyEventListener.java new file mode 100644 index 0000000..1f444ff --- /dev/null +++ b/common/src/main/java/com/qn/test/event/MyEventListener.java @@ -0,0 +1,12 @@ +package com.qn.test.event; + +import java.util.EventListener; + +public class MyEventListener implements EventListener { + + public void fire(MyEvent e){ + EventSourceObject source = (EventSourceObject) e.getSource(); + System.out.println("事件发生后" + source.getName()); + } + +} diff --git a/common/src/main/java/com/qn/test/sort/SortDemo.java b/common/src/main/java/com/qn/test/sort/SortDemo.java new file mode 100644 index 0000000..7c9ca5e --- /dev/null +++ b/common/src/main/java/com/qn/test/sort/SortDemo.java @@ -0,0 +1,43 @@ +package com.qn.test.sort; + +public class SortDemo { + + static int [] arr = {20,1,46,15,7,5,76,13,30,6,9,71,63,74,654,16,7894,1321,156,78,61,754,90,60,30,40,90,406}; + + //插入排序 + public static void sortTest1(){ + int length = arr.length; + for(int i = 1;i < length; i++){ + int temp = arr[i]; + int j; + for (j = i ; j > 0 && arr[j-1] > temp ; j-- ){ + arr[j] = arr[j-1]; + } + arr[j] = temp; + } + for(int o : arr){ + System.out.print(o + ","); + } + } + + //插入排序 + public static void sortTest2(){ + int length = arr.length; + for(int i = length/2 ;i > 0; i /= 2){ + int temp = arr[i]; + int j; + for (j = i ; j > 0 && arr[j-1] > temp ; j-- ){ + arr[j] = arr[j-1]; + } + arr[j] = temp; + } + for(int o : arr){ + System.out.print(o + ","); + } + } + + public static void main(String[] args) { + sortTest1(); + } + +} diff --git a/common/src/main/java/com/qn/utils/AesUtil.java b/common/src/main/java/com/qn/utils/AesUtil.java new file mode 100644 index 0000000..70e968c --- /dev/null +++ b/common/src/main/java/com/qn/utils/AesUtil.java @@ -0,0 +1,60 @@ +package com.qn.utils; +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; + +/** + * @author: wuyou + * @create: 2019-05-09 14:18 + **/ +public class AesUtil { + public static final String SECRET_KEY = "a69i3z8b516gd370"; + + /** + * Encrypt string. + * + * @param sSrc the s src + * @return the string + */ + public static String encrypt(String sSrc) { + try { + if (sSrc == null){ + return null; + } + byte[] raw = SECRET_KEY.getBytes(); + SecretKeySpec sKeySpec = new SecretKeySpec(raw, "AES"); + // "算法/模式/补码方式" + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + // 使用CBC模式,需要一个向量iv,可增加加密算法的强度 + IvParameterSpec iv = new IvParameterSpec("0102030405060708".getBytes()); + cipher.init(Cipher.ENCRYPT_MODE, sKeySpec, iv); + byte[] encrypted = cipher.doFinal(sSrc.getBytes()); + // 此处使用BASE64做转码功能,同时能起到2次加密的作用。 + return Base64.encodeS(encrypted); + } catch (Throwable e) { + return null; + } + } + + /** + * Decrypt string. + * + * @param sSrc the s src + * @return the string + */ + public static String decrypt(String sSrc) { + try { + byte[] raw = SECRET_KEY.getBytes("ASCII"); + SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + IvParameterSpec iv = new IvParameterSpec("0102030405060708".getBytes()); + cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); + // 先用base64解密 + byte[] encrypted1 = Base64.decode(sSrc); + byte[] original = cipher.doFinal(encrypted1); + return new String(original); + } catch (Throwable th) { + return null; + } + } +} diff --git a/common/src/main/java/com/qn/utils/Base64.java b/common/src/main/java/com/qn/utils/Base64.java new file mode 100644 index 0000000..7791b7d --- /dev/null +++ b/common/src/main/java/com/qn/utils/Base64.java @@ -0,0 +1,285 @@ +package com.qn.utils; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.zip.Deflater; +import java.util.zip.Inflater; + +/** + * @author: wuyou + * @create: 2019-05-09 14:19 + **/ +public class Base64 { + + private static final byte[] ENCODING_TABLE = {(byte) 'A', (byte) 'B', + (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F', (byte) 'G', + (byte) 'H', (byte) 'I', (byte) 'J', (byte) 'K', (byte) 'L', + (byte) 'M', (byte) 'N', (byte) 'O', (byte) 'P', (byte) 'Q', + (byte) 'R', (byte) 'S', (byte) 'T', (byte) 'U', (byte) 'V', + (byte) 'W', (byte) 'X', (byte) 'Y', (byte) 'Z', (byte) 'a', + (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', (byte) 'f', + (byte) 'g', (byte) 'h', (byte) 'i', (byte) 'j', (byte) 'k', + (byte) 'l', (byte) 'm', (byte) 'n', (byte) 'o', (byte) 'p', + (byte) 'q', (byte) 'r', (byte) 's', (byte) 't', (byte) 'u', + (byte) 'v', (byte) 'w', (byte) 'x', (byte) 'y', (byte) 'z', + (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', + (byte) '5', (byte) '6', (byte) '7', (byte) '8', (byte) '9', + (byte) '+', (byte) '/'}; + private static final byte[] DECODING_TABLE; + + static { + DECODING_TABLE = new byte[128]; + for (int i = 0; i < 128; i++) { + DECODING_TABLE[i] = (byte) -1; + } + for (int i = 'A'; i <= 'Z'; i++) { + DECODING_TABLE[i] = (byte) (i - 'A'); + } + for (int i = 'a'; i <= 'z'; i++) { + DECODING_TABLE[i] = (byte) (i - 'a' + 26); + } + for (int i = '0'; i <= '9'; i++) { + DECODING_TABLE[i] = (byte) (i - '0' + 52); + } + DECODING_TABLE['+'] = 62; + DECODING_TABLE['/'] = 63; + } + + public static String encodeS(byte[] data) { + return new String(encode(data)); + } + + public static byte[] encode(byte[] data) { + byte[] bytes; + int modulus = data.length % 3; + if (modulus == 0) { + bytes = new byte[(4 * data.length) / 3]; + } else { + bytes = new byte[4 * ((data.length / 3) + 1)]; + } + int dataLength = (data.length - modulus); + int a1; + int a2; + int a3; + for (int i = 0, j = 0; i < dataLength; i += 3, j += 4) { + a1 = data[i] & 0xff; + a2 = data[i + 1] & 0xff; + a3 = data[i + 2] & 0xff; + bytes[j] = ENCODING_TABLE[(a1 >>> 2) & 0x3f]; + bytes[j + 1] = ENCODING_TABLE[((a1 << 4) | (a2 >>> 4)) & 0x3f]; + bytes[j + 2] = ENCODING_TABLE[((a2 << 2) | (a3 >>> 6)) & 0x3f]; + bytes[j + 3] = ENCODING_TABLE[a3 & 0x3f]; + } + int b1; + int b2; + int b3; + int d1; + int d2; + switch (modulus) { + //nothing left to do + case 0: + break; + case 1: + d1 = data[data.length - 1] & 0xff; + b1 = (d1 >>> 2) & 0x3f; + b2 = (d1 << 4) & 0x3f; + bytes[bytes.length - 4] = ENCODING_TABLE[b1]; + bytes[bytes.length - 3] = ENCODING_TABLE[b2]; + bytes[bytes.length - 2] = (byte) '='; + bytes[bytes.length - 1] = (byte) '='; + break; + case 2: + d1 = data[data.length - 2] & 0xff; + d2 = data[data.length - 1] & 0xff; + b1 = (d1 >>> 2) & 0x3f; + b2 = ((d1 << 4) | (d2 >>> 4)) & 0x3f; + b3 = (d2 << 2) & 0x3f; + bytes[bytes.length - 4] = ENCODING_TABLE[b1]; + bytes[bytes.length - 3] = ENCODING_TABLE[b2]; + bytes[bytes.length - 2] = ENCODING_TABLE[b3]; + bytes[bytes.length - 1] = (byte) '='; + break; + default: + break; + } + return bytes; + } + + public static byte[] decode(byte[] data) { + byte[] bytes; + byte b1; + byte b2; + byte b3; + byte b4; + data = discardNonBase64Bytes(data); + if (data[data.length - 2] == '=') { + bytes = new byte[(((data.length / 4) - 1) * 3) + 1]; + } else if (data[data.length - 1] == '=') { + bytes = new byte[(((data.length / 4) - 1) * 3) + 2]; + } else { + bytes = new byte[((data.length / 4) * 3)]; + } + for (int i = 0, j = 0; i < (data.length - 4); i += 4, j += 3) { + b1 = DECODING_TABLE[data[i]]; + b2 = DECODING_TABLE[data[i + 1]]; + b3 = DECODING_TABLE[data[i + 2]]; + b4 = DECODING_TABLE[data[i + 3]]; + bytes[j] = (byte) ((b1 << 2) | (b2 >> 4)); + bytes[j + 1] = (byte) ((b2 << 4) | (b3 >> 2)); + bytes[j + 2] = (byte) ((b3 << 6) | b4); + } + if (data[data.length - 2] == '=') { + b1 = DECODING_TABLE[data[data.length - 4]]; + b2 = DECODING_TABLE[data[data.length - 3]]; + bytes[bytes.length - 1] = (byte) ((b1 << 2) | (b2 >> 4)); + } else if (data[data.length - 1] == '=') { + b1 = DECODING_TABLE[data[data.length - 4]]; + b2 = DECODING_TABLE[data[data.length - 3]]; + b3 = DECODING_TABLE[data[data.length - 2]]; + bytes[bytes.length - 2] = (byte) ((b1 << 2) | (b2 >> 4)); + bytes[bytes.length - 1] = (byte) ((b2 << 4) | (b3 >> 2)); + } else { + b1 = DECODING_TABLE[data[data.length - 4]]; + b2 = DECODING_TABLE[data[data.length - 3]]; + b3 = DECODING_TABLE[data[data.length - 2]]; + b4 = DECODING_TABLE[data[data.length - 1]]; + bytes[bytes.length - 3] = (byte) ((b1 << 2) | (b2 >> 4)); + bytes[bytes.length - 2] = (byte) ((b2 << 4) | (b3 >> 2)); + bytes[bytes.length - 1] = (byte) ((b3 << 6) | b4); + } + return bytes; + } + + public static byte[] decode(String data) { + byte[] bytes; + byte b1; + byte b2; + byte b3; + byte b4; + data = discardNonBase64Chars(data); + if (data.charAt(data.length() - 2) == '=') { + bytes = new byte[(((data.length() / 4) - 1) * 3) + 1]; + } else if (data.charAt(data.length() - 1) == '=') { + bytes = new byte[(((data.length() / 4) - 1) * 3) + 2]; + } else { + bytes = new byte[((data.length() / 4) * 3)]; + } + for (int i = 0, j = 0; i < (data.length() - 4); i += 4, j += 3) { + b1 = DECODING_TABLE[data.charAt(i)]; + b2 = DECODING_TABLE[data.charAt(i + 1)]; + b3 = DECODING_TABLE[data.charAt(i + 2)]; + b4 = DECODING_TABLE[data.charAt(i + 3)]; + bytes[j] = (byte) ((b1 << 2) | (b2 >> 4)); + bytes[j + 1] = (byte) ((b2 << 4) | (b3 >> 2)); + bytes[j + 2] = (byte) ((b3 << 6) | b4); + } + if (data.charAt(data.length() - 2) == '=') { + b1 = DECODING_TABLE[data.charAt(data.length() - 4)]; + b2 = DECODING_TABLE[data.charAt(data.length() - 3)]; + bytes[bytes.length - 1] = (byte) ((b1 << 2) | (b2 >> 4)); + } else if (data.charAt(data.length() - 1) == '=') { + b1 = DECODING_TABLE[data.charAt(data.length() - 4)]; + b2 = DECODING_TABLE[data.charAt(data.length() - 3)]; + b3 = DECODING_TABLE[data.charAt(data.length() - 2)]; + bytes[bytes.length - 2] = (byte) ((b1 << 2) | (b2 >> 4)); + bytes[bytes.length - 1] = (byte) ((b2 << 4) | (b3 >> 2)); + } else { + b1 = DECODING_TABLE[data.charAt(data.length() - 4)]; + b2 = DECODING_TABLE[data.charAt(data.length() - 3)]; + b3 = DECODING_TABLE[data.charAt(data.length() - 2)]; + b4 = DECODING_TABLE[data.charAt(data.length() - 1)]; + bytes[bytes.length - 3] = (byte) ((b1 << 2) | (b2 >> 4)); + bytes[bytes.length - 2] = (byte) ((b2 << 4) | (b3 >> 2)); + bytes[bytes.length - 1] = (byte) ((b3 << 6) | b4); + } + return bytes; + } + + private static byte[] discardNonBase64Bytes(byte[] data) { + byte[] temp = new byte[data.length]; + int bytesCopied = 0; + for (int i = 0; i < data.length; i++) { + if (isValidBase64Byte(data[i])) { + temp[bytesCopied++] = data[i]; + } + } + byte[] newData = new byte[bytesCopied]; + System.arraycopy(temp, 0, newData, 0, bytesCopied); + return newData; + } + + private static String discardNonBase64Chars(String data) { + StringBuffer sb = new StringBuffer(); + int length = data.length(); + for (int i = 0; i < length; i++) { + if (isValidBase64Byte((byte) (data.charAt(i)))) { + sb.append(data.charAt(i)); + } + } + return sb.toString(); + } + + private static boolean isValidBase64Byte(byte b) { + if (b == '=') { + return true; + } else if ((b < 0) || (b >= 128)) { + return false; + } else if (DECODING_TABLE[b] == -1) { + return false; + } + return true; + } + + public static byte[] compressBytes(byte input[]) { + int cachesize = 1024; + + Deflater compresser = new Deflater(); + + compresser.reset(); + compresser.setInput(input); + compresser.finish(); + byte output[] = new byte[0]; + ByteArrayOutputStream o = new ByteArrayOutputStream(input.length); + try { + byte[] buf = new byte[cachesize]; + int got; + while (!compresser.finished()) { + got = compresser.deflate(buf); + o.write(buf, 0, got); + } + output = o.toByteArray(); + } finally { + try { + o.close(); + } catch (IOException e) { + } + } + return output; + } + + public static byte[] decompressBytes(byte input[]) { + int cachesize = 1024; + Inflater decompresser = new Inflater(); + + byte output[] = new byte[0]; + decompresser.reset(); + decompresser.setInput(input); + ByteArrayOutputStream o = new ByteArrayOutputStream(input.length); + try { + byte[] buf = new byte[cachesize]; + int got; + while (!decompresser.finished()) { + got = decompresser.inflate(buf); + o.write(buf, 0, got); + } + output = o.toByteArray(); + } catch (Exception e) { + } finally { + try { + o.close(); + } catch (IOException e) { + } + } + return output; + } +} diff --git a/common/src/main/java/com/qn/utils/BeanUtil.java b/common/src/main/java/com/qn/utils/BeanUtil.java new file mode 100644 index 0000000..98e808b --- /dev/null +++ b/common/src/main/java/com/qn/utils/BeanUtil.java @@ -0,0 +1,423 @@ +package com.qn.utils; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.*; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock; + +public class BeanUtil { + + private static WriteLock lock = new ReentrantReadWriteLock().writeLock(); + + private static final Map, Map> METADATA = new HashMap<>(); + + /** + * 对象转换 + * + * @param source + * 源对象 + * @param targetClass + * 目标类 + * @return 返回一个新的目标类对象, 该目标类对象的属性值从源对象中拷贝而来 + */ + public static T convert(Object source, Class targetClass) { + T target = newInstance(targetClass); + copyProperties(source, target); + return target; + } + + /** + * 对象列表转换 + * + * @param sources + * 源对象列表 + * @param targetClass + * 目标类 + * @return 返回一个新的目标对象列表, 每个目标类对象的属性值从源对象中拷贝而来 + */ + public static List convert(Collection sources, Class targetClass) { + List targets = new ArrayList(); + if (sources != null && sources.size() > 0) { + for (Object source : sources) { + targets.add(convert(source, targetClass)); + } + } + return targets; + } + + /** + * 属性拷贝, 当且仅当两个对象的非静态属性名称相同且对应的属性类型也相同时才进行属性值拷贝 + * + * @param source + * 源对象 + * @param target + * 目标对象 + */ + public static void copyProperties(Object source, Object target) { + copyProperties(source, target, true); + } + + /** + * 属性拷贝, 当且仅当两个对象的非静态属性名称相同且对应的属性类型也相同时才进行属性值拷贝 + * + * @param source + * 源对象 + * @param target + * 目标对象 + * @param copyNullProperty + * 是否拷贝null属性值 + */ + public static void copyProperties(Object source, Object target, boolean copyNullProperty) { + if (source == null) { + return ; + } + Class sourceClass = source.getClass(); + Class targetClass = target.getClass(); + Map targetFields = getFieldsMap(targetClass, FieldType.NOT_STATIC); + Map sourceFields = getFieldsMap(sourceClass, FieldType.NOT_STATIC); + for (String name : targetFields.keySet()) { + if (sourceFields.containsKey(name)) { + Field sourceField = sourceFields.get(name); + Field targetField = targetFields.get(name); + if (targetField.getType() == sourceField.getType()) { + Object value = getPropertyValue(source, sourceField); + if (value == null && !copyNullProperty) { + continue ; + } + setPropertyValue(target, targetField, value); + } + } + } + } + + /** + * 创建类的一个实例 + * + * @param beanClass + * 类 + */ + public static T newInstance(Class beanClass) { + try { + return beanClass.newInstance(); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } + + /** + * 设置对象属性的值 + * + * @param bean + * 目标对象 + * @param field + * 属性名称 + * @param propertyValue + * 属性的值 + */ + public static void setPropertyValue(Object bean, Field field, Object propertyValue) { + try { + field.set(bean, propertyValue); + } catch (Throwable e) { + throw new RuntimeException(bean.getClass().getName() + " " + field.getName() + " " + propertyValue, e); + } + } + + /** + * 获取目标属性的值 + * + * @param bean + * 目标对象 + * @param field + * 属性名称 + * @return + */ + @SuppressWarnings("unchecked") + public static T getPropertyValue(Object bean, Field field) { + try { + return (T) field.get(bean); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } + + /** + * 设置属性的值 + * + * @param bean + * 对象或类 + * @param property + * 类属性或对象属性名称 + * @param propertyValue + * 属性的值 + */ + public static void setPropertyValue(Object bean, String property, Object propertyValue) { + if (bean != null) { + Class beanClass = null; + if (bean instanceof Class) { + beanClass = (Class) bean; + } else { + beanClass = bean.getClass(); + } + Field field = getFieldsMap(beanClass, FieldType.ALL).get(property); + if (field != null) { + setPropertyValue(bean, field, propertyValue); + } + } + } + + /** + * 获取属性的值 + * + * @param bean + * 对象或类 + * @param property + * 类属性名称或对象属性名称 + * @return + */ + public static T getPropertyValue(Object bean, String property) { + if (bean != null) { + Class beanClass = null; + if (bean instanceof Class) { + beanClass = (Class) bean; + } else { + beanClass = bean.getClass(); + } + Field field = getFieldsMap(beanClass, FieldType.ALL).get(property); + if (field != null) { + return getPropertyValue(bean, field); + } + } + return null; + } + + /** + * 获取属性的类型 + * + * @param bean + * 对象或类 + * @param property + * 类属性名称或对象属性名称 + * @return + */ + public static Class getPropertyType(Object bean, String property) { + if (bean != null) { + Class beanClass = null; + if (bean instanceof Class) { + beanClass = (Class) bean; + } else { + beanClass = bean.getClass(); + } + Field field = getFieldsMap(beanClass, FieldType.ALL).get(property); + if (field != null) { + return field.getType(); + } + } + return null; + } + + /** + * 将对象转换为散列表 + * + * @param source + * 源对象 + * @return + */ + public static Map convertMap(Object source) { + return convertMap(source, true); + } + + /** + * 将对象转换为散列表 + * + * @param source + * 源对象 + * @param convertNullProperty + * 空属性是否转换 + * @return + */ + public static Map convertMap(Object source, boolean convertNullProperty) { + Map map = new HashMap(); + if (source != null) { + Map sourceFields = getFieldsMap(source.getClass(), FieldType.NOT_STATIC); + for (String name : sourceFields.keySet()) { + Object value = getPropertyValue(source, sourceFields.get(name)); + if (value == null && !convertNullProperty) { + continue ; + } else { + map.put(name, value); + } + } + } + return map; + } + + /** + * 将list转换为 List> + * @param sources + * @param convertNullProperty + * @return + */ + public static List> convertListMap(List sources, boolean convertNullProperty) { + List> maps = new ArrayList<>(); + for (Object object : sources){ + maps.add(convertMap(object,convertNullProperty)); + } + return maps; + } + + + /** + * 获取声明的属性表 + * + * @param beanClass + * 目标类 + * @param fieldType + * 属性类型 + * @return + */ + private static Map getFieldsMap(Class beanClass, FieldType fieldType) { + Map map = getReferableFieldsMap(beanClass); + Map target = new HashMap<>(); + if (map != null && !map.isEmpty()) { + for (String name : map.keySet()) { + Field field = map.get(name); + switch (fieldType) { + case ALL: + target.put(name, field); + break; + case STATIC: + if ((field.getModifiers() & Modifier.STATIC) == Modifier.STATIC) { + target.put(name, field); + } + break; + case NOT_STATIC: + if ((field.getModifiers() & Modifier.STATIC) != Modifier.STATIC) { + target.put(name, field); + } + break; + } + } + } + return target; + } + + /** + * 获取当前类声明的属性表 + * + * @param beanClass + * 目标类 + * @return + */ + private static Map getDeclaredFieldsMap(Class beanClass) { + Field[] fields = beanClass.getDeclaredFields(); + Map map = new HashMap(); + if (fields != null && fields.length > 0) { + for (Field field : fields) { + field.setAccessible(true); + map.put(field.getName(), field); + } + } + return map; + } + + /** + * 获取声明的所有属性表 + * + * @param beanClass + * 目标类 + * @return + */ + private static Map getReferableFieldsMap(Class beanClass) { + if (!METADATA.containsKey(beanClass)) { + try { + lock.lock(); + if (!METADATA.containsKey(beanClass)) { + Map map = new HashMap<>(); + while (beanClass != null) { + map.putAll(getDeclaredFieldsMap(beanClass)); + beanClass = beanClass.getSuperclass(); + } + METADATA.put(beanClass, map); + } + } finally { + lock.unlock(); + } + } + return METADATA.get(beanClass); + } + + enum FieldType { STATIC, NOT_STATIC, ALL } + + /** + * 调用成员方法(或类方法), 该方法要求被调方法参数必须不能有基本数据类型 + * + * @param object + * 具体的对象(或类) + * @param methodName + * 对象的成员方法名称(或类的类方法名称) + * @param argValues + * 方法的参数值列表 + * @return + */ + public static E invokeMethod(Object object, String methodName, Object... argValues) { + Class[] classes = null; + if (argValues != null && argValues.length > 0) { + int length = argValues.length; + classes = new Class[length]; + for (int i = 0; i < length; i++) { + classes[i] = argValues[i].getClass(); + } + } + return invokeMethod(object, methodName, argValues, classes); + } + + /** + * 调用对象的成员方法(或类的类方法) + * + * @param object + * 具体的对象(或类) + * @param methodName + * 对象的成员方法名称(或类的类方法名称) + * @param argValues + * 方法的参数值列表 + * @param argTypes + * 方法的参数类型列表 + * @return + */ + @SuppressWarnings("unchecked") + public static E invokeMethod(Object object, String methodName, Object[] argValues, Class[] argTypes) { + try { + return (E) getAccessibleMethod(object, methodName, argTypes).invoke(object, argValues); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } + + /** + * 获取可访问的方法对象 + * + * @param object + * 具体的对象(或类) + * @param methodName + * 对象的成员方法名称(或类的类方法名称) + * @param types + * 方法的参数类型列表 + * @return + */ + private static Method getAccessibleMethod(Object object, String methodName, Class... types) { + Class entityClass = object instanceof Class ? (Class) object : object.getClass(); + while (entityClass != null) { + try { + Method target = entityClass.getDeclaredMethod(methodName, types); + target.setAccessible(true); + return target; + } catch (Throwable e) {} + entityClass = entityClass.getSuperclass(); + } + return null; + } +} + diff --git a/common/src/main/java/com/qn/utils/HTTPUtils.java b/common/src/main/java/com/qn/utils/HttpUtils.java similarity index 99% rename from common/src/main/java/com/qn/utils/HTTPUtils.java rename to common/src/main/java/com/qn/utils/HttpUtils.java index d0bf490..4235e27 100644 --- a/common/src/main/java/com/qn/utils/HTTPUtils.java +++ b/common/src/main/java/com/qn/utils/HttpUtils.java @@ -18,7 +18,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -public class HTTPUtils { +public class HttpUtils { public static String doGet(String url, Map param) { // 创建Httpclient对象 diff --git a/common/src/main/java/com/qn/utils/JacksonJsonUtil.java b/common/src/main/java/com/qn/utils/JacksonJsonUtil.java new file mode 100644 index 0000000..8bc8ee7 --- /dev/null +++ b/common/src/main/java/com/qn/utils/JacksonJsonUtil.java @@ -0,0 +1,167 @@ +package com.qn.utils; + +import org.codehaus.jackson.JsonFactory; +import org.codehaus.jackson.JsonGenerator; +import org.codehaus.jackson.JsonParser; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.map.annotate.JsonSerialize; +import org.codehaus.jackson.type.TypeReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.InputStream; +import java.io.StringWriter; +import java.util.Map; + +/** + * @Author lmqhz + */ +public class JacksonJsonUtil { + + private final static Logger errLogger = LoggerFactory.getLogger(JacksonJsonUtil.class); + private static ObjectMapper objectMapper = new ObjectMapper(); + private static JsonFactory jsonFactory = new JsonFactory(); + + static { + objectMapper.configure(SerializationConfig.Feature.WRITE_NULL_MAP_VALUES, false); + objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); + objectMapper.configure(DeserializationConfig.Feature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true); + objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); + } + + /** + * @param jsonAsString + * @param pojoClass + * @param + * @return + */ + public static T fromJson(String jsonAsString, Class pojoClass) { +// if (StringUtil.isEmpty(jsonAsString)) { +// return null; +// } + + try { + return objectMapper.readValue(jsonAsString, pojoClass); + } catch (Exception e) { + errLogger.error("fromJson error: " + jsonAsString, e); + return null; + } + + } + + public static T fromJsonByTypeRef(String jsonAsString, TypeReference typeReference) { +// if (StringUtils.isEmpty(jsonAsString)) { +// return null; +// } + try { + return objectMapper.readValue(jsonAsString, typeReference); + } catch (Exception e) { + errLogger.error("fromJson error: ", e); + return null; + } + } + + /** + * @param fr + * @param pojoClass + * @param + * @return + */ + public static T fromJson(FileReader fr, Class pojoClass) { + try { + return objectMapper.readValue(fr, pojoClass); + } catch (Exception e) { + errLogger.error("fromJson error: ", e); + return null; + } + } + + public static T fromJson(InputStream ins, Class pojoClass) { + try { + return objectMapper.readValue(ins, pojoClass); + } catch (Exception e) { + errLogger.error("fromJson error: ", e); + return null; + } + } + + public static T fromJsonByTypeRef(FileReader fr, TypeReference typeReference) { + try { + return objectMapper.readValue(fr, typeReference); + } catch (Exception e) { + errLogger.error("fromJson error: ", e); + return null; + } + } + + /** + * @param pojo + * @return + */ + public static String toJson(Object pojo) { + return toJson(pojo, false); + } + + /** + * @param pojo + * @param prettyPrint + * @return + */ + public static String toJson(Object pojo, boolean prettyPrint) { + try { + StringWriter sw = new StringWriter(); + JsonGenerator jg = jsonFactory.createJsonGenerator(sw); + if (prettyPrint) { + jg.useDefaultPrettyPrinter(); + } + objectMapper.writeValue(jg, pojo); + return sw.toString(); + } catch (Exception e) { + errLogger.error("toJson error: ", e); + return null; + } + + } + + /** + * @param pojo + * @param fw + * @param prettyPrint + */ + public static void toJson(Object pojo, FileWriter fw, boolean prettyPrint) { + try { + JsonGenerator jg = jsonFactory.createJsonGenerator(fw); + if (prettyPrint) { + jg.useDefaultPrettyPrinter(); + } + objectMapper.writeValue(jg, pojo); + } catch (Exception e) { + errLogger.error("toJson error: ", e); + return; + } + } + + /** + * @param jsonStr + * @return + */ + public static Map parseMap(String jsonStr) { + try { + Map map = objectMapper.readValue(jsonStr, Map.class); + return map; + } catch (Exception e) { + errLogger.error("parseMap error: ", e); + return null; + } + + } + + public static ObjectMapper getObjectMapper() { + return objectMapper; + } + +} diff --git a/common/src/main/java/com/qn/utils/Pager.java b/common/src/main/java/com/qn/utils/Pager.java new file mode 100644 index 0000000..e1f697f --- /dev/null +++ b/common/src/main/java/com/qn/utils/Pager.java @@ -0,0 +1,113 @@ +/** + * Alipay.com Inc. + * Copyright (c) 2004-2020 All Rights Reserved. + */ +package com.qn.utils; + +import java.util.List; + +/** + * @author jiezi + * @version $Id: Pager.java, v 0.1 2020年07月30日 19:49 jiezi Exp $ + */ +public class Pager { + /** 当前页内容 */ + private List list; + /** 当前页码 */ + private int pageIndex; + /** 每页显示数据 ,默认显示10天记录*/ + private int pageSize = 10; + /** 总记录数 */ + private long totalCount; + + private long totalPageCount; + + /** + * Constructor without args + */ + public Pager() { + super(); + } + + /** + * Constructor + * + * @param list + * @param pageIndex + * @param pageSize + * @param totalCount + */ + public Pager(List list, int pageIndex, int pageSize, long totalCount) { + super(); + this.list = list; + this.pageIndex = pageIndex; + this.pageSize = pageSize; + this.totalCount = totalCount; + resetTotalPageCount(); + } + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } + + public int getPageIndex() { + return pageIndex; + } + + public void setPageIndex(int pageIndex) { + this.pageIndex = pageIndex; + } + + public int getPageSize() { + return pageSize; + } + + public void setPageSize(int pageSize) { + this.pageSize = pageSize; + + resetTotalPageCount(); + } + + public long getTotalCount() { + return totalCount; + } + + public void setTotalCount(long totalCount) { + this.totalCount = totalCount; + resetTotalPageCount(); + } + + /** + * Getter method for property totalPageCount. + * + * @return property value of totalPageCount + */ + public long getTotalPageCount() { + return totalPageCount; + } + + /** + * Setter method for property totalPageCount. + * + * @param totalPageCount value to be assigned to property totalPageCount + */ + public void setTotalPageCount(long totalPageCount) { + this.totalPageCount = totalPageCount; + } + + private void resetTotalPageCount() { + if (pageSize > 0) { + long pageCount = totalCount / pageSize; + + if (pageCount * pageSize < totalCount) { + pageCount += 1; + } + + totalPageCount = pageCount; + } + } +} \ No newline at end of file diff --git a/common/src/main/java/com/qn/utils/Pageutils.java b/common/src/main/java/com/qn/utils/Pageutils.java new file mode 100644 index 0000000..fd4c13b --- /dev/null +++ b/common/src/main/java/com/qn/utils/Pageutils.java @@ -0,0 +1,36 @@ +package com.qn.utils; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +public class Pageutils implements Serializable { + + /** + * add by zhujt + * 自定义List分页方法 + */ + public static List startPage(List list, int pageNum, int pageSize) { + if (list == null || list.size() == 0) { + return new ArrayList(); + } + int count = list.size(); // 记录总数 + int pageCount = 0; // 页数 + if (count % pageSize == 0) { + pageCount = count / pageSize; + } else { + pageCount = count / pageSize + 1; + } + int fromIndex = 0; // 开始索引 + int toIndex = 0; // 结束索引 + if (pageNum < pageCount) { + fromIndex = (pageNum - 1) * pageSize; + toIndex = fromIndex + pageSize; + } else { + fromIndex = (pageCount - 1) * pageSize; + toIndex = count; + } + List pageList = list.subList(fromIndex, toIndex); + return pageList; + } +} \ No newline at end of file diff --git a/common/src/main/java/com/qn/utils/Pagination.java b/common/src/main/java/com/qn/utils/Pagination.java new file mode 100644 index 0000000..2e3bcd9 --- /dev/null +++ b/common/src/main/java/com/qn/utils/Pagination.java @@ -0,0 +1,86 @@ +package com.qn.utils; + +import java.io.Serializable; +import java.util.List; + +/** + * @author qinruidong + * @date 2020年6月12日 下午2:46:44 + */ +public class Pagination implements Serializable { + + private static final long serialVersionUID = -90024528L; + + public static final int DEFAULT_PAGE_SIZE = 10; + + /** + * 当前页码 + */ + private int currentPage = 0; + /** + * 分页大小 + */ + private int pageSize = 0; + /** + * 总记录数 + */ + private long count = 0; + + /** + * 分页数据列表 + */ + private List data; + + /** + * 构造函数 + */ + public Pagination() { + this(1, DEFAULT_PAGE_SIZE); + } + + /** + * 构造函数 + * + * @param page 请求的页码 + */ + public Pagination(final int page) { + this(page, DEFAULT_PAGE_SIZE); + } + + /** + * 构造函数 + * + * @param pageNo 请求的页码 + * @param pageSize 每页数量 + */ + public Pagination(final int pageNo, final int pageSize) { + // 传入的页码如果小于1则默认从第一页开始 + this.currentPage = pageNo < 1 ? 1 : pageNo; + // 传入的每页数量如果小于1则取默认的每页数量 + this.pageSize = pageSize < 1 ? DEFAULT_PAGE_SIZE : pageSize; + } + + public void setCount(long count) { + this.count = count; + } + + public long getCount() { + return count; + } + + public long getStartIndex() { + return (currentPage - 1) * pageSize; + } + + public long getPageLimit() { + return pageSize; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } +} \ No newline at end of file diff --git a/common/src/main/java/com/qn/utils/UUIDGenerator.java b/common/src/main/java/com/qn/utils/UUIDGenerator.java new file mode 100644 index 0000000..ee5eb3b --- /dev/null +++ b/common/src/main/java/com/qn/utils/UUIDGenerator.java @@ -0,0 +1,41 @@ +package com.qn.utils; + +import java.util.StringTokenizer; +import java.util.UUID; + +/** + * @title UUIDGenerator + * @description 随机生成32位UUID,格式如:a11686c39a154cf2a5238fb14cf3d097 + *
+ *
+ */ +public class UUIDGenerator { + /** + * 主键生成机制 + * @return + */ + public static String randomUUID(){ + String result=""; + UUID uuid = UUID.randomUUID(); + String temp=uuid.toString(); + StringTokenizer token=new StringTokenizer(temp,"-"); + while(token.hasMoreTokens()){ + result+=token.nextToken(); + } + return result; + } + + public static String randomUUID_16(){ + String result=""; + UUID uuid = UUID.randomUUID(); + String temp=uuid.toString(); + StringTokenizer token=new StringTokenizer(temp,"-"); + while(token.hasMoreTokens()){ + result+=token.nextToken(); + } + result = result.substring(16); + return result; + } + + +} diff --git a/pom.xml b/pom.xml index b365dd4..c1583f9 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,14 @@ dal ${version} + + + org.quartz-scheduler + quartz + 2.3.0 + + diff --git a/web/src/main/java/com/qn/controller/TestController.java b/web/src/main/java/com/qn/controller/TestController.java index aad78a6..8518bb4 100644 --- a/web/src/main/java/com/qn/controller/TestController.java +++ b/web/src/main/java/com/qn/controller/TestController.java @@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.io.IOException; @Controller @@ -30,4 +31,12 @@ public class TestController { response.flushBuffer(); } + /** + * 表白 + */ + @RequestMapping(value = "/image", method = RequestMethod.GET) + public void image() throws IOException { + File file = new File("/home/type/job"); + } + } diff --git a/web/src/main/java/com/qn/controller/WXTokenController.java b/web/src/main/java/com/qn/controller/WXTokenController.java index 78156a0..b19866f 100644 --- a/web/src/main/java/com/qn/controller/WXTokenController.java +++ b/web/src/main/java/com/qn/controller/WXTokenController.java @@ -56,7 +56,7 @@ public class WXTokenController { String msgType = map.get("MsgType"); String content = map.get("Content"); String message = null; -// HTTPUtils.doPost() +// HttpUtils.doPost() if ("text".equals(msgType)){ //回复文本信息触发的消息 message = MessageUtils.initText(toUserName,fromUserName,"text",fromUserName + "您好!" + content); diff --git a/web/src/main/java/com/qn/controller/utils/MessageUtils.java b/web/src/main/java/com/qn/controller/utils/MessageUtils.java index b587834..1bddf4a 100644 --- a/web/src/main/java/com/qn/controller/utils/MessageUtils.java +++ b/web/src/main/java/com/qn/controller/utils/MessageUtils.java @@ -1,7 +1,7 @@ package com.qn.controller.utils; import com.thoughtworks.xstream.XStream; -import model.wx.TextMessage; +import com.qn.model.wx.TextMessage; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader;