Переглянути джерело

银河惯例后台奈飞同步装置按钮

zoujiajian 2 роки тому
батько
коміт
af6eeab9fc

+ 1 - 2
netflix-service/src/main/java/com/cyksj/redis/RedisService.java

@@ -3,12 +3,10 @@ package com.cyksj.redis;
 import com.cyksj.common.util.StringUtil;
 import lombok.AllArgsConstructor;
 import lombok.Getter;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.core.ZSetOperations;
 import org.springframework.stereotype.Service;
 
-import javax.annotation.PostConstruct;
 import javax.annotation.Resource;
 import java.util.Arrays;
 import java.util.List;
@@ -843,6 +841,7 @@ public class RedisService {
         NETFLIX_SET_LIMIT_TIME("netflix_set_limit_time", "奈飞设置限制", 30l),
         MIDJOURNEY_CAR_TASK("midjourney:car:task","midjourney car 任务数", 48 * 60 * 60L),
         SYS_CONFIG_CACHE_KEY("sys_config_cache_key:", "系统配置缓存key", 60 * 60 * 23L),
+        NF_UPGRAD_USER_LIMIT_KEY("nf_upgrad_user_limit_key:%s:%s:%s", "奈飞同步装置key", 60 * 60L),
 
         ;
 

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/mail/CuiQiuMailService.java

@@ -11,7 +11,7 @@ public interface CuiQiuMailService {
 	/**
 	 * 获取最新邮箱 返回验证码
 	 */
-	String getVerifyCode(String email, Long goodsId, Integer type, Boolean sync, Integer linkType) throws Exception;
+	String getVerifyCode(String email, Long goodsId, Integer type, Integer linkType) throws Exception;
 
 	boolean isCuiQiuEmail(String account);
 }

+ 15 - 0
netflix-service/src/main/java/com/cyksj/service/mail/YhMailService.java

@@ -0,0 +1,15 @@
+package com.cyksj.service.mail;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: YhMailService
+ * 创建者: JavaZou
+ * 创建时间:2024/8/19 15:39
+ */
+public interface YhMailService {
+
+	/**
+	 * 获取最新邮箱 返回验证码
+	 */
+	String getVerifyCode(String email, Long goodsId, Integer type, Integer linkType) throws Exception;
+}

+ 8 - 3
netflix-service/src/main/java/com/cyksj/service/mail/impl/CuiQiuMailServiceImpl.java

@@ -61,8 +61,13 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
 		CuiQiuEmailConfigs = CuiQiuEmailConfigMapper.selectList(null);
 	}
 
+	/**
+	 *
+	 * @param type 1:奈飞安全码
+	 * @param linkType 链接 1:同步验证链接
+	 */
 	@Override
