YhEmailServiceImpl.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package com.cyksj.service.mail.impl;
  2. import cn.hutool.core.lang.Validator;
  3. import cn.hutool.core.util.StrUtil;
  4. import cn.hutool.http.HttpRequest;
  5. import cn.hutool.http.HttpStatus;
  6. import cn.hutool.http.HttpUtil;
  7. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  8. import com.cyksj.common.exception.BusinessRuntimeException;
  9. import com.cyksj.common.util.StringUtil;
  10. import com.cyksj.common.util.TicketCodeCommonUtil;
  11. import com.cyksj.mapper.sys.SysEmailMapper;
  12. import com.cyksj.model.entity.SysEmail;
  13. import com.cyksj.service.mail.YhMailService;
  14. import com.cyksj.service.relation.GroupsRelationNetflixService;
  15. import lombok.RequiredArgsConstructor;
  16. import lombok.extern.slf4j.Slf4j;
  17. import org.springframework.stereotype.Service;
  18. import java.util.HashMap;
  19. import java.util.Map;
  20. /**
  21. * 项目名: yhlxj2
  22. * 文件名: YhEmailServiceImpl
  23. * 创建者: JavaZou
  24. * 创建时间:2024/8/19 15:40
  25. */
  26. @Service
  27. @RequiredArgsConstructor
  28. @Slf4j
  29. public class YhEmailServiceImpl implements YhMailService {
  30. private final GroupsRelationNetflixService groupsRelationNetflixService;
  31. private final SysEmailMapper sysEmailMapper;
  32. @Override
  33. public String getVerifyCode(String account, Long goodsId, Integer type, Integer linkType) throws Exception {
  34. //获取邮箱密码
  35. SysEmail sysEmail = sysEmailMapper.selectOne(Wrappers.lambdaQuery(SysEmail.class)
  36. .eq(SysEmail::getEmail, account)
  37. .last("limit 1"));
  38. if (sysEmail == null) {
  39. log.info("获取账号:{}验证码异常,未配置对应系统邮箱", account);
  40. throw BusinessRuntimeException.getInstance("获取账号验证码异常,请联系客服...");
  41. }
  42. String url = "http://yinhelx.com/api/controller.php";
  43. Map<String, Object> params = new HashMap<>();
  44. params.put("imap_key", "imap_56568niua@@");
  45. params.put("fun", "imap_read");
  46. params.put("imap_ip", "yinhelx.com");
  47. params.put("port", "143");
  48. params.put("username", account);
  49. params.put("password", sysEmail.getPassword());
  50. params.put("mbox_id", "0");
  51. params.put("delete", "0");
  52. HttpRequest post = HttpUtil.createPost(url);
  53. post.form(params);
  54. cn.hutool.http.HttpResponse execute = post.execute();
  55. if (execute.getStatus() != HttpStatus.HTTP_OK) {
  56. throw BusinessRuntimeException.getInstance("获取验证码异常,请联系客服...");
  57. }
  58. String code = getDifferentGoodsCode(goodsId, execute.body(), type, linkType);
  59. return code;
  60. }
  61. public String getDifferentGoodsCode(Long goodsId, String body, Integer type, Integer linkType) {
  62. String code = null;
  63. //奈飞
  64. if (goodsId == 1) {
  65. if (type != null && type == 1) {
  66. if (body.contains("輸入此代碼登入") || body.contains("输入此代码登录") || body.contains("Enter this code to sign in")) {
  67. code = StrUtil.subBetween(body, "輸入此代碼登入", "請在裝置上輸入上");
  68. if (StrUtil.isEmpty(code)) {
  69. code = StrUtil.subAfter(body, "输入此代码登录", true);
  70. }
  71. if (StrUtil.isEmpty(code)) {
  72. code = StrUtil.subAfter(body, "Enter this code to sign in", true);
  73. }
  74. }
  75. if (StrUtil.isEmpty(code)) {
  76. throw BusinessRuntimeException.getInstance("查询失败,请检查是否发送了登陆码..");
  77. }
  78. } else {
  79. String urlPref;
  80. //更新装置
  81. if (linkType == 1) {
  82. urlPref = "https://www.netflix.com/account/update-primary-location";
  83. code = StrUtil.subBetween(body, "[" + urlPref, "]");
  84. } else {
  85. //验证链接
  86. urlPref = "https://www.netflix.com/account/travel/verify";
  87. code = StrUtil.subBetween(body, "[" + urlPref, "]");
  88. }
  89. if (StrUtil.isEmpty(code)) {
  90. throw BusinessRuntimeException.getInstance("获取认证链接失败,请重新获取");
  91. }
  92. String url = urlPref + code;
  93. //非点击装置同步更新按钮 直接返回链接
  94. if (linkType == 2) return url;
  95. //失败返回验证链接
  96. if (!groupsRelationNetflixService.confirmUpdate(url)) {
  97. return url;
  98. }
  99. return StrUtil.EMPTY;
  100. }
  101. }
  102. //除奈飞
  103. if (StrUtil.isEmpty(code)) {
  104. code = TicketCodeCommonUtil.getTicketCodeStr(body, goodsId);
  105. }
  106. int length = 4;
  107. if (goodsId == 33l) {
  108. length = 6;
  109. }
  110. code = StringUtil.getVerifyCodePattern(code, length);
  111. if (!Validator.isNumber(code)) {
  112. log.error("获取账号验证码失败:{}", StrUtil.subSufByLength(code, 512));
  113. throw BusinessRuntimeException.getInstance("获取验证码失败,请重新获取..");
  114. }
  115. return code.trim();
  116. }
  117. }