Browse Source

Merge branch 'master' of http://git.bjzxtw.org.cn:3000/zxt/admin_consumer

LiuJ 1 month ago
parent
commit
51d468e9d8

+ 6 - 1
.env

@@ -65,4 +65,9 @@ APP_SECRET = 09d1ac9287cb6f3c5e81aa27a6b7138e
 
 SENSITIVE_WORD = https://v.api.aa1.cn/api/api-mgc/index.php
 
-THE_HOST= adminpre.bjzxtw.org.cn
+THE_HOST= adminpre.bjzxtw.org.cn
+
+
+
+BAIDU_API_KEY = HZKNvKz4AHMRUVgbMt94vNo9
+BAIDU_SECRET_KEY = JorrzAQD669Y4vfuEWAgc0meGxuhHMTy

+ 33 - 8
app/Controller/LoginController.php

@@ -342,14 +342,18 @@ class LoginController extends AbstractController
      */
     public function checkUserAuth($data)
     {
+//        var_dump("进没进来呢::",$data);
         $websiteGroup = [
             'id'=>$data['id']
         ];
         $result = $this->userServiceClient->getWebsiteGroupInfo($websiteGroup);
+//        var_dump("checkUserAuth:",$result);
         if($result['code']==200){
             if($data['SiteId'] && $result['data']['web_ids']){
                 if(in_array($data['SiteId'],json_decode($result['data']['web_ids'],true))){
                     return true;
+                }else{
+                    return false;
                 }
             }else{
                 return false;
@@ -366,6 +370,12 @@ class LoginController extends AbstractController
      */
     public function loginStatus(Jwt $jwt)
     {
+        $header = $this->request->getHeader('userurl');
+        $origin = $header[0];
+        $logindevice = explode("//", $origin);
+        if(!isset($logindevice[1]) && !$logindevice[1]){
+            return Result::error('userurl不存在,请登录');
+        }
         $reqData = $this->request->all();
         $validator = $this->validationFactory->make(
             $reqData,
@@ -381,11 +391,22 @@ class LoginController extends AbstractController
             return Result::error($errorMessage);
         }
         try {
-            $status =  $jwt->verifyToken($reqData['token']);
-            //   var_dump("状态:",$status);
-            return Result::success(['isLogin' => true]);
+            $jwt->verifyToken($reqData['token']);
+            $results = $this->checkAuth([
+                'token'=>$reqData['token'],
+                'userurl'=>$logindevice[1]
+            ]);
+            if($results['code']==200){
+                return Result::success(['isLogin' => true]);
+            }elseif($results['code']==-1){
+                return Result::error("没有权限登陆".$logindevice[1]."这个域名",-1);
+            }elseif($results['code']==-2){
+                return Result::error("token已过期",-2);
+            }else{
+                return Result::error("参数错误");
+            }
         }catch(\Exception $e){
-            return Result::error('token已过期:'.$e->getMessage());
+            return Result::error('token已过期:'.$e->getMessage(),-2);
         }
     }
 
@@ -674,12 +695,12 @@ class LoginController extends AbstractController
         $ver =$jwt->getClaimsByToken($data['token']);
         $tokenTime =  $jwt->getTokenDynamicCacheTime($data['token']);
         if($tokenTime==0){
-            return Result::error("token已过期,请重新登录",-1);
+            return Result::error("token已过期,请重新登录",-2);
         }
         if(isset($data['userurl']) && $data['userurl']){
             $result = $this->websiteServiceClient->getWebsiteId(['website_url'=>$data['userurl']]);
             if(!isset($result['data']['id']) || !$result['data']['id']){
-                return Result::error("网站不存在...",-1);
+                return Result::error("网站不存在...",-2);
             }
             if($ver['type_id']!=10000){
                 $userInfo = $this->userServiceClient->getUserInfo($ver['uid']);
@@ -695,13 +716,17 @@ class LoginController extends AbstractController
                     if (!$resultAuth) {
                         // 如果没有权限,返回错误响应
                         return Result::error("没有权限登陆此网站...",-1);
+                    }else{
+                        return Result::success([]);
                     }
                 }else{
-                    return Result::error("用户没有群组...",-1);
+                    return Result::error("用户没有群组...",-2);
                 }
+            }else{
+                return Result::success([]);
             }
         }else{
-            return Result::error("userurl不能为空...",-1);
+            return Result::error("userurl不能为空...",-2);
         }
 
     }

+ 93 - 0
app/Controller/PublicController.php

@@ -3,6 +3,9 @@ declare (strict_types = 1);
 namespace App\Controller;
 
 use App\JsonRpc\PublicRpcServiceInterface;
+use App\Model\Couplet;
+use App\Model\HistoryToday;
+use App\Model\Riddle;
 use App\Tools\CommonService;
 use App\Tools\PublicData;
 use App\Tools\Result;
@@ -1266,5 +1269,95 @@ class PublicController extends AbstractController
         $result = $this->publicServiceClient->getCalendar($data);
         return $result['code'] == 200 ? Result::success($result['data']) : Result::error($result['message']);
     }
