Browse Source

新增收费ip

chenbiao 3 năm trước cách đây
mục cha
commit
19b7784a49

+ 5 - 0
netflix-common/src/main/java/com/cyksj/dto/RedisKey.java

@@ -43,4 +43,9 @@ public class RedisKey {
      */
      */
     public static String SPOTIFY_FREE_NUM = "register:free:spotify";
     public static String SPOTIFY_FREE_NUM = "register:free:spotify";
 
 
+    /**
+     * 付费ip
+     */
+    public static String DOVEIP = "dove_ip";
+
 }
 }

+ 37 - 4
netflix-service/src/main/java/com/cyksj/service/register/impl/SpotifyServiceImpl.java

@@ -11,6 +11,7 @@ import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.cyksj.dto.RedisKey;
 import com.cyksj.dto.Result;
 import com.cyksj.dto.Result;
 import com.cyksj.enums.GatewayResponse;
 import com.cyksj.enums.GatewayResponse;
 import com.cyksj.mapper.ProxysMapper;
 import com.cyksj.mapper.ProxysMapper;
@@ -19,6 +20,7 @@ import com.cyksj.model.entity.Proxys;
 import com.cyksj.model.entity.RegisterOrderDon;
 import com.cyksj.model.entity.RegisterOrderDon;
 import com.cyksj.model.entity.SpotifyRegister;
 import com.cyksj.model.entity.SpotifyRegister;
 import com.cyksj.model.response.ProxyInfo;
 import com.cyksj.model.response.ProxyInfo;
+import com.cyksj.redis.RedisService;
 import com.cyksj.service.register.SpotifyService;
 import com.cyksj.service.register.SpotifyService;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
@@ -43,6 +45,8 @@ public class SpotifyServiceImpl implements SpotifyService {
 
 
     private final RegisterOrderDonMapper registerOrderDonMapper;
     private final RegisterOrderDonMapper registerOrderDonMapper;
 
 
+    private final RedisService redisService;
+
     private static final List<String> User_Agent_LIST =  List.of(
     private static final List<String> User_Agent_LIST =  List.of(
             "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
             "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
             "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)",
             "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)",
@@ -114,9 +118,6 @@ public class SpotifyServiceImpl implements SpotifyService {
         request.form(jsonObject);
         request.form(jsonObject);
 
 
 
 
-
-
-
         int start = 1;
         int start = 1;
         int limit = 20;
         int limit = 20;
         boolean regFlag = false;
         boolean regFlag = false;
@@ -125,7 +126,39 @@ public class SpotifyServiceImpl implements SpotifyService {
             List<ProxyInfo> proxyInfos = new ArrayList<>();
             List<ProxyInfo> proxyInfos = new ArrayList<>();
             List<Proxys> records = proxysMapper.selectPage(new Page<>(start, limit), Wrappers.lambdaQuery(Proxys.class).orderByDesc(Proxys::getId)).getRecords();
             List<Proxys> records = proxysMapper.selectPage(new Page<>(start, limit), Wrappers.lambdaQuery(Proxys.class).orderByDesc(Proxys::getId)).getRecords();
             if (records.isEmpty()) {
             if (records.isEmpty()) {
-                break;
+                log.info("----------代理池内无可用ip 获取付费IP地址----------");
+                ProxyInfo proxyInfo = (ProxyInfo)redisService.get(RedisKey.DOVEIP);
+                if (proxyInfo == null) {
+
+                    String result = HttpUtil.get("https://dvapi.doveip.com/cmapi.php?rq=distribute&user=1031494735&token=ckc1MUFURnk3bi80MXVxeUFTZUh0Zz09&auth=0&geo=ph&agreement=0&timeout=10&num=1&type_ip=1");
+                    log.info("付费ip 请求返回 res:{}",result);
+                    /*
+                     * {
+                     *   "errno": 200,
+                     *   "msg": "Success",
+                     *   "data": {
+                     *     "geo": "mx", //国家
+                     *     "ip": "47.253.12.97", //代理ip
+                     *     "port": 40076, //代理端口
+                     *     "d_ip": "201.162.169.86" //目标ip
+                     *     "timeout": 600 //有效时间(秒)
+                     *   }
+                     * }
+                     */
+                    JSONObject resObj = JSONUtil.parseObj(result);
+                    if (200 == resObj.getInt("errno")) {
+                        JSONObject data = resObj.getJSONObject("data");
+                        ProxyInfo proxy = new ProxyInfo();
+                        proxy.setPort(data.getInt("port"));
+                        proxy.setIp(data.getStr("ip"));
+                        log.info("----------付费IP地址----------\n ip:{}",proxy);
+                        proxyInfos.add(proxy);
+                        redisService.set(RedisKey.DOVEIP,proxy,data.getLong("timeout"));
+                    }else {
+                        log.error("----------获取 付费IP 错误 停止循环----------");
+                        break;
+                    }
+                }
             }
             }
             proxyInfos = records.stream().map((proxy) -> {
             proxyInfos = records.stream().map((proxy) -> {
                 ProxyInfo proxyInfo = new ProxyInfo();
                 ProxyInfo proxyInfo = new ProxyInfo();

+ 9 - 7
netflix-service/src/main/java/com/cyksj/task/Scheduler.java

@@ -169,13 +169,15 @@ public class Scheduler {
      */
      */
     @Scheduled(cron = "0 0/5 * * * ?")
     @Scheduled(cron = "0 0/5 * * * ?")
     public void spotify() {
     public void spotify() {
-        List<RegisterOrderDon> spotify = registerOrderDonMapper.selectList(Wrappers.lambdaQuery(RegisterOrderDon.class)
-                .select(RegisterOrderDon::getId)
-                .eq(RegisterOrderDon::getPlatform, "spotify")
-                .eq(RegisterOrderDon::getStatus, RegisterOrderDon.Status.hasPayment));
-        spotify.forEach((orderDon)->{
-            spotifyService.register(orderDon.getId());
-        });
+        synchronized (this){
+            List<RegisterOrderDon> spotify = registerOrderDonMapper.selectList(Wrappers.lambdaQuery(RegisterOrderDon.class)
+                    .select(RegisterOrderDon::getId)
+                    .eq(RegisterOrderDon::getPlatform, "spotify")
+                    .eq(RegisterOrderDon::getStatus, RegisterOrderDon.Status.hasPayment));
+            spotify.forEach((orderDon)->{
+                spotifyService.register(orderDon.getId());
+            });
+        }
     }
     }
 
 
     /**
     /**