fyennyi/mofh-api-client 问题修复 & 功能扩展

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

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

fyennyi/mofh-api-client

Composer 安装命令:

composer require fyennyi/mofh-api-client

包简介

PSR-compliant MyOwnFreeHost API Client.

README 文档

README

Latest Stable Version Total Downloads License Static Analysis

A PSR-compliant client for interacting with the MyOwnFreeHost (MOFH) API. This library provides a structured, type-safe way to manage hosting accounts, domains, and support tickets.

Features

  • PSR-18 Compliant: Use any compatible HTTP client (Guzzle, Symfony, etc.).
  • PSR-17 Compliant: Decoupled request factories.
  • PSR-3 Logging: Built-in support for logging request/response cycles.
  • Domain Driven Design: Separated repositories for Accounts, Domains, Support, and System.
  • Strictly Typed: Utilizes DTOs (Data Transfer Objects) for all API interactions.

Installation

You can install the package via Composer:

composer require fyennyi/mofh-api-client

Basic Usage

Initialization

use Fyennyi\MofhApi\Client;
use Fyennyi\MofhApi\Connection;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\HttpFactory;

// Initialize dependencies
$httpClient = new GuzzleClient(['verify' => false]); // MOFH certificates are often expired
$requestFactory = new HttpFactory();
$connection = new Connection('your_api_username', 'your_api_password');

// Create the client
$mofh = new Client($connection, $httpClient, $requestFactory);

Managing Accounts

use Fyennyi\MofhApi\Dto\Account\CreateAccountRequest;
use Fyennyi\MofhApi\Dto\Support\TicketReply;

// Create a new hosting account
try {
    $request = new CreateAccountRequest(
        username: 'exampleuser',
        password: 'secure_password',
        contactEmail: 'user@example.com',
        domain: 'user.yourdomain.com',
        plan: 'MyPlan'
    );

    $response = $mofh->account->create($request);
    echo "Account created: " . $response->vPanelUsername;

} catch (\Exception $e) {
    echo "Error: " . $e->getMessage();
}

// Support System: Create and Reply to tickets
$ticketId = $mofh->support->createTicket('hname_1234', 'Issue', 'Text', 'domain.com');
$mofh->support->reply(new TicketReply($ticketId, 'My response message'));

// Suspend an account
$mofh->account->suspend('hname_12345678', 'Policy violation.');

Domain & System Information

// Check if a domain is available
$isAvailable = $mofh->domain->checkAvailability('test.example.com');

// Get account info by domain name
$userData = $mofh->domain->getUserByDomain('test.example.com');

// Get CNAME validation token (MD5)
$token = $mofh->system->getCnameToken('my-new-site.com');

// List available hosting packages
$packages = $mofh->system->getPackages();
foreach ($packages as $package) {
    echo "Plan: {$package->name} | Quota: {$package->diskQuota}MB\n";
}

Error Handling

The library throws Fyennyi\MofhApi\Exception\MofhException for API-level errors or transport issues.

try {
    $mofh->account->remove('hname_12345678');
} catch (\Fyennyi\MofhApi\Exception\MofhException $e) {
    // Handle specific API error
}

Requirements

  • PHP 8.1 or higher.
  • ext-json and ext-simplexml extensions.

Contributing

Contributions are welcome and appreciated! Here's how you can contribute:

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Please make sure to update tests as appropriate and adhere to the existing coding style.

License

This library is licensed under the CSSM Unlimited License v2.0 (CSSM-ULv2). See the LICENSE file for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: LicenseRef-CSSM-Unlimited-2.0
  • 更新时间: 2026-02-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固