jobsfav/laravel-whmcs

WHMCS API接口,适用于Laravel 7.0及以上版本

1.2.0 2023-02-02 00:15 UTC

This package is auto-updated.

Last update: 2024-09-04 05:32:45 UTC


README

Latest Stable Version Total Downloads License

这是一个用于与Laravel中的WHMCS API交互的接口。本包深受由Graham Campbell创建的Laravel GitLab启发。

注意

旧版本0.3可以在这里找到

安装

WHMCS API for Laravel需要PHP ^7.4 | ^8.0,至少需要Laravel版本6。

通过Composer安装包。从终端运行Composer require命令

composer require darthsoup/laravel-whmcs

包将通过composer包发现自动安装。如果没有,那么您需要在您的config/app.php中注册DarthSoup\Whmcs\WhmcsService服务提供者。

可选,如果您喜欢使用Facade,可以添加别名

'Whmcs' => DarthSoup\Whmcs\Facades\Whmcs::class

配置

要开始,您需要发布Laravel-Whmcs的供应商资源。

php artisan vendor:publish --provider="DarthSoup\Whmcs\WhmcsServiceProvider"

这将在您的应用中创建config/whmcs.php文件,修改它以设置您的配置。

默认连接

选项default是您指定默认连接的地方。

Whmcs连接

选项connections是您可以添加多个连接到您的whmcs实例的地方。您可以从whmcs中选择API连接类型。这些方法包括passwordtoken。已经包括示例连接,但您可以添加您想要的任何数量的连接。

使用方法

通过依赖注入

如果您更喜欢使用依赖注入,您可以轻松地将它添加到您的控制器中,如下所示

use DarthSoup\Whmcs\WhmcsManager;

class WhmcsController extends Controller
{
    private WhmcsManager $whmcsManager;

    public function __construct(WhmcsManager $whmcsManager)
    {
        $this->whmcsManager = $whmcsManager;
    }

    public function index()
    {
        $result = $this->whmcsManager->client()->getClients();
        dd($result);
    }
}

通过Facade

如果您更喜欢经典的Laravel facade样式,这可能是一种选择

use \DarthSoup\Whmcs\Facades\Whmcs;
# or
use \Whmcs;

\Whmcs::Client()->getClientsDomains(['clientid' => '1']);

真实示例

use \DarthSoup\Whmcs\Facades\Whmcs;

# Obtaining a list of domains purchased by the customer
\Whmcs::Client()->getClientsDomains(['clientid' => '1']);

# Obtaining a list of products purchased by the customer
\Whmcs::Client()->getClientsProducts(['clientid' => '12345']);

# Retrieve a specific invoice
\Whmcs::Billing()->getInvoice(['invoiceid' => '1337']);

# Retrieves all Orders from the system
\Whmcs::Orders()->getOrders();

# Obtain internal users
\Whmcs::Users()->getUsers(['search' => 'foo@bar.org']);

# Custom Method (in case you added custom endpoints) 
\Whmcs::Custom()-><myEndpoint>(['foo' => 'bar']);

有关如何使用WhmcsApi客户端DarthSoup\WhmcsApi\Client类的更多信息,请查看https://github.com/darthsoup/php-whmcs-api上的文档。

支持

请在github上创建一个issue

许可证

本包在MIT许可证下发布。有关详细信息,请参阅捆绑的LICENSE文件。