Procházet zdrojové kódy

Merge branch 'master' into pre

zoujiajian před 2 roky
rodič
revize
6dae97da2c

+ 18 - 0
netflix-common/src/main/java/com/cyksj/common/util/TicketCodeCommonUtil.java

@@ -2,6 +2,9 @@ package com.cyksj.common.util;
 
 import cn.hutool.core.util.StrUtil;
 
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 /**
  * 项目名: yhlxj2
  * 文件名: TicketCodeCommonUtil
@@ -43,4 +46,19 @@ public class TicketCodeCommonUtil {
 		}
 		return code;
 	}
+
+	public static String extractUrl(String body, String prefixUrl) {
+		String urlPattern = "(https?://\\S+)";
+		Pattern pattern = Pattern.compile(urlPattern);
+		Matcher matcher = pattern.matcher(body);
+
+		// 查找匹配的URL
+		while (matcher.find()) {
+			String url = matcher.group();
+			if (url.contains(prefixUrl)) {
+				return url.replace("\"", "");
+			}
+		}
+		return null;
+	}
 }

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/mail/CuiQiuMailService.java

@@ -11,5 +11,5 @@ public interface CuiQiuMailService {
 	/**
 	 * 获取最新邮箱 返回验证码
 	 */
-	String getVerifyCode(String email, Long goodsId) throws Exception;
+	String getVerifyCode(String email, Long goodsId, Integer type, Boolean sync) throws Exception;
 }

+ 53 - 8
netflix-service/src/main/java/com/cyksj/service/mail/impl/CuiQiuMailServiceImpl.java

@@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpResponse;
 import cn.hutool.http.HttpUtil;
+import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.util.Jsons;
 import com.cyksj.common.util.StringUtil;
 import com.cyksj.common.util.TicketCodeCommonUtil;
@@ -14,6 +15,8 @@ import com.cyksj.model.dto.CuiQiuEmailDetailDto;
 import com.cyksj.model.dto.CuiQiuEmailDto;
 import com.cyksj.model.dto.CuiQiuEmailResultDto;
 import com.cyksj.service.mail.CuiQiuMailService;
+import com.cyksj.service.relation.GroupsRelationNetflixService;
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
@@ -30,7 +33,10 @@ import java.util.stream.Collectors;
  */
 @Service
 @Slf4j
