TicketCodeCommonUtil.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package com.cyksj.common.util;
  2. import cn.hutool.core.lang.Validator;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.cyksj.common.exception.BusinessRuntimeException;
  5. import org.slf4j.Logger;
  6. import org.slf4j.LoggerFactory;
  7. import java.util.regex.Matcher;
  8. import java.util.regex.Pattern;
  9. /**
  10. * 项目名: yhlxj2
  11. * 文件名: TicketCodeCommonUtil
  12. * 创建者: JavaZou
  13. * 创建时间:2024/5/24 15:31
  14. */
  15. public class TicketCodeCommonUtil {
  16. private static final Logger LOGGER = LoggerFactory.getLogger(TicketCodeCommonUtil.class);
  17. /**
  18. * 车票邮箱验证码
  19. */
  20. public static String getTicketCodeStr(String body, Long goodsId) {
  21. if (StrUtil.isEmpty(body)) {
  22. return body;
  23. }
  24. String str = getCodeStartStr(goodsId, body);
  25. if (StrUtil.isEmpty(str)) {
  26. return null;
  27. }
  28. int index = body.indexOf(str);
  29. if (index == -1) {
  30. return null;
  31. }
  32. String code = StrUtil.subWithLength(body, index, 512);
  33. if (StrUtil.isNotBlank(code)) {
  34. code = code.replace(str, "");
  35. }
  36. int length = 4;
  37. if (goodsId == 33l || goodsId == 45l || goodsId == 18l) {
  38. length = 6;
  39. }
  40. code = StringUtil.getVerifyCodePattern(code, length);
  41. if (!Validator.isNumber(code)) {
  42. LOGGER.error("获取账号验证码失败:{}", StrUtil.subSufByLength(code, 512));
  43. throw BusinessRuntimeException.getInstance("获取验证码失败,请重新获取..");
  44. }
  45. return code.trim();
  46. }
  47. public static String extractUrl(String body, String prefixUrl) {
  48. String urlPattern = "(https?://\\S+)";
  49. Pattern pattern = Pattern.compile(urlPattern);
  50. Matcher matcher = pattern.matcher(body);
  51. // 查找匹配的URL
  52. while (matcher.find()) {
  53. String url = matcher.group();
  54. if (url.contains(prefixUrl)) {
  55. return url.replaceAll("\"", "");
  56. }
  57. }
  58. return null;
  59. }
  60. public static String getCodeStartStr(Long goodsId, String body) {
  61. String str = null;
  62. //PS、Adobe团队版全家桶
  63. if (goodsId == 33l || goodsId == 45l) {
  64. str = "color:#505050; font-family:adobe-clean, Helvetica Neue, Helvetica, Verdana, Arial, sans-serif;";
  65. if (!body.contains(str)) {
  66. str = "X-Report-Abuse: abuse@adobe.com";
  67. }
  68. }
  69. //迪士尼
  70. if (goodsId == 3l) {
  71. str = "letter-spacing:4px; line-height:38px; mso-line-height-rule: exactly";
  72. if (!body.contains(str)) {
  73. str = "Noto Sans Display', Helvetica, Arial, sans-serif; font-weight: 600;text-align: center;";
  74. if (!body.contains(str)) {
  75. str = "使用此密码验证 MyDisney 帐户关联的电子邮件地址。此密码将在 15 分钟后过期";
  76. }
  77. }
  78. }
  79. //GPT PLUS
  80. if (goodsId == 18l) {
  81. str = "X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-80345.templateTenant";
  82. }
  83. return str;
  84. }
  85. }