+
+    /**
+     * 添加历史上的今天
+     * @return void
+     */
+    public function addHistoryToday()
+    {
+        $result = PublicData::getHistoryToday();
+        if($result['code']!=200){
+            return Result::error($result['msg']);
+        }
+        $dataList = $result['data']??[];
+        if($dataList){
+            foreach ($dataList as $value){
+                preg_match('/^(-?\d+)年(\d+)月(\d+)日$/', $value['year'], $matches);
+                if (isset($matches[1], $matches[2], $matches[3])) {
+                    $year = $matches[1];
+                    $month = str_pad($matches[2], 2, '0', STR_PAD_LEFT); // 补零至两位
+                    $day = str_pad($matches[3], 2, '0', STR_PAD_LEFT); // 补零至两位
+                    $formattedDate = "{$year}-{$month}-{$day}";
+//                    echo $formattedDate; // 输出:-1184-04-24
+                } else {
+                    return Result::error($result['msg']);
+                }
+                $value['year'] = $formattedDate;
+                HistoryToday::updateOrInsert(
+                    ['title' => $value['title']],
+                    ['title' => $value['title']??'','year' => $value['year']]
+                );
+            }
+        }
+        return Result::success($result['data']);
+    }
+    /**
+     * 添加对联
+     * @return void
+     */
+    public function addCouplet()
+    {
+        $requireData = $this->request->all();
+//        $validator = $this->validationFactory->make(
+//            $requireData,
+//            [
+//                'type' => 'required',
+//            ],
+//            [
+//                'type.required' => 'type不能为空',
+//            ]
+//        );
+//        if ($validator->fails()) {
+//            $errorMessage = $validator->errors()->first();
+//            return Result::error($errorMessage);
+//        }
+        $result = PublicData::getCouplet($requireData['type']??"");
+        if($result['code']!=200){
+            return Result::error($result['msg']);
+        }
+        $dataList = $result['result']['list']??[];
+        if($dataList){
+            foreach ($dataList as $value){
+                Couplet::updateOrInsert(
+                    ['first' => $value['shanglian']],
+                    ['center' => $value['hengpi']??'','first' => $value['shanglian'],'second'=>$value['xialian'],'type'=>$value['fenlei']??'']
+                );
+            }
+        }
+        return Result::success($result['result']['list']);
+    }
+
+    /**
+     * 添加对联
+     * @return void
+     */
+    public function addRiddle()
+    {
+        for ($i = 0; $i < 5; $i++) {
+            $result = PublicData::addRiddle();
+            if($result['code']!=1){
+                return Result::error("没资源了");
+            }
+            var_dump($result);
+            Riddle::updateOrInsert(
+                ['riddle_title' => $result['mt']],
+                ['riddle_title' => $result['mt']??'','riddle_bottom' => $result['md']??'','type' => $result['lx']??'','prompt' => $result['ts']??'']
+            );
+            $i++;
+            sleep(2);
+        }
+        return Result::success($result);
+    }
 }
 

