Jelajahi Sumber

Merge branch 'dev-xym-update-proxy1' of Server/long-article-manage into master

xueyiming 4 bulan lalu
induk
melakukan
ef87dde1c0

+ 4 - 1
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/LongArticleServerApplication.java

@@ -7,6 +7,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
 import java.net.Authenticator;
 import java.net.PasswordAuthentication;
 
+import static com.tzld.piaoquan.longarticle.common.constants.ProxyConstant.PASSWORD;
+import static com.tzld.piaoquan.longarticle.common.constants.ProxyConstant.USERNAME;
+
 @EnableApolloConfig
 @SpringBootApplication
 public class LongArticleServerApplication {
@@ -17,7 +20,7 @@ public class LongArticleServerApplication {
                 new Authenticator() {
                     public PasswordAuthentication getPasswordAuthentication() {
                         return new PasswordAuthentication(
-                                "t17772369458618", "5zqcjkmy".toCharArray());
+                                USERNAME, PASSWORD.toCharArray());
                     }
                 }
         );

+ 9 - 0
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/common/constants/ProxyConstant.java

@@ -0,0 +1,9 @@
+package com.tzld.piaoquan.longarticle.common.constants;
+
+public interface ProxyConstant {
+
+    String PROXY_HOST = "j685.kdltps.com";
+    int PROXY_PORT = 15818;
+    String USERNAME = "t14070979713487";
+    String PASSWORD = "hqwanfvy";
+}

+ 23 - 0
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/controller/IndexController.java

@@ -1,12 +1,19 @@
 package com.tzld.piaoquan.longarticle.controller;
 
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
 import com.tzld.piaoquan.longarticle.service.local.impl.MatchVideoServiceImpl;
+import lombok.extern.slf4j.Slf4j;
 import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import static com.tzld.piaoquan.longarticle.common.constants.ProxyConstant.PROXY_HOST;
+import static com.tzld.piaoquan.longarticle.common.constants.ProxyConstant.PROXY_PORT;
+
+@Slf4j
 @RestController
 @RequestMapping("/")
 public class IndexController {
@@ -22,4 +29,20 @@ public class IndexController {
     }
 
 
+    @GetMapping("/test")
+    public String test() {
+
+        // 目标网站
+        String url = "https://www.baidu.com";
+
+        // 发送请求
+        HttpResponse result = HttpRequest.get(url)
+                .setHttpProxy(PROXY_HOST, PROXY_PORT)
+                .timeout(20000)//设置超时,毫秒
+                .execute();
+        log.info("test={}", result.body());
+        return "ok";
+    }
+
+
 }

+ 22 - 0
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/job/MatchVideoJob.java

@@ -1,5 +1,7 @@
 package com.tzld.piaoquan.longarticle.job;
 
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
 import com.tzld.piaoquan.longarticle.service.local.impl.MatchVideoServiceImpl;
 import com.tzld.piaoquan.longarticle.utils.LarkRobotUtil;
 import com.xxl.job.core.biz.model.ReturnT;
@@ -8,6 +10,11 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.net.Authenticator;
+
+import static com.tzld.piaoquan.longarticle.common.constants.ProxyConstant.PROXY_HOST;
+import static com.tzld.piaoquan.longarticle.common.constants.ProxyConstant.PROXY_PORT;
+
 @Slf4j
 @Component
 public class MatchVideoJob {
@@ -60,4 +67,19 @@ public class MatchVideoJob {
         }
         return ReturnT.SUCCESS;
     }
+
+
+    @XxlJob("testJob")
+    public ReturnT<String> testJob(String param) {
+        // 目标网站
+        String url = "https://www.baidu.com";
+
+        // 发送请求
+        HttpResponse result = HttpRequest.get(url)
+                .setHttpProxy(PROXY_HOST, PROXY_PORT)
+                .timeout(20000)//设置超时,毫秒
+                .execute();
+        log.info("test={}", result.body());
+        return ReturnT.SUCCESS;
+    }
 }

+ 0 - 9
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/job/PlanAccountJob.java

@@ -9,8 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
-import static com.tzld.piaoquan.longarticle.common.constants.RedisConstant.REDIS_COOKIE_KEY;
-
 @Slf4j
 @Component
 public class PlanAccountJob {
@@ -76,11 +74,4 @@ public class PlanAccountJob {
         }
         return ReturnT.SUCCESS;
     }
-
-    @XxlJob("updateCookieJob")
-    public ReturnT<String> updateCookie(String param) {
-        redisTemplate.opsForValue().set(REDIS_COOKIE_KEY, param);
-        return ReturnT.SUCCESS;
-    }
-
 }

+ 5 - 3
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/utils/other/HkspSearch.java

@@ -15,6 +15,8 @@ import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.*;
 
+import static com.tzld.piaoquan.longarticle.common.constants.ProxyConstant.*;
+
 @Slf4j
 public class HkspSearch {
 
@@ -43,7 +45,7 @@ public class HkspSearch {
                 new Authenticator() {
                     public PasswordAuthentication getPasswordAuthentication() {
                         return new PasswordAuthentication(
-                                "t17772369458618", "5zqcjkmy".toCharArray());
+                                USERNAME, PASSWORD.toCharArray());
                     }
                 }
         );
@@ -82,7 +84,7 @@ public class HkspSearch {
                     .header("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36")
                     .header("x-requested-with", "xmlhttprequest")
                     .timeout(120000) // 设置超时时间
-                    .setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("q796.kdltps.com", 15818)))
+                    .setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXY_HOST, PROXY_PORT)))
                     .form(params)
                     .execute();
 
@@ -162,7 +164,7 @@ public class HkspSearch {
                 .header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36")
                 .timeout(120000) // 设置超时时间
                 .form(params)
-                .setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("q796.kdltps.com", 15818)))
+                .setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXY_HOST, PROXY_PORT)))
                 .execute();
         return JSONObject.parseObject(response.body()).getJSONObject("data").getJSONObject("apiData").getJSONObject("curVideoMeta");
     }

+ 6 - 12
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/utils/other/VideoDownloader.java

@@ -1,31 +1,25 @@
 package com.tzld.piaoquan.longarticle.utils.other;
 
-import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.tzld.piaoquan.longarticle.utils.ConfigUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.message.BasicHeader;
 import org.springframework.util.CollectionUtils;
 
-import java.io.*;
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.*;
 import java.nio.file.Files;
 import java.util.Objects;
 import java.util.UUID;
 
+import static com.tzld.piaoquan.longarticle.common.constants.ProxyConstant.*;
+
 @Slf4j
 public class VideoDownloader {
 
-    private static final String PROXY_HOST = "q796.kdltps.com";
-    private static final int PROXY_PORT = 15818;
-    private static final String USERNAME = "t17772369458618";
-    private static final String PASSWORD = "5zqcjkmy";
     private static final int MAX_RETRIES = 3;
 
     public static String downloadCover(String outVideoId, String platform, String coverUrl) {
@@ -146,7 +140,7 @@ public class VideoDownloader {
                 new Authenticator() {
                     public PasswordAuthentication getPasswordAuthentication() {
                         return new PasswordAuthentication(
-                                "t17772369458618", "5zqcjkmy".toCharArray());
+                                USERNAME, PASSWORD.toCharArray());
                     }
                 }
         );