zero 1 月之前
父节点
当前提交
91f4b52317

+ 20 - 10
src/main/java/com/cslg/ppa/service/GetWebArticle/GetWeChatArticleService.java

@@ -2,7 +2,9 @@ package com.cslg.ppa.service.GetWebArticle;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.cslg.ppa.common.core.base.RedisConf;
 import com.cslg.ppa.common.utils.DateUtil;
+import com.cslg.ppa.common.utils.RedisUtil;
 import com.cslg.ppa.dto.GetArticleInfoDTO;
 import com.cslg.ppa.entity.ArticleInfo;
 import com.cslg.ppa.entity.SourceInfo;
@@ -56,11 +58,6 @@ import java.util.stream.Collectors;
 @Service
 @RequiredArgsConstructor
 public class GetWeChatArticleService {
-    @Value("${WeChat.token}")
-    private String token;
-    @Value("${WeChat.cookie}")
-    private String cookie;
-
     @Autowired
     private SourceInfoMapper sourceInfoMapper;
     @Autowired
@@ -69,8 +66,14 @@ public class GetWeChatArticleService {
     private DifyService difyService;
     @Autowired
     private FileManagerService fileManagerService;
+    @Autowired
+    private RedisUtil redisUtil;
 
+//    @Scheduled(cron = "0 0 6 * * ?")
+//    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
     public void getWeChatArticle() throws Exception {
+        String token = redisUtil.get(RedisConf.WECHAT_TOKEN + RedisConf.SYMBOL_COLON);
+        String cookie = redisUtil.get(RedisConf.WECHAT_COOKIE + RedisConf.SYMBOL_COLON);
         System.out.println(new Date() + "Wechat-Begin");
         List<SourceInfo> sourceInfos = sourceInfoMapper.selectList(new LambdaQueryWrapper<SourceInfo>()
                 .eq(SourceInfo::getSourceType, 2));
@@ -102,7 +105,9 @@ public class GetWeChatArticleService {
 
                 // 检查文章是否已存在
                 long sum = articleInfoService.count(new LambdaQueryWrapper<ArticleInfo>()
-                        .eq(ArticleInfo::getTitle, title));
+                        .eq(ArticleInfo::getTitle, title)
+                        .or()
+                        .eq(ArticleInfo::getArticleUrl, link));
                 if (sum > 0) {
                     continue; // 文章已存在,跳过
                 }
@@ -110,7 +115,7 @@ public class GetWeChatArticleService {
                 //获取公众号内容
                 String weChatArticleContent = null;
                 try {
-                    weChatArticleContent = this.getWeChatArticleContent(link);
+                    weChatArticleContent = this.getWeChatArticleContent(link, cookie);
                 } catch (Exception e) {
                     weChatArticleContent = "";
                 }
@@ -135,6 +140,9 @@ public class GetWeChatArticleService {
                     case "Bayes美国知识产权公众号":
                         articleInfoDTO.setCategoryId(this.wxArticleClassify(title));
                         break;
+                    case "跨域知见公众号":
+                        articleInfoDTO.setCategoryId(12);
+                        break;
                     default:
                         articleInfoDTO.setCategoryId(6);
                         break;
@@ -156,6 +164,8 @@ public class GetWeChatArticleService {
     }
 
     public void saveWeChatArticle(String fakeId, String sourceName, Integer sourceInfoId) {
+        String token = redisUtil.get(RedisConf.WECHAT_TOKEN + RedisConf.SYMBOL_COLON);
+        String cookie = redisUtil.get(RedisConf.WECHAT_COOKIE + RedisConf.SYMBOL_COLON);
         WxResultBody<List<Article>> findExList = WeiXinApi.findExList(fakeId, token, cookie);
         List<Article> exList = findExList.getApp_msg_list();
 
@@ -192,7 +202,7 @@ public class GetWeChatArticleService {
             //获取公众号内容
             String weChatArticleContent = null;
             try {
-                weChatArticleContent = this.getWeChatArticleContent(link);
+                weChatArticleContent = this.getWeChatArticleContent(link,cookie);
             } catch (Exception e) {
                 weChatArticleContent = "";
             }
@@ -257,7 +267,7 @@ public class GetWeChatArticleService {
         return classify;
     }
 
-    public String getWeChatArticleContent(String articleUrl) {
+    public String getWeChatArticleContent(String articleUrl, String cookie) {
         String content = "";
         try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
             HttpGet request = new HttpGet(articleUrl);
@@ -337,7 +347,7 @@ public class GetWeChatArticleService {
             // 设置完整的请求头(关键步骤!)
             request.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36");
             request.setHeader("Referer", "https://mp.weixin.qq.com/");
-            request.setHeader("Cookie", cookie);
+//            request.setHeader("Cookie", cookie);
 
             //执行请求并处理响应
             try (CloseableHttpResponse response = httpClient.execute(request)) {

文件差异内容过多而无法显示
+ 0 - 3
src/main/resources/application-dev.yml


+ 2 - 2
src/test/java/com/cslg/ppa/PpaApplicationTests.java

@@ -129,11 +129,11 @@ class PpaApplicationTests {
 //        getCNIPAArticleService.saveCNIPAArticle();
 //        getCNIPAArticleService.getCNIPA();
 
-        getLocalInformationService.getLocalInformation();
+//        getLocalInformationService.getLocalInformation();
 
 //        getPCTArticleService.getPCTArticle();
 
-//        getWeChatArticleService.getWeChatArticle();
+        getWeChatArticleService.getWeChatArticle();
 
 //        final String digest = getCNIPAArticleService.getDigest("");
 //        final Date yesterdayDate = DateUtil.getYesterdayDate();