当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。