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


PHP WHMCS AddProduct用法及代碼示例

將產品添加到係統以供購買

請求參數

參數 類型 說明 必需的
action string “AddProduct” Required
name string 要添加的產品名稱 Required
gid int 添加產品的產品組的id Required
slug string 產品的友好名稱。如果不提供將生成。 Optional
type string ‘hostingaccount’, ‘reselleraccount’, ‘server’ or ‘other’ 之一 Optional
stockcontrol bool 設置為 true 以啟用產品的庫存控製 Optional
qty int 該產品有多少庫存 Optional
paytype string 產品的支付類型。 ‘free’, ‘onetime’, ‘recurring’ 之一 Optional
hidden bool 產品是否應該從客戶訂單中隱藏 Optional
showdomainoptions bool 產品是否應顯示域注冊選項。 Optional
tax bool 稅收是否適用於產品。 Optional
isFeatured bool 產品是否應該出現在產品組中。 Optional
proratabilling bool 是否為此產品啟用了pro-rata 計費。 Optional
description string 要在購物車中的產品列表上顯示的產品說明 Optional
shortdescription string 在購物車的特定區域顯示的產品的簡短說明。 Optional
tagline string 在購物車的特定區域顯示的產品標語。 Optional
color string 與購物車特定區域中的產品相關聯的顏色。 Optional
welcomeemail int 用作歡迎電子郵件的電子郵件模板的 ID。僅限產品/服務消息 Optional
proratadate int 參看https://docs.whmcs.com/Products_and_Services#Pricing_Tab Optional
proratachargenextmonth int 參看https://docs.whmcs.com/Products_and_Services#Pricing_Tab Optional
subdomain string 要在域注冊頁麵上提供的子域的逗號分隔列表。例如:.domain1.com,.domain2.com Optional
autosetup string 何時應自動設置產品。 “(從不)、‘on’(待定訂單)、‘payment’(付款時)、‘order’(訂單中)之一 Optional
module string 要與產品關聯的服務器模塊係統名稱。例如:cpanel、autorelease、plesk Optional
servergroupid int 用於產品創建的服務器組 ID 以關聯適當的服務器 Optional
configoption1 mixed 第一個模塊配置值 Optional
configoption2 mixed 第二個模塊配置值 Optional
configoption3 mixed 第三個模塊配置值 Optional
configoption4 mixed 第四個模塊配置值 Optional
configoption5 mixed 第五個模塊配置值 Optional
configoption6 mixed 第六模塊配置值 Optional
order int 在訂單表格上顯示的順序 Optional
pricing array 與產品關聯的定價數組。格式:$pricing[currencyid][cycle]。請參見示例。 Optional
recommendations array 與產品關聯的推薦數組,格式如下:‘id’ => productid, ‘order’ => integer Optional

響應參數

參數 類型 說明
result string 操作結果:成功或錯誤
pid int 新創建產品的id

示例請求 (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' => 'AddProduct',
            // See https://developers.whmcs.com/api/authentication
            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
            'password' => 'SECRET_OR_HASHED_PASSWORD',
            'type' => 'other',
            'gid' => '1',
            'name' => 'Sample Product',
            'welcomeemail' => '5',
            'paytype' => 'recurring',
            'pricing' => array(2 => array('monthly' => 8.00, 'annually' => 80.00)),
            'recommendations' => array(array('id' => 1, 'order' => 0), array('id' => 2, 'order' => 1)),
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

示例請求(本地 API)

$command = 'AddProduct';
$postData = array(
    'type' => 'other',
    'gid' => '1',
    'name' => 'Sample Product',
    'welcomeemail' => '5',
    'paytype' => 'recurring',
    'pricing' => array(2 => array('monthly' => 8.00, 'annually' => 80.00)),
    'recommendations' => array(array('id' => 1, 'order' => 0), array('id' => 2, 'order' => 1)),
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

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

示例響應 JSON

{
    "result": "success"
}

錯誤響應

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

  • 您必須提供產品名稱
  • 您必須提供有效的產品組 ID
  • 您必須提供有效的歡迎電子郵件 ID
  • 產品類型無效。必須是“hostingaccount”, “reselleraccount”, “server” or “other” 之一
  • 支付類型無效。必須是“free”, “onetime” or “recurring” 之一
  • 無效的自動設置值。必須是“”之一,“on”, “order” or “payment”
  • 顏色必須是有效的十六進製值。
  • 推薦產品 ID 無效。這必須是現有的產品 ID。

相關用法


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