|
|
@@ -24,6 +24,8 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* 项目名: yhlxj
|
|
|
@@ -105,6 +107,22 @@ public class CommonMailServiceImpl implements CommonMailService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //Netflix get verify code
|
|
|
+ if (Constant.NETFLIX_GID.equals(goodsId) && linkType == null && (type == null || type == 1) && StrUtil.isNotBlank(emailPwd)) {
|
|
|
+ try {
|
|
|
+ String url = "https://ms.lqqq.cc/web/" + account + "----" + emailPwd;
|
|
|
+ HttpRequest post = HttpUtil.createGet(url).timeout(Constant.CONNECT_MILLISECONDS);
|
|
|
+ HttpResponse execute = post.execute();
|
|
|
+ String body = execute.body();
|
|
|
+ String code = getNetflixVerifyCodeByLqqqMail(account, emailPwd, body);
|
|
|
+ if (StrUtil.isNotBlank(code)) {
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("Netflix {} get verify code failed: {}", account, StringUtil.getErrorMsg(e));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
String checkEmail = StrUtil.isNotEmpty(relateEmail) ? relateEmail : account;
|
|
|
//关联邮箱
|
|
|
if (cuiQiuMailService.isCuiQiuEmail(checkEmail)) {
|
|
|
@@ -118,6 +136,108 @@ public class CommonMailServiceImpl implements CommonMailService {
|
|
|
return yhMailService.getVerifyCode(account, relateEmail, goodsId, type, linkType, false);
|
|
|
}
|
|
|
|
|
|
+ private String getNetflixVerifyCodeByLqqqMail(String account, String emailPwd, String body) {
|
|
|
+ if (StrUtil.isBlank(body)) {
|
|
|
+ return StrUtil.EMPTY;
|
|
|
+ }
|
|
|
+ if (!body.contains("/show_email/")) {
|
|
|
+ return getNetflixVerifyCode(body);
|
|
|
+ }
|
|
|
+ Matcher matcher = Pattern.compile("href=\"([^\"]*/show_email/[^\"]+)\"", Pattern.CASE_INSENSITIVE).matcher(body);
|
|
|
+ while (matcher.find()) {
|
|
|
+ String href = matcher.group(1);
|
|
|
+ int start = Math.max(0, matcher.start() - 800);
|
|
|
+ int end = Math.min(body.length(), matcher.end() + 200);
|
|
|
+ String emailItem = body.substring(start, end);
|
|
|
+ if (!emailItem.contains(Constant.NETFLIX) || !isNetflixLoginCodeMail(emailItem)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String detailUrl = href.startsWith("http") ? href : "https://ms.lqqq.cc" + href;
|
|
|
+ HttpResponse detailResp = HttpUtil.createGet(detailUrl).timeout(Constant.CONNECT_MILLISECONDS).execute();
|
|
|
+ String code = getNetflixVerifyCode(detailResp.body());
|
|
|
+ if (StrUtil.isNotBlank(code)) {
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("Netflix {} read mail detail failed: {}", account, StringUtil.getErrorMsg(e));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return StrUtil.EMPTY;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isNetflixLoginCodeMail(String body) {
|
|
|
+ return body.contains("\u767b\u5f55\u4ee3\u7801")
|
|
|
+ || body.contains("\u767b\u9304\u4ee3\u78bc")
|
|
|
+ || body.contains("login code")
|
|
|
+ || body.contains("c\u00f3digo de acceso")
|
|
|
+ || body.contains("c\u00f3digo para entrar")
|
|
|
+ || body.contains("\u8f93\u5165\u6b64\u4ee3\u7801\u767b\u5f55")
|
|
|
+ || body.contains("\u8f38\u5165\u6b64\u4ee3\u78bc\u767b\u5165");
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getNetflixVerifyCode(String body) {
|
|
|
+ if (StrUtil.isBlank(body)) {
|
|
|
+ return StrUtil.EMPTY;
|
|
|
+ }
|
|
|
+ String code = getNetflixCodeFromHtml(body);
|
|
|
+ if (StrUtil.isNotBlank(code)) {
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+ String[] startStrs = new String[]{
|
|
|
+ "Enter this code to sign in",
|
|
|
+ "Informe este c\u00f3digo para entrar",
|
|
|
+ "\u8f38\u5165\u6b64\u4ee3\u78bc\u767b\u5165",
|
|
|
+ "\u8f93\u5165\u6b64\u4ee3\u7801\u767b\u5f55"
|
|
|
+ };
|
|
|
+ for (String startStr : startStrs) {
|
|
|
+ if (body.contains(startStr)) {
|
|
|
+ code = cleanMailHtml(StrUtil.subAfter(body, startStr, false));
|
|
|
+ String verifyCode = getNetflixCodePattern(code);
|
|
|
+ if (StrUtil.isNotBlank(verifyCode)) {
|
|
|
+ return verifyCode;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return StrUtil.EMPTY;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getNetflixCodeFromHtml(String body) {
|
|
|
+ Matcher matcher = Pattern.compile("<td\\b[^>]*(?:font-size\\s*:\\s*28px|letter-spacing\\s*:\\s*6px)[^>]*>\\s*([0-9\\s]{4,30})\\s*</td>", Pattern.CASE_INSENSITIVE).matcher(body);
|
|
|
+ while (matcher.find()) {
|
|
|
+ String code = matcher.group(1).replaceAll("\\D", "");
|
|
|
+ if (code.length() == 4) {
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return StrUtil.EMPTY;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String cleanMailHtml(String body) {
|
|
|
+ if (StrUtil.isBlank(body)) {
|
|
|
+ return StrUtil.EMPTY;
|
|
|
+ }
|
|
|
+ return body.replaceAll("<[^>]*>", " ")
|
|
|
+ .replaceAll("(?i) ", " ")
|
|
|
+ .replaceAll("(?i)&#x?[0-9a-f]+;", " ")
|
|
|
+ .replaceAll("(?i)#[0-9a-f]{3,6}", " ");
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getNetflixCodePattern(String code) {
|
|
|
+ if (StrUtil.isBlank(code)) {
|
|
|
+ return StrUtil.EMPTY;
|
|
|
+ }
|
|
|
+ Matcher spacedMatcher = Pattern.compile("(?<!\\d)(\\d)\\D{1,8}(\\d)\\D{1,8}(\\d)\\D{1,8}(\\d)(?!\\d)").matcher(code);
|
|
|
+ while (spacedMatcher.find()) {
|
|
|
+ return spacedMatcher.group(1) + spacedMatcher.group(2) + spacedMatcher.group(3) + spacedMatcher.group(4);
|
|
|
+ }
|
|
|
+ Matcher continuousMatcher = Pattern.compile("(?<!\\d)\\d{4}(?!\\d)").matcher(code);
|
|
|
+ while (continuousMatcher.find()) {
|
|
|
+ return continuousMatcher.group();
|
|
|
+ }
|
|
|
+ return StrUtil.EMPTY;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public String getGptChangePwdLink(String email, String password) throws Exception {
|
|
|
String url = "https://ms.lqqq.cc/web/" + email + "----" + password;
|