我在外部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"];
}
?>
收到错误
结果=错误;消息=无效的IP 。 。 。
我已在常规设置中添加了IP - &gt;安全选项卡。
注意:我在localhost(xampp)
上尝试此操作我在这里缺少什么?
答案 0 :(得分:1)
此错误表示API Access Key尚未成功添加到configuration.php文件中。请参考上面的步骤7。 $ api_access_key行应在结束前进行?&gt;标签
您也可以按照
将IP列入白名单设置&gt;常规&gt;安全&gt; API IP访问限制
答案 1 :(得分:0)
如果你有一个关于whmcs的帐户,你必须列出你想要访问api的IP地址。它是whmcs团队使用的一种安全措施,以免未经授权的用户使用api。我希望这是有帮助的。谢谢
答案 2 :(得分:0)
或者,可以配置访问密钥以允许绕过IP限制。
它的工作原理是在WHMCS configuration.php文件中定义一个密钥/密码,然后将其传递给所有API调用。要对其进行配置,请将以下行添加到根WHMCS目录中的configuration.php文件中。
var array = [1,2,3,4,5,6,7,8,9,10];
for (var i = 0; i < array.length; i++)
{
if (array[i] == '3'){
function tfunc1(){
function tfunc2(){
return new Promise(function(resolve, reject){
setTimeout(function(){ // lets suppose that there is some async work here
var tsomeData = 'TsomeData';
resolve(tsomeData);
reject(console.log('tfunc4 ERROR'));
}, 2000);
});
}
// promises:
tfunc2().then(function(tsomeData)
{
return afunc2(tsomeData);
}).then(function({tsomeData, asomeData})
{
return after(tsomeData, asomeData);
}).catch(function()
{
console.log(err);
});
}
}
if (array[i] == '6'){
function afunc1(){
function afunc2(tsomeData){
return new Promise(function(resolve, reject){
setTimeout(function(){ // lets suppose that there is some async work here
var asomeData = 'AsomeData';
resolve({tsomeData : tsomeData, asomeData : asomeData});
reject(console.log('afunc4 ERROR'));
}, 2000);
});
}
}
}
// I need to work with tsomeData here - how to pass it here?
// I need to work with asomeData here - how to pass it here?
// tsomeData + asomeData mutating:
function after(tsomeData, asomeData){
return new Promise(function(resolve, reject){
setTimeout(function(){ // lets suppose that there is some async work here
var newData = tsomeData + asomeData;
resolve(console.log(newData));
reject(console.log('after ERROR'));
}, 2000);
});
}
}
在引入API访问密钥后,您可以将其包含在API请求中,如下所示:
$api_access_key = 'secret_key_passphrase_goes_here';