Parcourir la source

fix 直连token异常排除不再调用

zoujiajian il y a 3 ans
Parent
commit
17bfd1a590

+ 3 - 0
netflix-dao/src/main/java/com/cyksj/model/views/GroupsAccountView.java

@@ -35,6 +35,9 @@ public class GroupsAccountView {
 	@DbField("a.start_time")
 	private Date startTime;
 
+	@DbField("a.gpt_refresh_token")
+	private String gptRefreshToken;
+
 	@DbField("a.expiry_time")
 	private Date expiryTime;
 }

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

@@ -629,6 +629,7 @@ public class RedisService {
         ORDER_DON_POST_DATA_USER_KEY("order_don_post_data_user_key:", "用户订单回传缓存key", -1L),
         ABROAD_SUCCESS_URL("abroad:pay:success_url:","海外支付成功页",60 * 60 * 24L),
         CHAT_GPT_TOKEN_KEY("chat_gpt_token_key:", "chatGPT直连token key", 60 * 10l),
+        CHAT_GPT_TOKEN_EXCEPTION_KEY("chat_gpt_token_exception_key:", "chatGPT直连token异常 key", -1l),
         ;
 
         private String name;

+ 3 - 0
netflix-service/src/main/java/com/cyksj/service/chatgpt/impl/ChatGptAuthServiceImpl.java

@@ -118,6 +118,9 @@ public class ChatGptAuthServiceImpl implements ChatGptAuthService {
 
     @Override
     public String getAccessToken(String username) throws Exception {
+        if (redisService.get(RedisService.key.CHAT_GPT_TOKEN_EXCEPTION_KEY.getName() + username) != null) {
+            throw BusinessRuntimeException.getInstance("该账号登录异常.");
+        }
         Account account = accountMapper.selectOne(Wrappers.lambdaQuery(Account.class).eq(Account::getAccount, username));
         if(account == null){
             throw BusinessRuntimeException.getInstance("账号不存在.");

+ 5 - 2
netflix-service/src/main/java/com/cyksj/service/mange/group/CmsGroupServiceImpl.java

@@ -276,8 +276,11 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
                 .set(Account::getExpiryTime, afterExpiryTime)
                 .set(Account::getGptRefreshToken, StrUtil.EMPTY)
                 .eq(Account::getId, accountId));
-        //清除gpt token
-        redisService.del(RedisKey.CHATGPT_ACCESS_TOKEN + groupsAccountView.getAccount());
+        if (StrUtil.isNotBlank(groupsAccountView.getGptRefreshToken())) {
+            //清除gpt token
+            redisService.del(RedisKey.CHATGPT_ACCESS_TOKEN + groupsAccountView.getAccount());
+            redisService.del(RedisService.key.CHAT_GPT_TOKEN_EXCEPTION_KEY.getName() + groupsAccountView.getAccount());
+        }
 
         //时间有效
         if (afterExpiryTime != null && afterExpiryTime.after(DateTime.now())) {

+ 8 - 2
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -10,8 +10,11 @@ import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.enums.GatewayApiCode;
 import com.cyksj.mapper.GroupsRelationMapper;
 import com.cyksj.mapper.UserMapper;
-import com.cyksj.model.entity.*;
+import com.cyksj.model.entity.CouponUser;
+import com.cyksj.model.entity.GroupsRelation;
+import com.cyksj.model.entity.User;
 import com.cyksj.model.views.*;
+import com.cyksj.redis.RedisService;
 import com.cyksj.service.chatgpt.ChatGptAuthService;
 import com.cyksj.service.mange.coupon.CouponCommonService;
 import com.cyksj.service.relation.GroupRelationFrontService;
@@ -49,6 +52,8 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 
 	private final ChatGptAuthService chatGptAuthService;
 
+	private final RedisService redisService;
+
 	@Override
 	public List<RenewalView> getMyTicket(long userId, Boolean isLoginPopularize) {
 		User u = userMapper.selectById(userId);
@@ -74,12 +79,13 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 			}
 			//chatGPT直连
 			if (ticket.getGoodsId().equals(42l)) {
-				if (ticket.getAccount() != null) {
+				if (StrUtil.isNotBlank(ticket.getAccount())) {
 					String accessToken;
 					try {
 						accessToken = chatGptAuthService.getAccessToken(ticket.getAccount());
 						ticket.setGptRefreshToken(accessToken);
 					} catch (Exception e) {
+						redisService.set(RedisService.key.CHAT_GPT_TOKEN_EXCEPTION_KEY.getName() + ticket.getAccount(), ticket.getAccount());
 					}
 				}
 				ticket.setAccount(null);

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

@@ -283,6 +283,13 @@ public class CmsAccountController {
 							isUpdatePwd = true;
 							//发放模板消息
 							templateCommonService.sendAccountTemplateMsg(account);
+
+							if (StrUtil.isNotBlank(account.getGptRefreshToken())) {
+								account.setGptRefreshToken(StrUtil.EMPTY);
+								//清除gpt token
+								redisService.del(RedisKey.CHATGPT_ACCESS_TOKEN + account.getAccount());
+								redisService.del(RedisService.key.CHAT_GPT_TOKEN_EXCEPTION_KEY.getName() + account.getAccount());
+							}
 						}
 						if (flag) {
 							account.setStartTime(null);
@@ -490,6 +497,7 @@ public class CmsAccountController {
 		    account.setGptRefreshToken(StrUtil.EMPTY);
 		    //清除gpt token
 		    redisService.del(RedisKey.CHATGPT_ACCESS_TOKEN + dbAccount);
+		    redisService.del(RedisService.key.CHAT_GPT_TOKEN_EXCEPTION_KEY.getName() + dbAccount);
 	    }
 	    //时间有效
 	    if (account.getExpiryTime() != null && account.getExpiryTime().after(DateTime.now())) {
@@ -517,6 +525,13 @@ public class CmsAccountController {
 				if (!oldPwd.equals(updatePWd)) {
 					db.setPassword(updatePWd);
 					db.setCustomerServiceId(0l);
+
+					if (StrUtil.isNotBlank(db.getGptRefreshToken())) {
+						db.setGptRefreshToken(StrUtil.EMPTY);
+						//清除gpt token
+						redisService.del(RedisKey.CHATGPT_ACCESS_TOKEN + db.getAccount());
+						redisService.del(RedisService.key.CHAT_GPT_TOKEN_EXCEPTION_KEY.getName() + db.getAccount());
+					}
 					accountService.updateById(db);
 					//记录
 					accountService.saveRecord(userId, account.getId(), oldPwd, updatePWd, "多选修改密码");
@@ -690,6 +705,12 @@ public class CmsAccountController {
 				templateCommonService.sendAccountTemplateMsg(account);
 				//记录操作日志
 				accountService.recordAutoUpdatePwd(account.getId(), account.getAccount(), oldPwd, new_pass, ServletUtil.getClientIP(request));
+				if (StrUtil.isNotBlank(account.getGptRefreshToken())) {
+					account.setGptRefreshToken(StrUtil.EMPTY);
+					//清除gpt token
+					redisService.del(RedisKey.CHATGPT_ACCESS_TOKEN + account.getAccount());
+					redisService.del(RedisService.key.CHAT_GPT_TOKEN_EXCEPTION_KEY.getName() + account.getAccount());
+				}
 				//记录
 				accountService.saveRecord(0l, account.getId(), oldPwd, new_pass, "自动修改密码");
 			}