rkljw преди 1 седмица
родител
ревизия
6bd1cd02b8
променени са 1 файла, в които са добавени 16 реда и са изтрити 10 реда
  1. 16 10
      app/Middleware/Auth/SensitiveMiddleware.php

+ 16 - 10
app/Middleware/Auth/SensitiveMiddleware.php

@@ -65,21 +65,27 @@ class SensitiveMiddleware implements MiddlewareInterface
                     continue;
                 }
                 if (str_contains($concatenated, $badWord)) {
-                    return $this->response->json([
-                        'code' => 0,
-                        'data' => [],
-                        'message' => '发现违禁词: ' . $badWord
-                    ]);
+                    $response = $this->response->withStatus(200)
+                        ->withHeader('Content-Type', 'application/json')
+                        ->withBody(new SwooleStream(json_encode([
+                            'code' => 0,
+                            'data' => [],
+                            'message' => '发现违禁词: ' . $badWord
+                        ])));
+                    return $response;
                 }
             }
 
             return $handler->handle($request);
         } catch (\Exception $e) {
-            return $this->response->json([
-                'code' => -1,
-                'data' => [],
-                'message' => '系统错误:' . $e->getMessage()
-            ]);
+            $response = $this->response->withStatus(200)
+                ->withHeader('Content-Type', 'application/json')
+                ->withBody(new SwooleStream(json_encode([
+                    'code' => -1,
+                    'data' => [],
+                    'message' => '系统错误:' . $e->getMessage()
+                ])));
+            return $response;
         }
     }
 }