From 430b18b32a3d46598da2af163b4f6b9e1b2f71ce Mon Sep 17 00:00:00 2001 From: Allen Date: Sun, 8 Sep 2019 03:34:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 +++ src/main/java/com/hotlcc/wechat4j/Wechat.java | 27 +++++++++--- .../com/hotlcc/wechat4j/util/CommonUtil.java | 41 ------------------- src/test/java/TestClass.java | 8 ++-- 4 files changed, 32 insertions(+), 50 deletions(-) delete mode 100644 src/main/java/com/hotlcc/wechat4j/util/CommonUtil.java diff --git a/pom.xml b/pom.xml index f3cf9b0..480df3b 100644 --- a/pom.xml +++ b/pom.xml @@ -85,6 +85,12 @@ lombok 1.16.20 + + + cn.hutool + hutool-all + 4.6.4 + diff --git a/src/main/java/com/hotlcc/wechat4j/Wechat.java b/src/main/java/com/hotlcc/wechat4j/Wechat.java index 9bc9296..f17c462 100644 --- a/src/main/java/com/hotlcc/wechat4j/Wechat.java +++ b/src/main/java/com/hotlcc/wechat4j/Wechat.java @@ -1,12 +1,27 @@ package com.hotlcc.wechat4j; +import cn.hutool.core.thread.ThreadUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.hotlcc.wechat4j.enums.*; +import com.hotlcc.wechat4j.enums.ExitType; +import com.hotlcc.wechat4j.enums.LoginTip; +import com.hotlcc.wechat4j.enums.MediaType; +import com.hotlcc.wechat4j.enums.MsgType; +import com.hotlcc.wechat4j.enums.Retcode; +import com.hotlcc.wechat4j.enums.Selector; import com.hotlcc.wechat4j.handler.ExitEventHandler; import com.hotlcc.wechat4j.handler.ReceivedMsgHandler; -import com.hotlcc.wechat4j.model.*; -import com.hotlcc.wechat4j.util.*; +import com.hotlcc.wechat4j.model.BaseRequest; +import com.hotlcc.wechat4j.model.MediaMessage; +import com.hotlcc.wechat4j.model.ReceivedMsg; +import com.hotlcc.wechat4j.model.UserInfo; +import com.hotlcc.wechat4j.model.WxMessage; +import com.hotlcc.wechat4j.util.FileUtil; +import com.hotlcc.wechat4j.util.PropertiesUtil; +import com.hotlcc.wechat4j.util.QRCodeUtil; +import com.hotlcc.wechat4j.util.StringUtil; +import com.hotlcc.wechat4j.util.WebWeixinApiUtil; +import com.hotlcc.wechat4j.util.WechatUtil; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; @@ -265,7 +280,7 @@ public class Wechat { pw.flush(); getWxUuid(pw, 0); - CommonUtil.threadSleep(2000); + ThreadUtil.sleep(2000); continue; } @@ -445,7 +460,7 @@ public class Wechat { pw.println(); pw.flush(); - CommonUtil.threadSleep(2000); + ThreadUtil.sleep(2000); continue; } @@ -693,7 +708,7 @@ public class Wechat { //如果时间太短则阻塞2秒 long end = System.currentTimeMillis(); if (end - start < 2000) { - CommonUtil.threadSleep(2000); + ThreadUtil.sleep(2000); } } diff --git a/src/main/java/com/hotlcc/wechat4j/util/CommonUtil.java b/src/main/java/com/hotlcc/wechat4j/util/CommonUtil.java deleted file mode 100644 index d58c961..0000000 --- a/src/main/java/com/hotlcc/wechat4j/util/CommonUtil.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.hotlcc.wechat4j.util; - -import lombok.extern.slf4j.Slf4j; - -/** - * 通用工具类 - * - * @author Allen - */ -@Slf4j -public final class CommonUtil { - private CommonUtil() { - } - - /** - * 睡眠线程 - * - * @param millis 时间 - * @param nanos nanos - */ - public static void threadSleep(long millis, int nanos) { - try { - Thread.sleep(millis, nanos); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - - /** - * 睡眠线程 - * - * @param millis 时间 - */ - public static void threadSleep(long millis) { - try { - Thread.sleep(millis); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } -} diff --git a/src/test/java/TestClass.java b/src/test/java/TestClass.java index 7519ee3..92cbdec 100644 --- a/src/test/java/TestClass.java +++ b/src/test/java/TestClass.java @@ -1,9 +1,9 @@ +import cn.hutool.core.thread.ThreadUtil; import com.alibaba.fastjson.JSONObject; import com.hotlcc.wechat4j.Wechat; import com.hotlcc.wechat4j.handler.ReceivedMsgHandler; import com.hotlcc.wechat4j.model.ReceivedMsg; import com.hotlcc.wechat4j.model.UserInfo; -import com.hotlcc.wechat4j.util.CommonUtil; import com.hotlcc.wechat4j.util.StringUtil; import org.junit.Before; import org.junit.Test; @@ -38,13 +38,15 @@ public class TestClass { public void testSendImage() { File file = null; - JSONObject result = null; + JSONObject result; file = new File("C:\\Users\\Administrator\\Pictures\\壁纸\\9e5f4981099bcf351e0ec18c3654aced.jpg"); result = wechat.sendImageToUserName(null, file); file = new File("C:\\Users\\Administrator\\Videos\\手机QQ视频_20190416170016.mp4"); result = wechat.sendVideoToUserName(null, file); System.out.println(result); - while (true) CommonUtil.threadSleep(5000); + while (true) { + ThreadUtil.sleep(5000); + } } @Test