|
|
@@ -23,6 +23,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
|
|
|
@@ -34,81 +36,202 @@ import java.util.List;
|
|
|
@RequiredArgsConstructor
|
|
|
@Slf4j
|
|
|
public class CommonMailServiceImpl implements CommonMailService {
|
|
|
- private final CuiQiuMailService cuiQiuMailService;
|
|
|
-
|
|
|
- private final MailLuService mailLuService;
|
|
|
-
|
|
|
- private final YhMailService yhMailService;
|
|
|
-
|
|
|
- @Override
|
|
|
- public String getTicketMailCode(Long goodsId, String account, String relateEmail, String emailPwd, Date emailCreatedTime, Integer type, Integer linkType, Boolean isReturnDeviceUrl) throws Exception {
|
|
|
- if (StrUtil.isEmpty(relateEmail)) {
|
|
|
- //25年的GPT账号获取验证码 特殊处理
|
|
|
- //获取失败走下一步
|
|
|
- if (goodsId == 18 && emailCreatedTime.compareTo(DateUtil.parse("2025-01-01")) > 0) {
|
|
|
- try {
|
|
|
- //获取近十封邮件
|
|
|
- String url = "https://ms.lqqq.cc/web/" + account + "----" + emailPwd;
|
|
|
- HttpRequest post = HttpUtil.createGet(url);
|
|
|
- HttpResponse execute = post.execute();
|
|
|
- String body = execute.body();
|
|
|
- if (body.contains("Your ChatGPT code is") || body.contains("Your Sora code is")) {
|
|
|
- String code = TicketCodeCommonUtil.getTicketCodeStr(body, goodsId);
|
|
|
- return code;
|
|
|
- }
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //迪士尼 获取验证码
|
|
|
- if (goodsId == Constant.DISNEY_GID) {
|
|
|
- try {
|
|
|
- String url = "https://32t.cn/api/v1/code/" + emailPwd;
|
|
|
- HttpRequest post = HttpUtil.createGet(url);
|
|
|
- HttpResponse execute = post.execute();
|
|
|
- JSONObject resp = Jsons.parseObject(execute.body(), JSONObject.class);
|
|
|
- Object data = resp.getObj("data");
|
|
|
- if (data != null) {
|
|
|
- DisneyCodeResp codeData = Jsons.parseObject(data, DisneyCodeResp.class);
|
|
|
- return codeData.getCode();
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("迪士尼 {}获取验证码失败:{}", account, StringUtil.getErrorMsg(e));
|
|
|
- }
|
|
|
- }
|
|
|
- //Adobe 获取验证码
|
|
|
- if (goodsId == Constant.ADOBE_GOODS_ID) {
|
|
|
- try {
|
|
|
- String url = "https://xinapi.adbacc.top/admin/mails?limit=20&offset=0&email=" + account;
|
|
|
- HttpRequest post = HttpUtil.createGet(url).header("x-admin-auth", "xin456");
|
|
|
- HttpResponse execute = post.execute();
|
|
|
- JSONObject resp = Jsons.parseObject(execute.body(), JSONObject.class);
|
|
|
- List<AdobeEmailResp> AdobeEmailResps = Jsons.parseList(resp.getObj("results"), AdobeEmailResp.class);
|
|
|
- if (CollUtil.isNotEmpty(AdobeEmailResps)) {
|
|
|
- for (AdobeEmailResp adobeEmailResp : AdobeEmailResps) {
|
|
|
- String str = "Your verification code is";
|
|
|
- if (StrUtil.equals(adobeEmailResp.getAddress(), account) && StrUtil.isNotBlank(adobeEmailResp.getRaw()) && adobeEmailResp.getRaw().contains(str)) {
|
|
|
- String code = StrUtil.subAfter(adobeEmailResp.getRaw(), str, false);
|
|
|
- return StringUtil.getVerifyCodePattern(code, 6);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("Adobe {}获取验证码:{}", account, StringUtil.getErrorMsg(e));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- String checkEmail = StrUtil.isNotEmpty(relateEmail) ? relateEmail : account;
|
|
|
- //关联邮箱
|
|
|
- if (cuiQiuMailService.isCuiQiuEmail(checkEmail)) {
|
|
|
- return cuiQiuMailService.getVerifyCode(account, relateEmail, goodsId, type, linkType, false);
|
|
|
- }
|
|
|
- //是否是 mail lu邮箱
|
|
|
- if (mailLuService.isMailLuEmail(checkEmail)) {
|
|
|
- return mailLuService.getVerifyCode(account, relateEmail, goodsId, type, linkType, false);
|
|
|
- }
|
|
|
- //银河域名邮件
|
|
|
- return yhMailService.getVerifyCode(account, relateEmail, goodsId, type, linkType, false);
|
|
|
- }
|
|
|
+ private final CuiQiuMailService cuiQiuMailService;
|
|
|
+
|
|
|
+ private final MailLuService mailLuService;
|
|
|
+
|
|
|
+ private final YhMailService yhMailService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getTicketMailCode(Long goodsId, String account, String relateEmail, String emailPwd, Date emailCreatedTime, Integer type, Integer linkType, Boolean isReturnDeviceUrl) throws Exception {
|
|
|
+ if (StrUtil.isEmpty(relateEmail)) {
|
|
|
+ //25年的GPT账号获取验证码 特殊处理
|
|
|
+ //获取失败走下一步
|
|
|
+ if (goodsId == 18 && emailCreatedTime.compareTo(DateUtil.parse("2025-01-01")) > 0) {
|
|
|
+ try {
|
|
|
+ //获取近十封邮件
|
|
|
+ String url = "https://ms.lqqq.cc/web/" + account + "----" + emailPwd;
|
|
|
+ HttpRequest post = HttpUtil.createGet(url);
|
|
|
+ HttpResponse execute = post.execute();
|
|
|
+ String body = execute.body();
|
|
|
+ if (body.contains("Your ChatGPT code is") || body.contains("Your Sora code is")) {
|
|
|
+ String code = TicketCodeCommonUtil.getTicketCodeStr(body, goodsId);
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //迪士尼 获取验证码
|
|
|
+ if (goodsId == Constant.DISNEY_GID) {
|
|
|
+ try {
|
|
|
+ String url = "https://32t.cn/api/v1/code/" + emailPwd;
|
|
|
+ HttpRequest post = HttpUtil.createGet(url);
|
|
|
+ HttpResponse execute = post.execute();
|
|
|
+ JSONObject resp = Jsons.parseObject(execute.body(), JSONObject.class);
|
|
|
+ Object data = resp.getObj("data");
|
|
|
+ if (data != null) {
|
|
|
+ DisneyCodeResp codeData = Jsons.parseObject(data, DisneyCodeResp.class);
|
|
|
+ return codeData.getCode();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("迪士尼 {}获取验证码失败:{}", account, StringUtil.getErrorMsg(e));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //Adobe 获取验证码
|
|
|
+ if (goodsId == Constant.ADOBE_GOODS_ID) {
|
|
|
+ try {
|
|
|
+ String url = String.format("http://www.yxiang6.com/api/GetLastEmails?email=%s&boxType=1&num=2", account);
|
|
|
+ HttpRequest post = HttpUtil.createGet(url).header("x-admin-auth", "xin456");
|
|
|
+ HttpResponse execute = post.execute();
|
|
|
+ JSONObject resp = Jsons.parseObject(execute.body(), JSONObject.class);
|
|
|
+ List<AdobeEmailResp> AdobeEmailResps = Jsons.parseList(resp.getObj("data"), AdobeEmailResp.class);
|
|
|
+ if (CollUtil.isNotEmpty(AdobeEmailResps)) {
|
|
|
+ for (AdobeEmailResp adobeEmailResp : AdobeEmailResps) {
|
|
|
+ String str = "Your verification code is";
|
|
|
+ String body = adobeEmailResp.getBody();
|
|
|
+ if (adobeEmailResp.getTo().contains(account) && StrUtil.isNotBlank(body) && body.contains(str)) {
|
|
|
+ String code = StrUtil.subAfter(body, str, false);
|
|
|
+ code = code.replaceAll("<[^>]*>", " ");
|
|
|
+ return StringUtil.getVerifyCodePattern(code, 6);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("Adobe {}获取验证码:{}", account, StringUtil.getErrorMsg(e));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //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)) {
|
|
|
+ return cuiQiuMailService.getVerifyCode(account, relateEmail, goodsId, type, linkType, false);
|
|
|
+ }
|
|
|
+ //是否是 mail lu邮箱
|
|
|
+ if (mailLuService.isMailLuEmail(checkEmail)) {
|
|
|
+ return mailLuService.getVerifyCode(account, relateEmail, goodsId, type, linkType, false);
|
|
|
+ }
|
|
|
+ //银河域名邮件
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|