darthsoup/laravel-whmcs

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

1.2.2 2024-03-20 07:35 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 8。

通过Composer安装该包。请在终端中运行Composer require命令

composer require darthsoup/laravel-whmcs

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

可选,如果您更喜欢使用外观,您可以添加别名

'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);
    }
}

通过外观

如果您更喜欢传统的Laravel外观风格,这可能是一个不错的选择

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上创建一个问题

许可证

此包根据MIT许可证发布。有关详细信息,请参阅附带LICENSE文件。