lvzhiqiang 2 年之前
父节点
当前提交
21ef7b1a9a

+ 3 - 0
src/main/java/top/lvzhiqiang/config/WorkWeixinAutoConfiguration.java

@@ -1,5 +1,8 @@
 package top.lvzhiqiang.config;
 
+import me.chanjar.weixin.cp.api.WxCpService;
+import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
+import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;

+ 11 - 11
src/main/java/top/lvzhiqiang/service/impl/CoinServiceImpl.java

@@ -3,6 +3,10 @@ package top.lvzhiqiang.service.impl;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.cp.api.WxCpService;
+import me.chanjar.weixin.cp.bean.message.WxCpMessage;
+import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
 import org.jsoup.Connection;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
@@ -49,7 +53,7 @@ public class CoinServiceImpl implements CoinService {
     @Resource
     private CoinMapper coinMapper;
 
-    @Autowired(required = false)
+    @Resource
     private WxCpService wxCpService;
     @Autowired(required = false)
     private WorkWeixinProperties properties;
@@ -91,7 +95,7 @@ public class CoinServiceImpl implements CoinService {
 
 
     @Override
-    //@Async("coinTaskExecutor")
+    @Async("coinTaskExecutor")
     public String monitorJob() {
         Timer timer = new Timer();
         timer.scheduleAtFixedRate(new TimerTask() {
@@ -121,12 +125,6 @@ public class CoinServiceImpl implements CoinService {
             }
         }, 0, 2000);
 
-        try {
-            Thread.sleep(100000);
-        } catch (InterruptedException e) {
-            throw new RuntimeException(e);
-        }
-
         return null;
     }
 
@@ -146,9 +144,11 @@ public class CoinServiceImpl implements CoinService {
                 .url(logUrl).btnTxt(btnTxt)
                 .build();
         try {
+            log.info("企业微信推送消息,send message: {}", wxCpMessage);
             WxCpMessageSendResult sendResult = wxCpService.getMessageService().send(wxCpMessage);
-            System.out.println(sendResult);
+            log.info("企业微信推送消息成功,send result: {}", sendResult);
         } catch (WxErrorException e) {
+            log.error("企业微信推送消息失败!Detail: ", e);
         }
     }
 
@@ -174,8 +174,8 @@ public class CoinServiceImpl implements CoinService {
 
         try {
             String requestUrl = mainUrl + requestPath;
-            Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 1080));
-            //Proxy proxy = Proxy.NO_PROXY;
+            //Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 1080));
+            Proxy proxy = Proxy.NO_PROXY;
             Connection.Response response = JsoupUtil.requestBody(requestUrl, httpMethod, proxy, headerMap, paramMap);
 
             return JSONObject.parseObject(response.body());

+ 8 - 0
src/test/java/top/lvzhiqiang/TestCoin.java

@@ -1,5 +1,6 @@
 package top.lvzhiqiang;
 
+import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -41,4 +42,11 @@ public class TestCoin {
     public void testMonitorJob() {
         coinService.monitorJob();
     }
+
+    @Test
+    public void testMonitorAlarm() {
+        JSONObject jo = new JSONObject();
+        jo.put("symbol", "aaa");
+        coinService.monitorAlarm(jo);
+    }
 }