我在外部API上尝试GetClient密码
<?php
$url = "http://localhost:81/whmcs/includes/api.php"; # URL to WHMCS API file goes here
$username = "admin"; # Admin username goes here
$password = "pass"; # Admin password goes here
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "GetClientPassword";
$postfields["userid"] = "1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);
$data = explode(";",$data);
foreach ($data AS $temp) {
$temp = explode("=",$temp);
$results[$temp[0]] = $temp[1];
}
if ($results["result"]=="success") {
echo "Success<br />
<br />
";
# Result was OK!
} else {
# An error occured
echo "The following error occured: ".$results["message"];
}
?>
得到一个错误
result = error; message =无效的IP ...
我已在常规设置 - >安全选项卡中添加了IP。
注意:我在localhost(xampp)上尝试这个
我在这里错过了什么?
此错误表示API Access Key尚未成功添加到configuration.php文件中。请参考上面的步骤7。 $ api_access_key行应该在结束?>标记之前。
您也可以通过以下方式将您的IP列入白名单
设置>常规>安全性> API IP访问限制
如果您有关于whmcs的帐户,则必须将您要访问API的IP地址列入白名单。这是whmcs团队使用的一种安全措施,以免未经授权的用户使用api。我希望这是有帮助的。谢谢
或者,可以配置访问密钥以允许绕过IP限制。
它的工作原理是在WHMCS configuration.php文件中定义一个密钥/密码,然后将其传递给所有API调用。要对其进行配置,请在根WHMCS目录中的configuration.php文件中添加如下所示的行。
$api_access_key = 'secret_key_passphrase_goes_here';
在引入API访问密钥后,您可以将其包含在API请求中,如下所示:
?action=xxxx&username=xxx&password=xxx&accesskey=secret_key_passphrase_goes_here