文档授权验证

请输入授权码后查看文档内容

Skip to content

系统命令

php think tm

===============系统命令行==============
(1) 修改后台密码   (2) 清除登录限制
(3) 清除系统日志   (4) 清除系统缓存
=======================================

【修改后台密码】
命令: php think tm 1 --account admin --password 123456
参数:
    --account : 要修改的账号
    --password : 修改的新密码
        
【清除登录限制】
命令: php think tm 2 --account admin
参数:
    --account : 要清除限制的账号

【清除系统日志】
命令: php think tm 3 --reserve_day 30
参数:
    --reserve_day : 保留日志天数 

【清除系统缓存】
命令: php think tm 4
参数:

访问控制器

可跳过路由限制,直接访问控制方法

php think action

php think action admin/test/index --option name=jack,age=10

参数:
    --action : 控制器路径
    --option : 参数

mcp服务命令

php think mcp

===============MCP工具命令================
(1) 生成mcp服务token   (2) 查看mcp服务token
(3) 获取mcp工具信息     (4) 获取mcp路由列表
=========================================
请携带命令编号如: php think mcp 1


【生成mcp服务token】
命令: php think mcp 1
参数:
    --key : MCP服务key
    --expire : MCP服务token过期时间(秒)
        
【查看mcp服务token】
命令: php think mcp 2
参数:
    --key : MCP服务key

【获取mcp工具信息】
命令: php think mcp 3

【获取mcp路由列表】
命令: php think mcp 4

平台接口命令

php think platform

===============平台接口工具命令==========================
(1) 生成接口调用统计日志   (2) 清理开发者过期accessToken
(3) 清理用户过期userToken (4) 令牌桶添加令牌
=======================================================

【生成接口调用统计日志】
命令: php think platform 1
参数:
    --type : 统计时间类型 hour|day|month
    --date : 统计时间(天) 例如 2026-1-20
        
【清理开发者过期accessToken】
命令: php think platform 2

【清理用户过期userToken】
命令: php think platform 3

【令牌桶添加令牌】
// 每分钟执行一次
命令: php think platform 4

创建命令

命令文件统一放在app/common/command目录下

以创建订单order命令为例,可传参params

<?php

namespace app\common\command;

use Exception;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\console\input\Option;

/**
 * 计划任务
 */
class Crontab extends Command
{
    /**
     * 指令配置
     */
    protected function configure()
    {
        $this->setName('order')->setDescription('订单任务')->addOption('params', null, Option::VALUE_REQUIRED, '参数');
    }

    /**
     * 执行任务
     * @param Input $input
     * @param Output $output
     * @return bool
     */
    protected function execute(Input $input, Output $output): bool
    {
        // 订单任务
        $params  = $input->getOption('params'); // 获取参数
        return true;
    }
}

添加命令到配置文件,文件路径:config/console.php

<?php
return [
    // 指令定义
    'commands' => [
        // 订单命令
        "order"=>"app\common\command\Order",
    ],
];

执行命令

php think order

Released under the Apache-2.0 License.