mivodev/mikrotik-api-ros7 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mivodev/mikrotik-api-ros7

Composer 安装命令:

composer require mivodev/mikrotik-api-ros7

包简介

Complete, universal PHP client for Mikrotik RouterOS v7 REST API. Framework-agnostic, zero-dependency.

README 文档

README

Mikrotik API ROS7 (REST)

Mikrotik API ROS7 (REST)

PHP Version License

Complete, universal PHP client for Mikrotik RouterOS v7 REST API. Framework-agnostic, leveraging native PHP cURL.

Features

  • 🌐 Modern REST API — Uses RouterOS v7's native REST interface (HTTP/HTTPS)
  • 🔄 100% Backward Compatible — The comm() method maps legacy ROS6 CLI commands to REST automatically
  • 🏗️ Native HTTP Methods — Dedicated get(), put(), patch(), post(), and delete() methods
  • 🧩 Framework-Agnostic — Works with PHP Native, Laravel, CodeIgniter, Symfony
  • 🔐 SSL Support — Auto-connects via HTTPS (port 443) with options to verify or bypass self-signed certificates
  • 📊 Auto-Parsing — JSON responses are automatically parsed and structured

Requirements

  • PHP >= 8.2
  • ext-curl
  • ext-json
  • Mikrotik RouterOS v7 (with www-ssl or www service enabled)

Installation

Via Composer (Recommended)

composer require mivodev/mikrotik-api-ros7

For Laravel Projects

Use the Laravel wrapper instead, which provides ServiceProvider, Facade, and .env configuration:

composer require mivodev/laravel-mikrotik-api-ros7

Quick Start

<?php

use Mivo\MikrotikRos7\Client;

$api = new Client();
$api->connect('192.168.1.1', 'admin', 'password');

// Using Native REST Methods
$identity = $api->get('/rest/system/identity');
print_r($identity);

// Using Legacy CLI Mapping
$users = $api->comm('/ip/hotspot/user/print');
print_r($users);

Usage: Native REST

The preferred way to interact with ROS7 is using explicit HTTP methods:

$api = new Client();
$api->connect('192.168.1.1', 'admin', 'password');

// GET (Read)
$users = $api->get('/rest/ip/hotspot/user', ['profile' => 'default']);

// PUT (Create)
$api->put('/rest/ip/hotspot/user', [
    'name' => 'new-user',
    'password' => 'secret123',
    'profile' => 'default'
]);

// PATCH (Update) - Requires the .id
$api->patch('/rest/ip/hotspot/user/*1', [
    'password' => 'new-secret'
]);

// DELETE (Remove)
$api->delete('/rest/ip/hotspot/user/*1');

// POST (Execute Command)
$api->post('/rest/system/reboot');

Usage: Legacy ROS6 CLI Mapping

If you are migrating from ROS6, you don't need to rewrite your code! The comm() method automatically translates legacy CLI syntax into the correct REST HTTP requests:

// Translated to: GET /rest/ip/hotspot/user
$users = $api->comm('/ip/hotspot/user/print');

// Translated to: PUT /rest/ip/hotspot/user with JSON payload
$api->comm('/ip/hotspot/user/add', [
    'name' => 'test-user',
    'password' => '123'
]);

// Translated to: PATCH /rest/ip/hotspot/user/*1
$api->comm('/ip/hotspot/user/set', [
    '.id' => '*1',
    'password' => 'new-password'
]);

// Translated to: DELETE /rest/ip/hotspot/user/*1
$api->comm('/ip/hotspot/user/remove', [
    '.id' => '*1'
]);

// Translated to: GET /rest/ip/hotspot/user?name=test-user
$api->comm('/ip/hotspot/user/print', [
    '?name' => 'test-user'
]);

Configuration

$api = new Client();

// Disable SSL certificate verification (useful for router self-signed certs)
$api->verifySsl = false;

// Set connection timeout (seconds)
$api->timeout = 10;

// Enable debug mode (prints cURL commands and JSON payloads)
$api->debug = true;

// Connect via HTTP instead of HTTPS (not recommended for production)
$api->connect('192.168.1.1', 'admin', 'password', 80);

Architecture

src/
├── Client.php                   # Main client — uses cURL for REST
├── Contracts/
│   └── ClientInterface.php      # Universal interface (shared with ROS6)
├── Http/
│   ├── RequestBuilder.php       # Maps legacy CLI commands to REST
│   └── ResponseParser.php       # Parses JSON and handles HTTP errors
└── Exceptions/
    └── MikrotikException.php    # Error handling for REST (400, 401, 404, 500)

References

License

MIT License. See LICENSE for details.

统计信息

  • 总下载量: 203
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固