-	public String getVerifyCode(String email, Long goodsId, Integer type, Boolean sync, Integer linkType) throws Exception {
+	public String getVerifyCode(String email, Long goodsId, Integer type, Integer linkType) throws Exception {
 		//获取近二十封邮件
 		String url = "https://domain-open-api.cuiqiu.com/v1/message/list";
 
@@ -114,7 +119,7 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
 			for (CuiQiuEmailDto CuiQiuEmailDto : list) {
 				Long messageId = CuiQiuEmailDto.getId();
 				try {
-					String code = getVerifyCodeByEmail(messageId, goodsId, type, sync, linkType, mailId);
+					String code = getVerifyCodeByEmail(messageId, goodsId, type, linkType, mailId);
 					if (StrUtil.isNotBlank(code)) {
 						return code;
 					}
@@ -135,7 +140,7 @@ public class CuiQiuMailServiceImpl implements CuiQiuMailService {
 		return false;
 	}
 
-	public String getVerifyCodeByEmail(Long messageId, Long goodsId, Integer type, Boolean sync, Integer linkType, String mailId) throws Exception {
+	public String getVerifyCodeByEmail(Long messageId, Long goodsId, Integer type, Integer linkType, String mailId) throws Exception {
 		String url = "https://domain-open-api.cuiqiu.com/v1/message/detail";
 		Map<String, Object> params = new HashMap<>();
 		params.put("token", CUI_QIU_TOKEN);

+ 126 - 0
netflix-service/src/main/java/com/cyksj/service/mail/impl/YhEmailServiceImpl.java

@@ -0,0 +1,126 @@
+package com.cyksj.service.mail.impl;
+
+import cn.hutool.core.lang.Validator;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpStatus;
+import cn.hutool.http.HttpUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.cyksj.common.exception.BusinessRuntimeException;
+import com.cyksj.common.util.StringUtil;
+import com.cyksj.common.util.TicketCodeCommonUtil;
+import com.cyksj.mapper.sys.SysEmailMapper;
+import com.cyksj.model.entity.SysEmail;
+import com.cyksj.service.mail.YhMailService;
+import com.cyksj.service.relation.GroupsRelationNetflixService;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: YhEmailServiceImpl
+ * 创建者: JavaZou
+ * 创建时间:2024/8/19 15:40
+ */
+@Service
+@RequiredArgsConstructor
+@Slf4j
+public class YhEmailServiceImpl implements YhMailService {
+	private final GroupsRelationNetflixService groupsRelationNetflixService;
+
+	private final SysEmailMapper sysEmailMapper;
+
+	@Override
+	public String getVerifyCode(String account, Long goodsId, Integer type, Integer linkType) throws Exception {
+		//获取邮箱密码
+		SysEmail sysEmail = sysEmailMapper.selectOne(Wrappers.lambdaQuery(SysEmail.class)
+				.eq(SysEmail::getEmail, account)
+				.last("limit 1"));
+		if (sysEmail == null) {
+			log.info("获取账号:{}验证码异常,未配置对应系统邮箱", account);
+			throw BusinessRuntimeException.getInstance("获取账号验证码异常,请联系客服...");
+		}
+		String url = "http://yinhelx.com/api/controller.php";
+		Map<String, Object> params = new HashMap<>();
+
+		params.put("imap_key", "imap_56568niua@@");
+		params.put("fun", "imap_read");
+		params.put("imap_ip", "yinhelx.com");
+		params.put("port", "143");
+		params.put("username", account);
+		params.put("password", sysEmail.getPassword());
+		params.put("mbox_id", "0");
+		params.put("delete", "0");
+
+		HttpRequest post = HttpUtil.createPost(url);
+		post.form(params);
+		cn.hutool.http.HttpResponse execute = post.execute();
+		if (execute.getStatus() != HttpStatus.HTTP_OK) {
+			throw BusinessRuntimeException.getInstance("获取验证码异常,请联系客服...");
+		}
+		String code = getDifferentGoodsCode(goodsId, execute.body(), type, linkType);
+		return code;
+	}
+
+	public String getDifferentGoodsCode(Long goodsId, String body, Integer type, Integer linkType) {
+		String code = null;
+		//奈飞
+		if (goodsId == 1) {
+			if (type != null && type == 1) {
+				if (body.contains("輸入此代碼登入") || body.contains("输入此代码登录") || body.contains("Enter this code to sign in")) {
+					code = StrUtil.subBetween(body, "輸入此代碼登入", "請在裝置上輸入上");
+					if (StrUtil.isEmpty(code)) {
+						code = StrUtil.subAfter(body, "输入此代码登录", true);
+					}
+					if (StrUtil.isEmpty(code)) {
+						code = StrUtil.subAfter(body, "Enter this code to sign in", true);
+					}
+				}
+				if (StrUtil.isEmpty(code)) {
+					throw BusinessRuntimeException.getInstance("查询失败,请检查是否发送了登陆码..");
+				}
+			} else {
+				String urlPref;
+				//更新装置
+				if (linkType == 1) {
+					urlPref = "https://www.netflix.com/account/update-primary-location";
+					code = StrUtil.subBetween(body, "[" + urlPref, "]");
+				} else {
+					//验证链接
+					urlPref = "https://www.netflix.com/account/travel/verify";
+					code = StrUtil.subBetween(body, "[" + urlPref, "]");
+				}
+				if (StrUtil.isEmpty(code)) {
+					throw BusinessRuntimeException.getInstance("获取认证链接失败,请重新获取");
+				}
+				String url = urlPref + code;
+				//非点击装置同步更新按钮 直接返回链接
+				if (linkType == 2) return url;
+				//失败返回验证链接
+				if (!groupsRelationNetflixService.confirmUpdate(url)) {
+					return url;
+				}
+				return StrUtil.EMPTY;
+			}
+		}
+		//除奈飞
+		if (StrUtil.isEmpty(code)) {
+			code = TicketCodeCommonUtil.getTicketCodeStr(body, goodsId);
+		}
+		int length = 4;
+		if (goodsId == 33l) {
+			length = 6;
+		}
+		code = StringUtil.getVerifyCodePattern(code, length);
+		if (!Validator.isNumber(code)) {
+			log.error("获取账号验证码失败:{}", StrUtil.subSufByLength(code, 512));
+			throw BusinessRuntimeException.getInstance("获取验证码失败,请重新获取..");
+		}
+		return code.trim();
+	}
+
+}

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/mange/CmsAccountService.java

@@ -53,4 +53,6 @@ public interface CmsAccountService extends IService<Account> {
 	void readFileAndImportEmail(MultipartFile file) throws Exception;
 
 	void batchImportBlockedAccount(Long goodsId, List<Object> accountBlockedList);
+
+	String nfUpgradeDevice(Long accountId) throws Exception;
 }

+ 32 - 0
netflix-service/src/main/java/com/cyksj/service/mange/account/CmsAccountServiceImpl.java

@@ -26,6 +26,8 @@ import com.cyksj.model.manage.views.AccountView;
 import com.cyksj.model.views.CmsUserVO;
 import com.cyksj.model.views.ExpiredAccountDataView;
 import com.cyksj.redis.RedisService;
+import com.cyksj.service.mail.CuiQiuMailService;
+import com.cyksj.service.mail.YhMailService;
 import com.cyksj.service.mange.AccountCommonService;
 import com.cyksj.service.mange.CmsAccountService;
 import com.cyksj.service.mange.CmsGroupService;
@@ -77,6 +79,10 @@ public class CmsAccountServiceImpl extends ServiceImpl<AccountMapper, Account> i
 
 	private final AccountBlockedReplaceRecordMapper accountBlockedReplaceRecordMapper;
 
+	private final CuiQiuMailService cuiQiuMailService;
+
+	private final YhMailService yhMailService;
+
 	@Override
 	public IPage<ExpiredAccountDataView> getExpiredAccountView(Boolean isCorpWx, String customerService, Long goodsId, Long skuId, String account, Boolean renewStatus, Boolean handleStatus, String cnAccount, String usAccount, Integer userId, String startTime, String endTime, String now, Long offset, Long limit) {
 		return accountMapper.getExpiredAccountView(isCorpWx, customerService, goodsId, skuId, account, renewStatus, handleStatus, cnAccount, usAccount, userId, startTime, endTime, now, new Page<>(offset, limit));
@@ -443,4 +449,30 @@ public class CmsAccountServiceImpl extends ServiceImpl<AccountMapper, Account> i
 			accountBlockedReplaceRecordMapper.batchInsert(list);
 		}
 	}
+
+	@Override
+	public String nfUpgradeDevice(Long accountId) throws Exception {
+		Account at = accountMapper.selectById(accountId);
+		if (at == null || at.getGoodsId() != 1l) {
+			throw BusinessRuntimeException.getInstance("只支持奈飞账号");
+		}
+		String account = at.getAccount();
+		String password = at.getPassword();
+		if (StrUtil.hasEmpty(account, password)) {
+			throw BusinessRuntimeException.getInstance("账户异常");
+		}
+		if (cuiQiuMailService.isCuiQiuEmail(account)) {
+			return cuiQiuMailService.getVerifyCode(account, at.getGoodsId(), null, 1);
+		}
+		String code = null;
+		try {
+			code = yhMailService.getVerifyCode(account, at.getGoodsId(), null, 1);
+		} catch (Exception e) {
+			if (e.getMessage() != null && e.getMessage().contains("认证链接")) {
+				throw BusinessRuntimeException.getInstance("请联系用户确认是否发送邮件");
+			}
+			throw BusinessRuntimeException.getInstance(e.getMessage());
+		}
+		return code;
+	}
 }

+ 26 - 91
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -8,9 +8,6 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.lang.Assert;
 import cn.hutool.core.lang.Validator;
 import cn.hutool.core.util.StrUtil;
-import cn.hutool.http.HttpRequest;
-import cn.hutool.http.HttpStatus;
-import cn.hutool.http.HttpUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.cyksj.common.constant.Constant;
@@ -18,7 +15,6 @@ import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
 import com.cyksj.common.util.Jsons;
 import com.cyksj.common.util.StringUtil;
-import com.cyksj.common.util.TicketCodeCommonUtil;
 import com.cyksj.enums.GatewayApiCode;
 import com.cyksj.mapper.*;
 import com.cyksj.mapper.manage.distribute.DistributeGeneralSkuRateMapper;
@@ -38,6 +34,7 @@ import com.cyksj.service.claude.ClaudeService;
 import com.cyksj.service.groups.GroupsFuncService;
 import com.cyksj.service.mail.CuiQiuMailService;
 import com.cyksj.service.mail.MailService;
+import com.cyksj.service.mail.YhMailService;
 import com.cyksj.service.mange.coupon.CouponCommonService;
 import com.cyksj.service.midjourney.MidjourneyAccountService;
 import com.cyksj.service.relation.GroupRelationFrontService;
@@ -58,7 +55,10 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.*;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -145,6 +145,8 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 
 	private final ClaudeService claudeService;
 
+	private final YhMailService yhMailService;
+
 	@Override
 	public SearchResult<RenewalView> getMyTicket(long userId, Boolean isLoginPopularize, String customId, String account) {
 		User u = userMapper.selectById(userId);
@@ -558,35 +560,26 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 			throw BusinessRuntimeException.getInstance("您的车票账号密码异常,请联系客服...");
 		}
 		if (cuiQiuMailService.isCuiQiuEmail(renewalView.getAccount())) {
-			return cuiQiuMailService.getVerifyCode(renewalView.getAccount(), renewalView.getGoodsId(), type, sync, loginReq.getLinkType());
+			return cuiQiuMailService.getVerifyCode(renewalView.getAccount(), renewalView.getGoodsId(), type, loginReq.getLinkType());
 		}
-		//获取邮箱密码
-		SysEmail sysEmail = sysEmailMapper.selectOne(Wrappers.lambdaQuery(SysEmail.class)
-				.eq(SysEmail::getEmail, account)
-				.last("limit 1"));
-		if (sysEmail == null) {
-			log.info("获取账号:{}验证码异常,未配置对应系统邮箱", account);
-			throw BusinessRuntimeException.getInstance("获取账号验证码异常,请联系客服...");
-		}
-		String url = "http://yinhelx.com/api/controller.php";
-		Map<String, Object> params = new HashMap<>();
-
-		params.put("imap_key", "imap_56568niua@@");
-		params.put("fun", "imap_read");
-		params.put("imap_ip", "yinhelx.com");
-		params.put("port", "143");
-		params.put("username", account);
-		params.put("password", sysEmail.getPassword());
-		params.put("mbox_id", "0");
-		params.put("delete", "0");
-
-		HttpRequest post = HttpUtil.createPost(url);
-		post.form(params);
-		cn.hutool.http.HttpResponse execute = post.execute();
-		if (execute.getStatus() != HttpStatus.HTTP_OK) {
-			throw BusinessRuntimeException.getInstance("获取验证码异常,请联系客服...");
-		}
-		String code = getDifferentGoodsCode(renewalView.getGoodsId(), execute.body(), type, sync, loginReq.getLinkType());
+		if (renewalView.getGoodsId() == 1l) {
+			Integer linkType = loginReq.getLinkType();
+			if (linkType == null) {
+				throw BusinessRuntimeException.getInstance("系统异常");
+			}
+			String key = RedisService.key.NF_UPGRAD_USER_LIMIT_KEY.getNameFormat(DateUtil.hour(DateTime.now(), true), linkType, renewalView.getUserId());
+			if (!redisService.hasKey(key)) {
+				redisService.set(key, 1l, RedisService.key.NF_UPGRAD_USER_LIMIT_KEY.getTimeout());
+			} else {
+				Integer value = (Integer) redisService.get(key);
+				if (value > 5) {
+					throw BusinessRuntimeException.getInstance("获取失败,请联系客服");
+				}
+				redisService.incr(key, 1L);
+			}
+		}
+		//银河域名邮件
+		String code = yhMailService.getVerifyCode(account, renewalView.getGoodsId(), type, loginReq.getLinkType());
 		GroupsRelationLoginCodeRecord record = new GroupsRelationLoginCodeRecord();
 		record.setUserId(userId);
 		record.setRelationId(relationId);
@@ -787,64 +780,6 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		return expiryTickets;
 	}
 
-	public String getDifferentGoodsCode(Long goodsId, String body, Integer type, Boolean sync, Integer linkType) {
-		String code = null;
-		//奈飞
-		if (goodsId == 1) {
-			if (type != null && type == 1) {
-				if (body.contains("輸入此代碼登入") || body.contains("输入此代码登录") || body.contains("Enter this code to sign in")) {
-					code = StrUtil.subBetween(body, "輸入此代碼登入", "請在裝置上輸入上");
-					if (StrUtil.isEmpty(code)) {
-						code = StrUtil.subAfter(body, "输入此代码登录", true);
-					}
-					if (StrUtil.isEmpty(code)) {
-						code = StrUtil.subAfter(body, "Enter this code to sign in", true);
-					}
-				}
-				if (StrUtil.isEmpty(code)) {
-					throw BusinessRuntimeException.getInstance("查询失败,请检查是否发送了登陆码..");
-				}
-			} else {
-				String urlPref;
-				//更新装置
-				if (linkType == 1) {
-					urlPref = "https://www.netflix.com/account/update-primary-location";
-					code = StrUtil.subBetween(body, "[" + urlPref, "]");
-				} else {
-					//验证链接
-					urlPref = "https://www.netflix.com/account/travel/verify";
-					code = StrUtil.subBetween(body, "[" + urlPref, "]");
-				}
-				if (StrUtil.isEmpty(code)) {
-					throw BusinessRuntimeException.getInstance("获取认证链接失败,请重新获取");
-				}
-				String url = urlPref + code;
-				//非点击装置同步更新按钮 直接返回链接
-				if (linkType == 2) return url;
-				//失败返回验证链接
-				if (!groupsRelationNetflixService.confirmUpdate(url)) {
-					return url;
-				}
-				return StrUtil.EMPTY;
-			}
-		}
-		//除奈飞
-		if (StrUtil.isEmpty(code)) {
-			code = TicketCodeCommonUtil.getTicketCodeStr(body, goodsId);
-		}
-		int length = 4;
-		if (goodsId == 33l) {
-			length = 6;
-		}
-		code = StringUtil.getVerifyCodePattern(code, length);
-		if (!Validator.isNumber(code)) {
-			log.error("获取账号验证码失败:{}", StrUtil.subSufByLength(code, 512));
-			throw BusinessRuntimeException.getInstance("获取验证码失败,请重新获取..");
-		}
-		return code.trim();
-	}
-
-
 	@Override
 	public void getCollegeStudentUserGptTicket(Long userId) {
 		Retryer<Boolean> build = RetryerBuilder.<Boolean>newBuilder()

+ 10 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/account/CmsAccountController.java

@@ -1295,4 +1295,14 @@ public class CmsAccountController {
 				.field(AccountDisableView::getIsDisable, 1).build());
 		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
 	}
+
+
+	/**
+	 * 奈飞同步用户更新装置
+	 */
+	@PostMapping("/nf/upgrade/device/{accountId}")
+	public Result<String> nfUpgradeDevice(@PathVariable Long accountId) throws Exception {
+		String url = accountService.nfUpgradeDevice(accountId);
+		return GatewayResponse.SUCCESS.newBuilder().toResult(url);
+	}
 }