【问题标题】:Openfire RestAPI for PHP Configuration用于 PHP 配置的 Openfire RestAPI
【发布时间】:2017-02-08 14:36:48
【问题描述】:

我正在尝试使用来自 Github 的 RestAPI 连接到我的 Openfire 服务器

现在我已经在 Openfire 文件夹中安装了 RestAPI 插件。 我在 Centos 7 上。

    <?php

include "vendor/autoload.php";

$api = new \Gnello\OpenFireRestAPI\API();

//Set the required config parameters
$api->Settings()->setSecret("YWRtaW46YWRtaW4");
$api->Settings()->setHost("localhost");
$api->Settings()->setServerName("localhost");

//Default values
$api->Settings()->setPort("9090");
$api->Settings()->setSSL(false);
$api->Settings()->setPlugin("/plugins/restapi/v1");

现在当我尝试连接时显示错误:

if($result['response']) {
    echo $result['output'];
} else {
    echo 'Error!';
}

在 httpd 日志中它说 undefined $result 这很明显。

但我按照其存储库中提到的步骤进行操作。

谁能指导我如何使用它?

#Udated

    include "vendor/autoload.php";

$api = new \Gnello\OpenFireRestAPI\API();

//Enable debug mode
$api->Settings()->setDebug(true);
$requests = \Gnello\OpenFireRestAPI\Debug\Request::getRequests();

//var_dump($api);

//var_dump($requests);

$result = $api->users();
//var_dump($api);

$username ="test2";
$results = $api->getuser($username); 


 if($result['response']) 
    { 
        echo $result['output']; 
    } 
else 
    { 
        echo 'Error!'; 
    }

【问题讨论】:

  • 在开发过程中,您可能需要访问一些通常不可用的软件执行信息。为此,只需像这样启用调试模式 //Enable debug mode $api->Settings()->setDebug(true);
  • 我尝试启用调试模式,但不好:(它没有在屏幕上显示任何内容@JYoThI
  • 你必须执行任何操作然后得到这样的 $results //添加一个新用户 $properties = array('key1' => 'value1', 'key2' => 'value2'); $result = $api->Users()->createUser('用户名', '密码', '全名', 'email@domain.com', $properties); if($result['response']) { echo $result['output']; } else { echo '错误!'; }
  • 简单 $results = $api->getuser($username);然后现在检查 if($result['response']) { echo $result['output']; } else { echo '错误!'; }
  • $results = $api->Settings()->setPlugin("/plugins/restapi/v1"); f($result['response']) { echo $result['output']; } else { echo '错误!'; }

标签: php openfire


【解决方案1】:

https://github.com/gnello/php-openfire-restapi

用于 Openfire REST API 插件的简易 PHP REST API 客户端,它提供了通过向服务器发送 REST/HTTP 请求来管理 Openfire 实例的能力

有关使用此应用程序的更多信息,请阅读文档。

安装

composer require gnello/php-openfire-restapi

身份验证 有两种认证方式:

基本 HTTP 身份验证

$authenticationToken = new \Gnello\OpenFireRestAPI\AuthenticationToken('your_user', 'your_password');

共享密钥

$authenticationToken = new \Gnello\OpenFireRestAPI\AuthenticationToken('your_secret_key');

开始

$api = new \Gnello\OpenFireRestAPI\API('your_host', 9090, $authenticationToken);

用户

//Add a new user
$properties = array('key1' => 'value1', 'key2' => 'value2');
$result = $api->Users()->createUser('Username', 'Password', 'Full Name', 'email@domain.com', $properties);

//Delete a user
$result = $api->Users()->deleteUser('Username');

//Ban a user
$result = $api->Users()->lockoutUser('Username');

//Unban a user
$result = $api->Users()->unlockUser('Username');

然后打印结果。

打开更多链接。 https://github.com/gnello/php-openfire-restapi

【讨论】:

    猜你喜欢
    • 2015-05-26
    • 2016-04-12
    • 1970-01-01
    • 2020-06-29
    • 1970-01-01
    • 2016-09-18
    • 2019-01-29
    • 1970-01-01
    • 2013-05-04
    相关资源
    最近更新 更多