当前位置: 首页 > news >正文

群控系统服务端开发模式-应用开发-业务架构逻辑开发BaseAPI继续开发一

        思来想去,还是加一张系统配置表,主要的作用是配置网站信息及token过期时间的。

一、添加系统配置表

        1、创建表语句

CREATE TABLE `cluster_control`.`nc_param_system`  (`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '编号',`website_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '网站名称',`website_describe` varchar(250) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '网站描述',`website_keyword` varchar(120) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '网站关键字',`security_password` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '二次密码',`checked_backend_log` varchar(250) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '后端Log',`website_filing_applica` varchar(250) NOT NULL COMMENT '网站备案申明',`platform_token_expira` smallint(6) UNSIGNED NULL DEFAULT 0 COMMENT '平台端token过期时间',`update_time` datetime(0) NULL ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '修改时间',PRIMARY KEY (`id`)
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '系统配置文件';

        2、表结构

        3、添加配置数据

INSERT INTO `cluster_control`.`nc_param_system`(`website_name`, `website_describe`, `website_keyword`, `security_password`, `checked_backend_log`, `website_filing_applica`, `platform_token_expira`, `update_time`) VALUES ('国际群控系统', '国际群控系统', '群控系统|国际群控系统', 'cX#IdvJlYX6LmYr8gR@v', 'https://yuanlong-base.oss-cn-hangzhou.aliyuncs.com/2024-04-14/c59313916105916258762d26806a158c85a6bb59.png', 'Copyright © 2028 Themepure. All Rights Reserved|群控系统|http://www.yuanlongsoftware.cn', 1800, '2024-10-29 09:49:55')

二、token数据层开发

        1、系统配置数据层开发

<?php
/*** 系统配置参数数据层管理* User: 龙哥·三年风水* Date: 2024/10/29* Time: 10:20*/
namespace app\model\common;
use app\model\Tools;
use Redis\Redis;
class ParamSystem extends Tools
{protected static $name = 'param_system';protected static $connection = 'mysql';protected $pk = 'id';protected static $unsetField = ['update_time','create_time','status'];//获取单条数据public static function dataFind($where = [], $field='*', $unsetField=[]){$fieldL = 0; //预防字段少于数据库字段等情况下,加入等级进行区分。保障Redis存储最高性if($field == '*'){$res = Redis::select(config('cache.stores.redis.other_db'))->hgetall('param_system1');}else{$res = Redis::select(config('cache.stores.redis.other_db'))->hmget('param_system1',explode(',',$field));}foreach($res as $v){if(empty($v)){$fieldL = 1;break;}}if($fieldL === 1){$fields = $field;if($fieldL === 1)$fields = '*';$res = self::dataFinds(self::$name, $where, $fields, true,self::$connection);if(count($unsetField) > 0){//如果单独添加过滤数据,则优先并入数据foreach($unsetField as $v){array_push(self::$unsetField,$v);}}if(!empty(self::$unsetField)){//主动过滤修改时间等状态foreach(self::$unsetField as $v){if(isset($res[$v]))unset($res[$v]);}}//过滤好了之后存入RedisRedis::select(config('cache.stores.redis.other_db'))->hmset('param_system1',$res);}if($field != '*'){//根据需要,将需要的字段过滤返回$data = [];$list = explode(',',$field);foreach($list as $k=>$v){if($fieldL === 1){$data[$v] = $res[$v];}else{$data[$v] = $res[$k];}}$res = $data;}return  $res;}//保存数据public static function save($data, $where = [], $unsetField=[]){self::dataSaves(self::$name, $data, $where, self::$connection);if(count($unsetField) > 0){//如果单独添加过滤数据,则优先并入数据foreach($unsetField as $v){array_push(self::$unsetField,$v);}}if(count(self::$unsetField) > 0){//主动过滤修改时间等状态foreach(self::$unsetField as $v){if(isset($data[$v]))unset($data[$v]);}}//过滤好了之后存入RedisRedis::select(config('cache.stores.redis.other_db'))->hmset('param_system1',$data);}
}

        2、管理员数据层开发

<?php
/*** 管理员数据控制* User: 龙哥·三年风水* Date: 2024/10/29* Time: 10:26*/
namespace app\model\permission;
use app\model\Tools;
class Admin extends Tools
{protected static $name = 'permission_admin';protected static $connection = 'mysql';protected $pk = 'id';protected static $unsetField = ['update_time','create_time'];//获取分页数据public static function getRedisList($where = [], $limit = []){return self::dataRedisLists(self::$name, $where, $limit, self::$connection);}//获取所有数据public static function getAll($where = [], $field = '*', $order = '', $join = []){return self::dataAlls(self::$name, $where, $field, $order, $join, self::$connection);}//获取单条数据public static function dataFind($where = [], $field, $findType = true){return self::dataFinds(self::$name, $where, $field, $findType, self::$connection);}//保存数据public static function redisSave($data, $pk = ''){return self::dataRedisSaves(self::$name, $data, $pk, self::$connection);}//删除数据 -- 带图片的public static function dataDetele($pk){self::dataRedisDeteles(self::$name, $pk, self::$connection);}
}

        3、token数据层开发

<?php
/*** 登录用户数据管理* User: 龙哥 三年风水* Date: 2024/10/29* Time: 10:26*/
namespace app\model\common;
use app\model\Tools;
use Redis\Redis;
use app\model\common\ParamSystem as SystemModel;
use app\model\permission\Admin;
class Token extends Tools
{protected static $name = 'permission_token';protected static $connection = 'mysql';protected $pk = 'token';//查询列表public static function dataList($where,$field,$limit,$order){return self::dataLists(self::$name, $where, $field, $limit, $order, [], self::$connection);}public static function dataFind($where = [], $field, $findType = true){return self::dataFinds(self::$name, $where, $field, $findType, self::$connection);}//保存数据public static function save($data, $where = []){return self::dataSaves(self::$name, $data, $where, self::$connection);}//修改token整个状态public static function setToken($token, $attack, $clientIp){$data['admin_id'] = 0;$data['username'] = '';$data['avatar'] = '';$data['realname'] = '';$data['email'] = '';$data['ip'] = '';$data['department_id'] = 0;$data['grade_id'] = 0;$data['role_id'] = 0;$redisToken = Redis::select(config('cache.stores.redis.token_db'))->get('token_'.$token);if(empty($redisToken))return array('status' => false, 'info' => 'token已经过期咯,请重新登录!', 'data' => $data);//获取系统配置的过期时间$systemParam = SystemModel::dataFind(['id' => 1],'platform_token_expira');//验证是否跨站攻击$attackToken = Redis::select(config('cache.stores.redis.token_db'))->get('token_' . $redisToken);if(!empty($attackToken)){if ($attackToken === $attack){//如果传过来加密后的token与Redis里面记录的一样,就禁止访问、延长过期时间并加入黑名单Redis::select(config('cache.stores.redis.token_db'))->expire('token_'.$token, $systemParam['platform_token_expira']);//加入黑名单Redis::select(config('cache.stores.redis.default_db'))->sadd('black-list', $clientIp);return array('status' => false, 'info' => '跨站攻击', 'data' => $data);}}Redis::select(config('cache.stores.redis.token_db'))->expire('token_'.$token, $systemParam['platform_token_expira']);Redis::select(config('cache.stores.redis.token_db'))->setex('token_' . $redisToken, $systemParam['platform_token_expira'], serialize($attack));$resAdminFind = Admin::dataFind(['id' => $redisToken], 'username,avatar,realname,email,ip,department_id,grade_id,role_id,status',true);if ($resAdminFind['status'] !== 1) return array('status' => false, 'info' => '该用户已被禁用', 'data' => $data);$data['admin_id'] = $redisToken;$data['username'] = $resAdminFind['username'];$data['avatar'] = $resAdminFind['avatar'];$data['realname'] = $resAdminFind['realname'];$data['email'] = $resAdminFind['email'];$data['ip'] = $resAdminFind['ip'];$data['department_id'] = $resAdminFind['department_id'];$data['grade_id'] = $resAdminFind['grade_id'];$data['role_id'] = $resAdminFind['role_id'];return array('status' => true, 'info' => '', 'data' => $data);}
}

三、提前说明

        我思来想去,还是将报错统一化管理,这样方便后面拓展。


http://www.mrgr.cn/news/61115.html

相关文章:

  • Windows 11 开启 WSL(Windows Subsystem for Linux)完整指南
  • RabbitMQ介绍与使用
  • 【面试题】技术场景 5、日志采集ELK
  • 不同路径 不同路径 II 整数拆分
  • 前端:前端开发任务分解
  • 【数据结构】树的定义
  • 借助Aspose.Email,管理受密码保护的 PST 文件
  • Netty核心源码与优化
  • python去掉字符串空格
  • CISAW考试通过率怎么样?
  • 一款扫描整个网络存活的IP 工具——Advanced IP Scanner
  • 【软件测试】- 手机APP测试方法
  • 汽车电子行业数字化转型的实践与探索——以盈趣汽车电子为例
  • uniapp通过id获取div的宽度,高度,位置等(应该是 任意平台都通用 )
  • 视频转gif技巧:视频怎么做成动态表情包?5个简单方法搞定
  • 论文阅读:MultiUI 利用网页UI进行丰富文本的视觉理解
  • 确保公司数据不泄密的措施有哪些(如何保证公司数据安全)?8个重要措施你需要知道!
  • 【机器学习(十九)】零代码开发之随机森林(Random Forest,RF)算法-Sentosa_DSML社区版
  • php反序列化常见魔术方法整理
  • SpringBoot框架下的商场应急处理流程
  • Python库numpy之七
  • 手机无线/有线投屏电脑方案
  • 新能源行业必会基础知识-----电力系统经济学原理-----主目录-----持续更新
  • win10 wsl2 install
  • 2024-10-29 商业分析-恒大数据超过50%造假-依然获得AAA评级-国内营商环境-诈骗为主-记录
  • jenkins自动化构建vue(web)项目并部署(项目实战)