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


PHP WHMCS AddClient用法及代碼示例

添加客戶端。

請求參數

參數 類型 說明 必需的
action string “AddClient” Required
owner_user_id int 應該擁有客戶端的用戶的 ID。可選的。如果未提供,將創建一個新用戶。 Optional
firstname string 要創建的客戶的名字。當未指定owner_user_id 時,也用於用戶的名字。 Required
lastname string 要創建的客戶的姓氏。當未指定owner_user_id 時,也用於用戶的姓氏。 Required
companyname string Optional
email string 要創建的客戶的電子郵件地址。當未指定owner_user_id 時,也用於用戶的電子郵件。 Required
address1 string Required
address2 string Optional
city string Required
state string Required
postcode string Required
country string 2 個字符的 ISO 國家代碼。 Required
phonenumber string Required
tax_id string 客戶的稅號。 Optional
password2 string 新創建的用戶帳戶的密碼。未指定 owner_user_id 時需要。 Optional
securityqid int tbladminsecurityquestions 中安全問題的 ID。未指定 owner_user_id 時需要。 Optional
securityqans string 新創建用戶的安全問題答案。 Optional
currency int 來自 tblcurrencies 的貨幣 ID。 Optional
groupid int 來自 tblclientgroups 的客戶端組 ID。 Optional
customfields string Base64 編碼的自定義字段值的序列化數組。 Optional
language string 默認語言設置。當未指定owner_user_id 時,也用於用戶的語言。提供全名:‘english’, ‘french’,等等……。 Optional
clientip string 請求的原始 IP 地址。 Optional
notes string 僅管理員注釋。 Optional
marketingoptin bool 客戶是否應該opt-in 來接收營銷電子郵件。 Optional
noemail bool 是否向客戶發送歡迎電子郵件。真正的值不會發送電子郵件。 Optional
skipvalidation bool 是否強製執行必填字段。真值不會強製執行必填字段。當未指定owner_user_id 時,這不適用於emailpassword2 Optional
cardtype string 信用卡類型。提供全名:Visa, Mastercard, American Express, etc....。 Deprecated
cardnum string 信用卡號碼。 Deprecated
expdate string 格式:MMYY。 Deprecated
startdate string 格式:MMYY(如果適用)。 Deprecated
issuenumber string 信用卡發行號(如適用)。 Deprecated
cvv string 信用卡 CVV 號碼(不會被存儲)。 Deprecated

響應參數

參數 類型 說明
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' => 'AddClient',
            // See https://developers.whmcs.com/api/authentication
            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
            'password' => 'SECRET_OR_HASHED_PASSWORD',
            'firstname' => 'John',
            'lastname' => 'Doe',
            'email' => '[email protected]',
            'address1' => '123 Main Street',
            'city' => 'Anytown',
            'state' => 'State',
            'postcode' => '12345',
            'country' => 'US',
            'phonenumber' => '800-555-1234',
            'password2' => 'password',
            'clientip' => '1.2.3.4',
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

示例請求(本地 API)

$command = 'AddClient';
$postData = array(
    'firstname' => 'John',
    'lastname' => 'Doe',
    'email' => '[email protected]',
    'address1' => '123 Main Street',
    'city' => 'Anytown',
    'state' => 'State',
    'postcode' => '12345',
    'country' => 'US',
    'phonenumber' => '800-555-1234',
    'password2' => 'password',
    'clientip' => '1.2.3.4',
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

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

示例響應 JSON

{
    "result": "success",
    "clientid": "1"
}

警告響應

使用已刪除或標記為已棄用的 API 函數時會返回警告響應。我們建議遵循警告中的任何建議操作,以確保未來的兼容性。

可能的警告消息包括:

  • 信用卡相關參數現已棄用,可能會在未來版本中刪除。請改用AddPayMethod。

錯誤響應

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

  • 所有者用戶 ID 無效
  • 你沒有輸入你的名字
  • 你沒有輸入你的姓氏
  • 您沒有輸入您的電子郵件地址
  • 您輸入的電子郵件地址無效
  • 您沒有輸入您的電子郵件地址
  • 您沒有輸入您的地址第 1 行
  • 你沒有進入你的城市
  • 你沒有進入你的州
  • 您沒有輸入郵政編碼
  • 需要有效的國家
  • 你沒有輸入你的電話號碼
  • 電話號碼無效
  • 您沒有提供所需的自定義字段值
  • 使用該電子郵件地址的客戶已經存在
  • 已存在使用該電子郵件地址的用戶

相關用法


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