【问题标题】:How to use WHMCS Local api (internal API)如何使用WHMCS Local api(内部API)
【发布时间】:2019-09-26 13:42:07
【问题描述】:

如何使用 WHMCS LocalAPI (InternaAPI)

嗨 我在使用 WHMCS LocalAPI 时遇到问题 WHMCS 文档非常差,并且不清楚这个问题 当我运行此代码时,会出现一个空白页面并且发生任何事情

<?php
require('../init.php');
require('../includes/api.php');
$command = 'AddOrder';
$postData = array(
    'clientid' => '1',
    'domain' => array('domain1.com'),
    'billingcycle' => array('annually'),
    'domaintype' => array('register',),
    'regperiod' => array(1),
    'nameserver1' => 'ns1.demo.com',
    'nameserver2' => 'ns2.demo.com',
    'paymentmethod' => 'zarinpalgw',
);
$adminUsername = 'myadminname'; // Optional for WHMCS 7.2 and later

$results = localAPI($command, $postData, $adminUsername);
print_r($results);


?>

我希望在运行此代码后添加订单 外部 API 非常慢,由于某些原因不适合我,例如 我有一个动态 IP 和外部 API 与静态 IP 一起使用,因为 IP 必须在 WHMCS->General setting->Security

中识别

【问题讨论】:

    标签: api whmcs


    【解决方案1】:

    您示例中的Internal API 代码看起来应该可以工作。暂时启用 PHP 错误可以帮助缩小此问题的确切原因 (Setup > General Settings > Other > Display Errors),尽管我相信这是由于您在 PHP 文件中初始化 WHMCS 环境的方式。

    WHMCS 提供了有关构建自定义页面的特定指南,这似乎是您在提供的示例中尝试执行的操作。自定义 PHP 文件必须位于根 WHMCS 目录中,但是 require('../init.php'); 表示您的脚本当前位于子目录中。您也不应该需要 api.php,因为它已经由 init.php 处理。 将您的脚本移动到 WHMCS 根目录并注释掉 require('../includes/api.php'); 行应该有望解决空白页问题。

    请注意:您提供的示例不显示正常的 WHMCS 客户端界面,也不检查用户是否已登录。如果这也是您需要的功能,您可以创建与本机 WHMCS 客户区页面具有相同界面和功能的页面。以下是 WHMCS 在其creating client area pages 指南中提供的示例代码的略微修改版本:

    <?php
    
    // Define WHMCS namespaces
    use WHMCS\ClientArea;
    use WHMCS\Database\Capsule;
    
    // Initialize WHMCS client area
    define('CLIENTAREA', true);
    require __DIR__ . '/init.php';
    $ca = new ClientArea();
    $ca->setPageTitle('Your Page Title Goes Here');
    $ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
    $ca->addToBreadCrumb('mypage.php', 'Your Custom Page Name');
    $ca->initPage();
    
    // Uncomment to require a login to access this page
    //$ca->requireLogin();
    
    // Uncomment to assign variables to the template system
    //$ca->assign('variablename', $value);
    
    // Code to run when the current user IS logged in
    if ($ca->isLoggedIn()) {
        $clientName = Capsule::table('tblclients')->where('id', '=', $ca->getUserID())->pluck('firstname');
        $ca->assign('clientname', $clientName);
    
    // Code to run when the current user is NOT logged in
    } else {
        $ca->assign('clientname', 'Random User');
    }
    
    // Setup the primary and secondary sidebars
    Menu::addContext();
    Menu::primarySidebar('announcementList');
    Menu::secondarySidebar('announcementList');
    
    // Define the template filename to be used (without the .tpl extension)
    $ca->setTemplate('mypage');
    
    // Display the contents of the page (generated by the Smarty template)
    $ca->output();
    

    【讨论】:

    • 非常感谢。您的信息解决了我的问题。
    • 明白,很高兴能为您提供帮助。如果您觉得我的回答充分解决了您的问题,能否将其标记为已接受?如果没有,不用担心......我只是想确保你理解这个过程。更多信息在这里:stackoverflow.com/help/someone-answers
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多