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


PHP WHMCS GetProducts用法及代碼示例

檢索符合提供條件的配置產品

注意:此 API 方法旨在用於構建自定義訂單表格。因此,對於給定的產品,隻會返回啟用了“在訂單上顯示”設置的自定義字段。

請求參數

參數 類型 說明 必需的
action string “GetProducts” Required
pid int string 獲取特定的產品 id 配置。可以是逗號分隔的 id 列表
gid int 檢索特定組 ID 中的產品 Optional
module string 使用特定模塊檢索產品 Optional

響應參數

參數 類型 說明
result string 操作結果:成功或錯誤
totalresults int 可用結果總數
startnumber int 返回結果的起始編號
numreturned int 返回的結果數
products array 符合通過條件的產品數組

示例請求 (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' => 'GetProducts',
            // See https://developers.whmcs.com/api/authentication
            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
            'password' => 'SECRET_OR_HASHED_PASSWORD',
            'pid' => '1',
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

示例請求(本地 API)

$command = 'GetProducts';
$postData = array(
    'pid' => '1',
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

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

示例響應 JSON

{
    "result": "success",
    "totalresults": 1,
    "products": {
        "product": [
            {
                "pid": 1,
                "gid": 1,
                "type": "hostingaccount",
                "name": "Best Hosting Plan",
                "slug": "best-hosting-plan",
                "product-url": "https:\/\/www.example.com\/whmcs\/product-group\/best-hosting-plan",
                "description": "This is our best hosting plan, with all the bells and whistles.",
                "module": "cpanel",
                "paytype": "recurring",
                "pricing": {
                    "USD": {
                        "prefix": "$",
                        "suffix": " USD",
                        "msetupfee": "0.00",
                        "qsetupfee": "0.00",
                        "ssetupfee": "0.00",
                        "asetupfee": "0.00",
                        "bsetupfee": "0.00",
                        "tsetupfee": "0.00",
                        "monthly": "25.99",
                        "quarterly": "-1.00",
                        "semiannually": "-1.00",
                        "annually": "-1.00",
                        "biennially": "-1.00",
                        "triennially": "-1.00"
                    }
                },
                "customfields": {
                    "customfield": [
                        {
                            "id": 2,
                            "name": "Secondary Contact",
                            "description": "Would you like to provide a secondary point of contact?",
                            "required": ""
                        }
                    ]
                },
                "configoptions": {
                    "configoption": [
                        {
                            "id": 4,
                            "name": "MultiPHP Services",
                            "type": "3",
                            "options": {
                                "option": [
                                    {
                                        "id": 4,
                                        "name": "Include MultiPHP Options",
                                        "rawName": null,
                                        "recurring": 0,
                                        "required": null,
                                        "pricing": {
                                            "USD": {
                                                "msetupfee": "0.00",
                                                "qsetupfee": "0.00",
                                                "ssetupfee": "0.00",
                                                "asetupfee": "0.00",
                                                "bsetupfee": "0.00",
                                                "tsetupfee": "0.00",
                                                "monthly": "2.99",
                                                "quarterly": "0.00",
                                                "semiannually": "0.00",
                                                "annually": "0.00",
                                                "biennially": "0.00",
                                                "triennially": "0.00"
                                            }
                                        }
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        ]
    }
}

相關用法


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