Posted on

whmcs插件开发完全手册

whmcs是一款主机自动销售软件,用php开发,可销售虚拟主机、vps、独立服务器,可以自动收费和开通服务。另外一个用途是可出售虚拟服务,例如ss服务。
whmcs的插件有4种类型:产品和服务插件、系统扩展插件、域名注册插件和支付网关插件。我们主要关注前2个类型。

产品和服务插件:

插件的核心功能是创建, 暂停, 开通, 和终止产品. 这些功能的触发条件是下面的事件:

  • 新订单付款
  • 订单到期
  • 到期付费
  • 取消操作

WHMCS 插件可以实现下面的功能:

  • 自动密码重置
  • 升级和降级
  • 更新
  • 后台链接
  • 客户后台输出
  • 自定函数可以实现更多

文件目录:插件存放在/modules/servers/目录下。

配置选项:

用来设置每一个产品。函数用yourmodulename_ConfigOptions命名。
支持下面的类型:

  • Text
  • Password
  • Yes/No Checkboxes
  • Dropdown Menus
  • Radio Buttons
  • Text Areas

元数据参数:

有以下参数可设置
DisplayName
APIVersion
RequiresServer
DefaultNonSSLPort
DefaultSSLPort
ServiceSingleSignOnLabel
AdminSingleSignOnLabel

支持函数:

这是产品服务插件所有可包含函数的概览。函数是可选的,如果不应用可以不包含。 所有的函数必须有前缀filename_后接函数名. 函数名包含下面的:

CreateAccount

This function runs when a new product provisions. This can be by WHMCS upon checkout or payment for a new order. Also, by an admin user from the Products/Services tab in a clients profile of the admin area.

SuspendAccount

This function runs when a suspension is requested. Requested by the WHMCS Cron when a product becomes overdue, or by admin user in the Client Profile.

UnsuspendAccount

This function runs when an unsuspension is requested. Requested upon payment of an overdue invoice for a product.

TerminateAccount

This function runs when a termination is requested. Requested by the WHMCS Cron for long overdue products when enabled (Automation Settings). Also requested by an admin user in the Client Profile.

Renew

This function runs each time a renewal invoice for a product becomes paid.

ChangePassword

This function runs as a client requests a password change. The option will not show up if the function is not defined in the module. The status of the product must also be active. Admins can also invoke this command from the admin area.

ChangePackage

This function runs for upgrading and downgrading of products. This function runs when an upgrade or downgrade order placed by the client becomes paid. Admins can also invoke this from the product management pages. The same function runs for upgrades and downgrades of both products and configurable options.

ClientArea

This function can be used to define module specific client area output. It accepts a return of HTML for display on the product details page of the client area. Output via a template file within the module folder named “clientarea.tpl” is also possible. Discussion of this function in more detail later on in the docs.

AdminArea

Used to define HTML code that displays on server configuration page (Setup > Products/Services > Servers). Used to provide an automated shortcut/login link to the integrated server control panel.

Used to define HTML code to link to the customers account on a server control panel. Displayed on the product management page of the admin area. The return must be HTML output or link (no forms).

ClientAreaCustomButtonArray

Used to define custom functions that your module supports. Customers can invoke and run these from the client area. The functions can perform actions or product page output in the client area. Example usages for this are to provide product management pages, bandwidth reporting pages, etc…

ClientAreaAllowedFunctions

Like the above, used to define custom functions. Customers can invoke, but are not shown as buttons by default (i.e. custom client area output will invoke them).

AdminCustomButtonArray

Used to define custom functions in your module for admin users. This can contain more functions than the client area equivalent.

UsageUpdate

Used to perform a daily import of the disk and bandwidth usage from a server. The data imported is then used to display the usage stats both within the client and admin areas of WHMCS. The data is also used in disk and bandwidth overage billing calculations if enabled for a product.

AdminServicesTabFields

Used to define extra fields or output to display within admin product pages.

AdminServicesTabFieldsSave

Used in conjunction with the above. This function handles the values submitted in any custom fields when a save occurs.

插件参数:

插件参数是引用时传给每个函数的数据/值。每一个插件函数收到同样的参数. 这些参数提供关于插件命令运行的特定产品/服务的信息。参数也包含了产品自己的设置。
产品服务插件示例代码:https://github.com/WHMCS/sample-provisioning-module

附加插件:

附加插件允许你创建管理员页面和钩子去扩展whmcs功能。
附加插件可以仅包含管理页面, 仅钩子或者都包含。她们都可以通过Setup > Addon Modules界面管理。
一旦激活,插件将显示在附加菜单可以在后台随时访问。
管理选项包含激活和停止插件。 访问控制允许决定哪一个管理角色可以访问插件。

上手:

插件放在/modules/addons/目录下,/your_module_name/ 目录是你的插件目录,核心插件your_module_name.php应该放在此目录下。

配置:

第一步是配置插件,包含插件名, 版本, 作者, 描述。同样也有自定义配置项。

安装和卸载:

插件可以包含激活和停止函数。 这些函数当管理员激活或者停止时运行。
这些函数可以用来运行任何代码当激活或者停止函数时。例如,创建自定义表, 数据库语句,或者授权检查. 也可以用来返回消息或者错误。
当插件运行时已经有了一个数据库连接,所以连接到WHMCS 数据库你不需要再新建连接。

-end-