+@RequiredArgsConstructor
 public class CuiQiuMailServiceImpl implements CuiQiuMailService {
+	private final GroupsRelationNetflixService groupsRelationNetflix;
+
 	private final static String CUI_QIU_TOKEN = "4ff0341ebf1747cd89a2d1a5a296b68b";
 
 	//脆球域名id
@@ -44,8 +50,10 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
 
 	private final static String DISNEY = "Disney+";
 
+	private final static String NETFLIX = "Netflix";
+
 	@Override
-	public String getVerifyCode(String email, Long goodsId) throws Exception {
+	public String getVerifyCode(String email, Long goodsId, Integer type, Boolean sync) throws Exception {
 		//获取近二十封邮件
 		String url = "https://domain-open-api.cuiqiu.com/v1/message/list";
 
@@ -65,6 +73,9 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
 		post.form(params);
 		HttpResponse execute = post.execute();
 		CuiQiuEmailResultDto resultDto = Jsons.parseObject(execute.body(), CuiQiuEmailResultDto.class);
+		if (resultDto.getData().getList() == null) {
+			return null;
+		}
 		List<CuiQiuEmailDto> list = resultDto.getData().getList();
 		//获取邮箱对应的邮件
 		list = list.stream().filter(emailInfo -> {
@@ -79,6 +90,9 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
 				if (goodsId == 3l && StrUtil.equals(from.getName(), DISNEY)) {
 					return true;
 				}
+				if (goodsId == 1l && StrUtil.equals(from.getName(), NETFLIX)) {
+					return true;
+				}
 			}
 			return false;
 		}).collect(Collectors.toList());
@@ -87,7 +101,7 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
 			for (CuiQiuEmailDto cuiQiuEmailDto : list) {
 				Long messageId = cuiQiuEmailDto.getId();
 				try {
-					String code = getVerifyCodeByEmail(messageId, goodsId);
+					String code = getVerifyCodeByEmail(messageId, goodsId, type, sync);
 					if (StrUtil.isNotBlank(code)) {
 						return code;
 					}
@@ -98,7 +112,7 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
 		return null;
 	}
 
-	public String getVerifyCodeByEmail(Long messageId, Long goodsId) throws Exception {
+	public String getVerifyCodeByEmail(Long messageId, Long goodsId, Integer type, Boolean sync) throws Exception {
 		String url = "https://domain-open-api.cuiqiu.com/v1/message/detail";
 		Map<String, Object> params = new HashMap<>();
 		params.put("token", CUI_QIU_TOKEN);
@@ -107,12 +121,43 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
 		HttpRequest post = HttpUtil.createPost(url);
 		post.form(params);
 		HttpResponse execute = post.execute();
-		String body = execute.body();
-		CuiQiuEmailDetailDto cuiQiuEmailDetailDto = Jsons.parseObject(body, CuiQiuEmailDetailDto.class);
+		String respBody = execute.body();
+		CuiQiuEmailDetailDto cuiQiuEmailDetailDto = Jsons.parseObject(respBody, CuiQiuEmailDetailDto.class);
 		CuiQiuEmailDetailDto.Content content = cuiQiuEmailDetailDto.getData().getContent();
-
-		String contentBody = content.getBody();
-		String code = TicketCodeCommonUtil.getTicketCodeStr(contentBody, goodsId);
+		String code = null;
+		String body = content.getBody();
+		if (goodsId == 1) {
+			if (type != null && type == 1) {
+				String pre = "NetflixSans-Regular, Helvetica, Roboto, Segoe UI, sans-serif; font-weight";
+				if (body.contains("輸入此代碼登入") || body.contains("输入此代码登录")) {
+					code = StrUtil.subAfter(body, pre, false);
+				}
+				if (StrUtil.isEmpty(code)) {
+					throw BusinessRuntimeException.getInstance("查询失败,请检查是否发送了登陆码..");
+				}
+			} else {
+				String urlPref = "https://www.netflix.com/account/update-primary-location";
+				code = TicketCodeCommonUtil.extractUrl(body, urlPref);
+				if (StrUtil.isEmpty(code)) {
+					urlPref = "https://www.netflix.com/account/travel/verify";
+					code = TicketCodeCommonUtil.extractUrl(body, urlPref);
+					if (StrUtil.isEmpty(code)) {
+						throw BusinessRuntimeException.getInstance("获取认证链接失败,请重新获取");
+					}
+				}
+				String neurl = urlPref + code;
+				//非点击装置同步更新按钮 直接返回链接
+				if (!sync) return neurl;
+				//失败返回验证链接
+				if (!groupsRelationNetflix.confirmUpdate(neurl)) {
+					return url;
+				}
+				return StrUtil.EMPTY;
+			}
+		}
+		if (StrUtil.isEmpty(code)) {
+			code = TicketCodeCommonUtil.getTicketCodeStr(body, goodsId);
+		}
 		int length = 4;
 		if (goodsId == 33l) {
 			length = 6;

+ 38 - 4
netflix-service/src/main/java/com/cyksj/service/midjourney/impl/MidJourneyAccountServiceImpl.java

@@ -1,5 +1,6 @@
 package com.cyksj.service.midjourney.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.lang.UUID;
 import cn.hutool.core.map.MapUtil;
 import cn.hutool.http.HttpRequest;
@@ -26,9 +27,7 @@ import javax.imageio.stream.FileImageOutputStream;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @author zwhui
@@ -137,13 +136,48 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
             throw BusinessRuntimeException.getInstance("addAccount error message:" + jsonObject.getStr("description"));
         }
     }
-
+    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 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; AOL 9.5; AOLBuild 4337.35; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
+            "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)",
+            "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)",
+            "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)",
+            "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.0.04506.30)",
+            "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)",
+            "Mozilla/5.0 (X11; U; Linux; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6",
+            "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2pre) Gecko/20070215 K-Ninja/2.1.1",
+            "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/20080705 Firefox/3.0 Kapiko/3.0",
+            "Mozilla/5.0 (X11; Linux i686; U;) Gecko/20070322 Kazehakase/0.4.5",
+            "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6",
+            "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
+            "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.20 (KHTML, like Gecko) Chrome/19.0.1036.7 Safari/535.20",
+            "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52",
+            "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.11 TaoBrowser/2.0 Safari/536.11",
+            "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.71 Safari/537.1 LBBROWSER",
+            "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; LBBROWSER)",
+            "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E; LBBROWSER)",
+            "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.84 Safari/535.11 LBBROWSER",
+            "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)",
+            "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; QQBrowser/7.0.3698.400)",
+            "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)",
+            "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SV1; QQDownload 732; .NET4.0C; .NET4.0E; 360SE)",
+            "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)",
+            "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)",
+            "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1",
+            "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1",
+            "Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5",
+            "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:2.0b13pre) Gecko/20110307 Firefox/4.0b13pre",
+            "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0",
+            "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11",
+            "Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10");
     private Map<String, Object> createAccountParam(MidjourneyAccount midjourneyAccount) {
         Map<String, Object> param = new HashMap<>();
         param.put("channelId", midjourneyAccount.getChannelId());
         param.put("guildId", midjourneyAccount.getGuildId());
         param.put("userToken", midjourneyAccount.getUserToken());
         param.put("remark", midjourneyAccount.getId());
+        param.put("userAgent", User_Agent_LIST.get(new Random().nextInt(User_Agent_LIST.size())));
         return param;
     }
 

+ 20 - 16
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -531,7 +531,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 			throw BusinessRuntimeException.getInstance("您的车票账号密码异常,请联系客服...");
 		}
 		if (renewalView.getAccount().contains(CUI_QIU_EMAIL_SUFFIX)) {
-			return cuiQiuMailService.getVerifyCode(renewalView.getAccount(), renewalView.getGoodsId());
+			return cuiQiuMailService.getVerifyCode(renewalView.getAccount(), renewalView.getGoodsId(), type, sync);
 		}
 		//获取邮箱密码
 		SysEmail sysEmail = sysEmailMapper.selectOne(Wrappers.lambdaQuery(SysEmail.class)
@@ -761,33 +761,37 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		String code = null;
 		//奈飞
 		if (goodsId == 1) {
-			if (body.contains("輸入此代碼登入")) {
-				code = StrUtil.subBetween(body, "輸入此代碼登入", "請在裝置上輸入上");
+			if (type != null && type == 1) {
+				if (body.contains("輸入此代碼登入") || body.contains("输入此代码登录")) {
+					code = StrUtil.subBetween(body, "輸入此代碼登入", "請在裝置上輸入上");
+					if (StrUtil.isEmpty(code)) {
+						code = StrUtil.subAfter(body, "输入此代码登录", true);
+					}
+				}
+				if (StrUtil.isEmpty(code)) {
+					throw BusinessRuntimeException.getInstance("查询失败,请检查是否发送了登陆码..");
+				}
 			} else {
 				String urlPref = "https://www.netflix.com/account/update-primary-location";
 				code = StrUtil.subBetween(body, "[" + urlPref, "]");
 				if (StrUtil.isEmpty(code)) {
 					urlPref = "https://www.netflix.com/account/travel/verify";
 					code = StrUtil.subBetween(body, "[" + urlPref, "]");
-					if (StrUtil.isEmpty(code) && type == null) {
+					if (StrUtil.isEmpty(code)) {
 						throw BusinessRuntimeException.getInstance("获取认证链接失败,请重新获取");
 					}
 				}
-				if (StrUtil.isNotBlank(code)) {
-					String url = urlPref + code;
-					//非点击装置同步更新按钮 直接返回链接
-					if (!sync) return url;
-					//失败返回验证链接
-					if (!groupsRelationNetflixService.confirmUpdate(url)) {
-						return url;
-					}
-					return StrUtil.EMPTY;
+				String url = urlPref + code;
+				//非点击装置同步更新按钮 直接返回链接
+				if (!sync) return url;
+				//失败返回验证链接
+				if (!groupsRelationNetflixService.confirmUpdate(url)) {
+					return url;
 				}
-			}
-			if (type != null && type == 1 && StrUtil.isEmpty(code)) {
-				throw BusinessRuntimeException.getInstance("查询失败,请检查是否发送了登陆码..");
+				return StrUtil.EMPTY;
 			}
 		}
+		//除奈飞
 		if (StrUtil.isEmpty(code)) {
 			code = TicketCodeCommonUtil.getTicketCodeStr(body, goodsId);
 		}