|
@@ -2,6 +2,7 @@ package com.cyksj.common.util;
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.Validator;
|
|
import cn.hutool.core.lang.Validator;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import cn.hutool.http.HtmlUtil;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -18,6 +19,15 @@ import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
public class TicketCodeCommonUtil {
|
|
public class TicketCodeCommonUtil {
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TicketCodeCommonUtil.class);
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TicketCodeCommonUtil.class);
|
|
|
|
|
+
|
|
|
|
|
+ private static final Pattern GPT_VERIFY_CODE_PATTERN = Pattern.compile(
|
|
|
|
|
+ "(?:Enter\\s+this\\s+temporary\\s+verification\\s+code(?:\\s+to\\s+continue)?"
|
|
|
|
|
+ + "|Your\\s+(?:ChatGPT|Sora)\\s+code\\s+is"
|
|
|
|
|
+ + "|输入\\s*此\\s*临时\\s*验证码\\s*以\\s*继续"
|
|
|
|
|
+ + "|輸入\\s*此\\s*臨時\\s*驗證碼\\s*以\\s*繼續)"
|
|
|
|
|
+ + "\\s*[::]?\\s*(?<!\\d)((?:\\d\\s*){6})(?!\\s*\\d)",
|
|
|
|
|
+ Pattern.CASE_INSENSITIVE);
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 车票邮箱验证码
|
|
* 车票邮箱验证码
|
|
|
*/
|
|
*/
|
|
@@ -25,6 +35,9 @@ public class TicketCodeCommonUtil {
|
|
|
if (StrUtil.isEmpty(body)) {
|
|
if (StrUtil.isEmpty(body)) {
|
|
|
return body;
|
|
return body;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (Long.valueOf(18L).equals(goodsId)) {
|
|
|
|
|
+ return getGptVerifyCode(body);
|
|
|
|
|
+ }
|
|
|
String str = getCodeStartStr(goodsId, body);
|
|
String str = getCodeStartStr(goodsId, body);
|
|
|
if (StrUtil.isEmpty(str)) {
|
|
if (StrUtil.isEmpty(str)) {
|
|
|
return null;
|
|
return null;
|
|
@@ -49,6 +62,23 @@ public class TicketCodeCommonUtil {
|
|
|
return code.trim();
|
|
return code.trim();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取 GPT/Sora 登录验证码。将 HTML 邮件转为纯文本后,
|
|
|
|
|
+ * 按正文出现顺序返回第一个符合明确登录提示语的六位验证码。
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String getGptVerifyCode(String body) {
|
|
|
|
|
+ if (StrUtil.isBlank(body)) {
|
|
|
|
|
+ return StrUtil.EMPTY;
|
|
|
|
|
+ }
|
|
|
|
|
+ String text = HtmlUtil.unescape(body)
|
|
|
|
|
+ .replaceAll("(?is)<(?:script|style)\\b[^>]*>.*?</(?:script|style)>", " ")
|
|
|
|
|
+ .replaceAll("(?s)<[^>]+>", " ")
|
|
|
|
|
+ .replace('\u00a0', ' ')
|
|
|
|
|
+ .replaceAll("\\s+", " ");
|
|
|
|
|
+ Matcher matcher = GPT_VERIFY_CODE_PATTERN.matcher(text);
|
|
|
|
|
+ return matcher.find() ? matcher.group(1).replaceAll("\\s", "") : StrUtil.EMPTY;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static String extractUrl(String body, String prefixUrl) {
|
|
public static String extractUrl(String body, String prefixUrl) {
|
|
|
String urlPattern = "(https?://\\S+)";
|
|
String urlPattern = "(https?://\\S+)";
|
|
|
Pattern pattern = Pattern.compile(urlPattern);
|
|
Pattern pattern = Pattern.compile(urlPattern);
|