针对分销商俱乐部的php api集成

针对分销商俱乐部的php api集成,php,html,api,dns,Php,Html,Api,Dns,我需要实现经销商api到我的网站搜索可用的域名,我有经销商id和密钥,所以我使用了下面的代码 <html> <head> </head> <body> <form method="post" action="test.php"> <input type="text" name="domain" value="<?php echo $domainname; ?>"/> <input type

我需要实现经销商api到我的网站搜索可用的域名,我有经销商id和密钥,所以我使用了下面的代码

<html>
<head>
</head>
<body>
<form method="post" action="test.php">
    <input type="text" name="domain" value="<?php echo $domainname; ?>"/>

    <input type="checkbox" name="tld[]" value="com"  <?php  if(!isset($_POST['check'])){  ?> checked="checked" <?php } elseif (in_array("com", $tldarray)) {  ?> checked="checked" <?php  } ?> />com
    <input type="checkbox" name="tld[]" value="net" <?php if (in_array("net", $tldarray)) {  ?> checked="checked" <?php  } ?> />net
    <input type="checkbox" name="tld[]" value="in" <?php if (in_array("in", $tldarray)) {  ?> checked="checked" <?php  } ?> />in
    <input type="checkbox" name="tld[]" value="biz" <?php if (in_array("biz", $tldarray)) {  ?> checked="checked" <?php  } ?> />biz
    <input type="checkbox" name="tld[]" value="org" <?php if (in_array("org", $tldarray)) {  ?> checked="checked" <?php  } ?> />org
    <input type="checkbox" name="tld[]" value="asia" <?php if (in_array("asia", $tldarray)) {  ?> checked="checked" <?php  } ?> />asia


    <input type="submit" name="check" value="Check"/>
</form> 
</body>
</html> 
我的php来了

<?php

$api_user_id="xxx";
$api_key="yyyyyy";


function domainCallAPI($method, $url, $data = false) {
    $curl = curl_init();

    switch ($method) {
        case "POST":
            curl_setopt($curl, CURLOPT_POST, 1);

            if ($data)
                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
            break;
        case "PUT":
            curl_setopt($curl, CURLOPT_PUT, 1);
            break;
        default:
            if ($data)
                $url = sprintf("%s?%s", $url, http_build_query($data));
    }

    // Optional Authentication: - Need not touch this
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_USERPWD, "username:password");
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    return curl_exec($curl);
}
?>

<?php
//Example Call to see available domains and suggestions
$url = '';
$tldarray[] = "";
$domainname="";
if (isset($_POST['check']) && isset($_POST['domain']) && $_POST['domain'] != "" && isset($_POST['tld']) && $_POST['tld'] != "") {

    $domainname = $_POST['domain'];
    $tld = "";
    $i = 0;
    foreach ($_POST['tld'] as $arrayitem) {
        $tld.='&tlds=' . $arrayitem;
        $tldarray[$i] = $arrayitem;
        $i++;
    }

    $url = 'https://test.httpapi.com/api/domains/available.json?auth-userid=' . $api_user_id . '&auth-password=' . $api_key . '&domain-name=' . $domainname . $tld . '&suggest-alternative=true';
    $data = "";
    $data = domainCallAPI('GET', $url, $data);
    $datajson = json_decode($data, TRUE);
    $fulldomainname = "";
    //  $flag=0;
    foreach ($tldarray as $arrayitem) {

        $fulldomainname = $domainname . "." . $arrayitem;
        echo '<br/>' . $fulldomainname;
        if ($datajson[$fulldomainname]["status"] == "available") {
            echo '    Available';
            // $flag=1;
        } else {
            echo '    Not Available <br/>';
        }
    }
    // Domain Suggestions
    $stack = array("");
    $i = 0;
    foreach ($datajson[$domainname] as $sugdomain => $sugtld) {
        // echo $sugdomain.'.'.$tld;

        $stack[$i] = $sugdomain;
        $i++;
    }
    echo '<br/>Sugg names : <br/>';
    $i = 0;
    foreach ($stack as $value) {
        foreach ($datajson[$domainname][$value] as $sugdomain => $sugtld) {
            if ($datajson[$domainname][$value][$sugdomain] == "available") {
                echo $value . '.' . $sugdomain;
                echo '<br/>';
                $i++;
                if ($i == 7) {

                    break;
                }
            }
        }

        if ($i == 7) {

            break;
        }
    }
    // domain suggestions end
}
 elseif (isset($_POST['check'])){

    if(!isset($_POST['tld'])){
      echo '<br/> Tick Your Domain';

    }
     if( !isset($_POST['domain']) || $_POST['domain'] =="" ){
        echo '<br/> Type Domain Name';     
    }else{
        $domainname=$_POST['domain'];
    }
}
?>
它总是显示为api不可用的结果,我不熟悉php或api我只是在网上找到这段代码并使用,请帮助我在这方面

我需要经销商api只是因为我一直在做生意使用经销商俱乐部


我所需要的只是使用分销商api搜索域名。谢谢。

您正在尝试post和put,但它们的API与get一起工作,您可以使用file\u get\u内容或simplexml\u load\u文件发送请求。您需要白名单服务器ip,如果您在本地主机上工作,则需要白名单ISP或静态ip。转到转销商面板>>设置>>下拉式Api将出现。单击Api您将找到添加IP的选项