當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP WHMCS TriggerNotificationEvent用法及代碼示例

觸發自定義通知事件。

請求參數

參數 類型 說明 必需的
action string “TriggerNotificationEvent” Required
notification_identifier string 唯一標識符字符串,在製定通知規則時用作條件。 Optional
title string 通知的標題 Optional
message string 通知的消息正文 Optional
url string 通知的後續 URL Optional
status string 通知的狀態說明 Optional
statusStyle string 通知狀態的格式樣式,目前支持“success”, “danger”, and “info” Optional
attributes array 要包含在通知中的屬性數組。至少需要 labelvalue 參數。其他參數是可選的。請參閱 WHMCS\Notification\NotificationAttribute。 Optional

響應參數

參數 類型 說明
result string 操作結果:成功或錯誤

示例請求 (CURL)

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
    http_build_query(
        array(
            'action' => 'TriggerNotificationEvent',
            // See https://developers.whmcs.com/api/authentication
            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
            'password' => 'SECRET_OR_HASHED_PASSWORD',
            'notification_identifier' => 'custom.server.add',
            'title' => 'New Server Added',
            'message' => 'new-server.examplehost.com added as a cPanel server and is available for provisioning.',
            'url' => 'https://whmcs.example.test/admin/configservers.php?action=manage&id=3',
            'status' => 'Success',
            'statusStyle' => 'info',
            'attributes[0][label]' => 'example',
            'attributes[0][value]' => 'example',
            'attributes[0][url]' => 'https://whmcs.example.test/admin/configservers.php?action=manage&id=3',
            'attributes[0][style]' => 'success',
            'attributes[0][icon]' => 'example',
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

示例請求(本地 API)

$command = 'TriggerNotificationEvent';
$postData = array(
    'notification_identifier' => 'custom.server.add',
    'title' => 'New Server Added',
    'message' => 'new-server.examplehost.com added as a cPanel server and is available for provisioning.',
    'url' => 'https://whmcs.example.test/admin/configservers.php?action=manage&id=3',
    'status' => 'Success',
    'statusStyle' => 'info',
    'attributes[0][label]' => 'example',
    'attributes[0][value]' => 'example',
    'attributes[0][url]' => 'https://whmcs.example.test/admin/configservers.php?action=manage&id=3',
    'attributes[0][style]' => 'success',
    'attributes[0][icon]' => 'example',
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

$results = localAPI($command, $postData, $adminUsername);
print_r($results);

示例響應 JSON

{
    "result": "success"
}

錯誤響應

可能的錯誤條件響應包括:

  • API 通知事件需要傳遞一個標識符字符串。
  • API 通知事件需要提供標題。
  • API 通知事件需要提供消息。

相關用法


注:本文由純淨天空篩選整理自whmcs.com大神的英文原創作品 TriggerNotificationEvent。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。