dongtong1226 2015-02-26 12:40
浏览 59
已采纳

如何在不实际显示WHMCS的情况下使用WHMCS API?

Is there any way in which i can use the WHMCS API without displaying WHMCS to the clients and users. I want my PHP scripts to first create a WHMCS client, add an order for the client and then copy some files to the client's directory. But i don't want my clients to be able to login to their WHMCS panel or even be able to see the WHMCS

  • 写回答

1条回答 默认 最新

  • doumao6212 2015-02-26 14:23
    关注

    WHMCS has something called External API that will help you.

    Here is the documentation. But for what you need yo should do this:

    Connect to the API

    $url = "http://www.yourdomain.com/includes/api.php"; # URL to WHMCS API file goes here
    $username = "Admin"; # Admin username goes here
    $password = "demoxyz"; # Admin password goes here
    

    Add the Client

    $postfields = array();
    $postfields["username"] = $username;
    $postfields["password"] = md5($password);
    $postfields["action"] = "addclient"; 
    $postfields["firstname"] = "Test";
    $postfields["lastname"] = "User";
    $postfields["companyname"] = "WHMCS";
    $postfields["email"] = "demo@whmcs.com";
    $postfields["address1"] = "123 Demo Street";
    $postfields["city"] = "Demo";
    $postfields["state"] = "Florida";
    $postfields["postcode"] = "AB123";
    $postfields["country"] = "US";
    $postfields["phonenumber"] = "123456789";
    $postfields["password2"] = "demo";
    $postfields["customfields"] = base64_encode(serialize(array("1"=>"Google")));
    $postfields["currency"] = "1";
    
    $query_string = "";
    foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $jsondata = curl_exec($ch);
    if (curl_error($ch)) die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch));
    curl_close($ch);
    
    $arr = json_decode($jsondata); # Decode JSON String
    
    print_r($arr); # Output XML Response as Array
    

    Add the Order

    $postfields = array();
    $postfields["username"] = $username;
    $postfields["password"] = md5($password);
    $postfields["action"] = "addorder";
    $postfields["clientid"] = "1";
    $postfields["pid"] = "1";
    $postfields["domain"] = "whmcs.com";
    $postfields["billingcycle"] = "monthly";
    $postfields["addons"] = "1,3,9";
    $postfields["customfields"] = base64_encode(serialize(array("1"=>"Google")));
    $postfields["domaintype"] = "register";
    $postfields["regperiod"] = "1";
    $postfields["paymentmethod"] = "mailin";
    
    $query_string = "";
    foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $jsondata = curl_exec($ch);
    if (curl_error($ch)) die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch));
    curl_close($ch);
    
    $arr = json_decode($jsondata); # Decode JSON String
    
    print_r($arr); # Output XML Response as Array
    

    Then you can copy the files to the client's directory. Hope it helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