jerry 1 год назад
Родитель
Сommit
41293b3e4f

+ 1 - 1
backendApi/modules/v1/controllers/BaseController.php

@@ -49,7 +49,7 @@ class BaseController extends \yii\rest\ActiveController {
         ];
 
         $request = Yii::$app->request;
-        if (\Yii::$app->redis->get('backend_ip_filter') && !in_array($request->getUrl(), $notFilterApi)) {
+        if (\Yii::$app->redis->get('backend_ip_filter') && !Tool::checkArrayElementSubstringOfString($request->getUrl(), $notFilterApi)) {
             if (!(new IpFilter())->checkIp('backend')) {
                 throw new \Exception('用户名或密码错误');
             }

+ 10 - 0
common/helpers/Tool.php

@@ -575,4 +575,14 @@ class Tool {
 
         return true;
     }
+
+    function checkArrayElementSubstringOfString($string, $array) {
+        foreach ($array as $substr) {
+            if (strpos($string, $substr) !== false) {
+                return true;
+            }
+        }
+        return false;
+    }
+
 }

+ 2 - 1
frontendApi/modules/v1/controllers/BaseController.php

@@ -11,6 +11,7 @@ namespace frontendApi\modules\v1\controllers;
 use common\components\ActiveRecord;
 use common\helpers\Date;
 use common\helpers\Form;
+use common\helpers\Tool;
 use common\libs\IpFilter;
 use frontendApi\modules\v1\models\User;
 use Yii;
@@ -63,7 +64,7 @@ class BaseController extends \yii\rest\ActiveController {
         ];
 
         $request = Yii::$app->request;
-        if (\Yii::$app->redis->get('member_ip_filter') && !in_array($request->getUrl(), $notFilterApi)) {
+        if (\Yii::$app->redis->get('member_ip_filter') && !Tool::checkArrayElementSubstringOfString($request->getUrl(), $notFilterApi)) {
             if (!(new IpFilter())->checkIp('member')) {
                 throw new \Exception('用户名或密码错误');
             }