Browse Source

脆球兼容奈飞验证码

zoujiajian 2 năm trước cách đây
mục cha
commit
e903849c6b

+ 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.replaceAll("\"", "");
+			}
+		}
+		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;
 }

+ 52 - 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,42 @@ 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";
+				String nfVerifyUrl = TicketCodeCommonUtil.extractUrl(body, urlPref);
+				if (StrUtil.isEmpty(nfVerifyUrl)) {
+					urlPref = "https://www.netflix.com/account/travel/verify";
+					nfVerifyUrl = TicketCodeCommonUtil.extractUrl(body, urlPref);
+					if (StrUtil.isEmpty(nfVerifyUrl)) {
+						throw BusinessRuntimeException.getInstance("获取认证链接失败,请重新获取");
+					}
+				}
+				//非点击装置同步更新按钮 直接返回链接
+				if (!sync) return nfVerifyUrl;
+				//失败返回验证链接
+				if (!groupsRelationNetflix.confirmUpdate(nfVerifyUrl)) {
+					return nfVerifyUrl;
+				}
+				return StrUtil.EMPTY;
+			}
+		}
+		if (StrUtil.isEmpty(code)) {
+			code = TicketCodeCommonUtil.getTicketCodeStr(body, goodsId);
+		}
 		int length = 4;
 		if (goodsId == 33l) {
 			length = 6;

+ 18 - 17
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -515,7 +515,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)
@@ -745,10 +745,15 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		String code = null;
 		//奈飞
 		if (goodsId == 1) {
-			if (body.contains("輸入此代碼登入") || 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)) {
-					code = StrUtil.subAfter(body, "输入此代码登录", true);
+					throw BusinessRuntimeException.getInstance("查询失败,请检查是否发送了登陆码..");
 				}
 			} else {
 				String urlPref = "https://www.netflix.com/account/update-primary-location";
@@ -756,25 +761,21 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 				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);
 		}