Procházet zdrojové kódy

新增每个IP最多访问5次(未开启)

anderx před 2 roky
rodič
revize
949096c040

+ 7 - 0
src/main/java/com/goafanti/baiduAI/bo/OutChatER.java

@@ -4,6 +4,13 @@ public class OutChatER extends OutSendChat{
     private Integer error_code;
     private String error_msg;
 
+    public OutChatER(Integer error_code, String error_msg) {
+        this.error_code = error_code;
+        this.error_msg = error_msg;
+    }
+
+    public OutChatER() {
+    }
 
     public Integer getError_code() {
         return error_code;

+ 1 - 6
src/main/java/com/goafanti/baiduAI/controller/BaiduAiController.java

@@ -27,7 +27,7 @@ import java.util.*;
 
 @RestController
 @RequestMapping(value = "/chat")
-public class BaiduAiController extends CertifyApiController{
+public class BaiduAiController {
 
     @Autowired
     private BaiduAiService baiduAiService;
@@ -38,11 +38,6 @@ public class BaiduAiController extends CertifyApiController{
             in.setUserId(UUID.randomUUID().toString());
             in.setStream(true);
         }
-        if (in.getMessages()==null||in.getMessages().isEmpty()){
-            Result res= new Result();
-            res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"访问参数"));
-            return res;
-        }
         return baiduAiService.sendChat(in);
     }
 

+ 9 - 8
src/main/java/com/goafanti/common/utils/BaiduChatUtils.java

@@ -48,16 +48,17 @@ public class BaiduChatUtils {
     @Async
     public void sendBaiduAiStream(InputSendChat inputSendChat) throws IOException {
         SseResult res =  SseMap.sseEmitterMap.get(inputSendChat.getUserId());
-        if (checkIp()){
-            OutChatER er=new OutChatER();
-            er.setError_code(4004);
-            er.setError_msg("访问超过最大限制,陌生游客每天最多访问5次");
-            res.sseEmitter.send(er);
-        }
+//        if (checkIp()){
+//            res.sseEmitter.send(new OutChatER(4004,"访问超过最大限制,陌生游客每天最多访问5次"));
+//            res.sseEmitter.complete();
+//            SseMap.sseEmitterMap.remove(inputSendChat.getUserId());
+//            return;
+//        }
         BufferedReader reader=null;
         InputStreamReader inputStreamReader=null;
         OutputStream outputStream=null;
         try {
+
             String baidu_url=BAIDU_CHAT_WXYY_URL+getRedisBaiduAccessToken();
             URL url = new URL(baidu_url);
             HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@@ -114,8 +115,8 @@ public class BaiduChatUtils {
         } catch (ProtocolException e) {
             e.printStackTrace();
         }catch (IllegalStateException e){
-            LoggerUtils.debug(getClass(),"前端网页已关闭");
-        }finally {
+            LoggerUtils.debug(this.getClass(),"前端网页已关闭");
+        } finally {
             inputStreamReader.close();
             outputStream.close();
             reader.close();