+ 1 - 1
app/Middleware/Auth/SensitiveMiddleware.php

@@ -70,7 +70,7 @@ class SensitiveMiddleware implements MiddlewareInterface
                         [
                             'code' => 0,
                             'data' => [$message],
-                            'message' => "该内容存在非法信息,请修改后重新发布"
+                            'message' => "存在违禁词:".$badWord.",请修改后重新发布"
                         ]
                     );
                 }

+ 22 - 0
app/Model/Couplet.php

@@ -0,0 +1,22 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class Couplet extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'couplet';
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}

+ 22 - 0
app/Model/HistoryToday.php

@@ -0,0 +1,22 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class HistoryToday extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'history_today';
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}

+ 22 - 0
app/Model/Riddle.php

@@ -0,0 +1,22 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class Riddle extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'riddle';
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}

+ 61 - 0
app/Tools/PublicData.php

@@ -2,6 +2,7 @@
 namespace App\Tools;
 use Hyperf\Snowflake\IdGeneratorInterface;
 use Hyperf\Context\ApplicationContext;
+use function Hyperf\Support\env;
 
 class PublicData
 {
@@ -207,4 +208,64 @@ class PublicData
         ];
     }
 
+    /**
+     * 历史上的今天
+     * @return mixed
+     */
+    public static function getHistoryToday()
+    {
+        $api_url = "https://api.52vmy.cn/api/wl/today?type=json";
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $api_url);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        $response = curl_exec($ch);
+        curl_close($ch);
+        $data = json_decode($response, true);
+        return $data;
+    }
+
+    /**
+     * 获取谜语
+     * @return mixed
+     */
+    public static function addRiddle()
+    {
+        $api_url = "https://v.api.aa1.cn/api/api-miyu/index.php";
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $api_url);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        $response = curl_exec($ch);
+        curl_close($ch);
+        var_dump("返回数据:",$response);
+        $cleanStr = preg_replace('/<script[^>]*?>.*?<\/script>/is', '', $response);
+        $jsonStr = trim(preg_replace('/\s+/', ' ', $cleanStr)); // 压缩空白符
+        $jsonStr = preg_replace('/^.*?({.*})$/', '$1', $jsonStr); // 提取最后一个完整 JSON
+        $arr = json_decode($jsonStr, true);
+        if (json_last_error() !== JSON_ERROR_NONE) {
+            return json_last_error_msg();
+        }
+        var_dump("返回数据111:",$response);
+        return $arr;
+    }
+    /**
+     * @param $text
+     * @return bool|string
+     */
+    public static  function getCouplet($text="") {
+        if($text){
+            $api_url = "https://apis.tianapi.com/msdl/index?key=44c4f9b3d66ce06900a098c78b90478f&num=10&fenlei=".urlencode($text);
+        }else{
+            $api_url = "https://apis.tianapi.com/msdl/index?key=44c4f9b3d66ce06900a098c78b90478f&num=10";
+        }
+//        var_dump("请求地址:",$api_url);
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $api_url);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        $response = curl_exec($ch);
+        curl_close($ch);
+        $data = json_decode($response, true);
+        return $data;
+    }
+
+
 }

+ 4 - 1
config/api/public.php

@@ -93,10 +93,13 @@ Router::addGroup(
         Router::post('/buckets', [MinioController::class, 'listBuckets']);
 
         Router::post('/uploadFile', [MinioController::class, 'uploadFiles']);
-
+        //获取ip信息
         Router::get('/getIpInfo', [PublicController::class, 'getIpInfo']);
         Router::get('/getCalendar', [PublicController::class, 'getCalendar']);
         Router::get('/getWeatherInfo', [PublicController::class, 'getWeatherInfo']);
+        Router::post('/addHistoryToday', [PublicController::class, 'addHistoryToday']);
+        Router::post('/addCouplet', [PublicController::class, 'addCouplet']);
+        Router::post('/addRiddle', [PublicController::class, 'addRiddle']);
 
     }
 );