Kaynağa Gözat

从采购系统获取微信token

3254194295 8 ay önce
ebeveyn
işleme
6c5c12a295

+ 2 - 1
platform-service/src/main/java/com/platform/service/event/EventListenerBean.java

@@ -20,6 +20,7 @@ import org.springframework.context.event.EventListener;
 import org.springframework.core.annotation.Order;
 import org.springframework.scheduling.annotation.Async;
 
+import java.io.IOException;
 import java.time.LocalDateTime;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -101,7 +102,7 @@ public class EventListenerBean {
     @Async
     @Order
     @EventListener(WechatEvent.class)
-    public void sendWechatEvent(WechatEvent event) {
+    public void sendWechatEvent(WechatEvent event) throws IOException {
         log.info("微信通知事件执行");
         WeChatConnectService.postTemplate((WechatTemplateRequest) event.getSource());
     }

+ 13 - 6
platform-service/src/main/java/com/platform/service/wechat/service/WeChatConnectService.java

@@ -8,10 +8,7 @@ import com.platform.common.constant.CommonConstants;
 import com.platform.common.constant.RedisKeyConstants;
 import com.platform.common.enums.DictTypeEnum;
 import com.platform.common.exception.BusinessException;
-import com.platform.common.util.HttpUtil;
-import com.platform.common.util.RedisUtils;
-import com.platform.common.util.ShaUtil;
-import com.platform.common.util.StringUtils;
+import com.platform.common.util.*;
 import com.platform.dao.entity.upms.SysUser;
 import com.platform.service.wechat.model.request.template.WechatTemplateRequest;
 import com.platform.service.wechat.model.request.token.WechatTicketToken;
@@ -177,6 +174,10 @@ public class WeChatConnectService {
         return null;
     }
 
+    public static void main(String[] args) throws IOException {
+        postTemplate(new WechatTemplateRequest());
+    }
+
     /***
      * 发送模版消息
      *
@@ -184,9 +185,15 @@ public class WeChatConnectService {
      *            请求json数据
      * @return 返回消息 WechatTemplateResponse
      */
-    public static WechatTemplateResponse postTemplate(WechatTemplateRequest request) {
+    public static WechatTemplateResponse postTemplate(WechatTemplateRequest request) throws IOException {
         log.info("获取微信token");
-        String token = getToken();
+        String resp = HttpUtil.get("http://buy.catlsc.com:6688/api/common/wechat/token/sb");
+        JSONObject jsonObject = JSONObject.parseObject(resp);
+        log.info("获取token返回数据:"+jsonObject);
+        if (Integer.parseInt(jsonObject.get("code").toString())!=0){
+            throw new BusinessException("token获取失败!");
+        }
+        String token = jsonObject.get("data").toString();
         if(StringUtils.isBlank(token)){
             log.info("发送模板消息时,获取token失败");
         }