douyun1950 2016-09-30 05:34
浏览 163

用于PHP配置的Openfire RestAPI

I am trying to connect to my Openfire Server using RestAPI from Github

Now I have installed RestAPI plugin in Openfire folder. I am on 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");

Now WhenI try to connect it shows error:

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

In httpd logs it says undefined $result which is obvious.

But I followed the steps as it were mentioned on its repository.

Can Any One please guide me how to use this ?

#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!'; 
    }
  • 写回答

1条回答 默认 最新

  • dongshi4078 2018-01-12 05:30
    关注

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

    Easy Php REST API Client for the Openfire REST API Plugin which provides the ability to manage Openfire instance by sending an REST/HTTP request to the server

    Please read documentation for further information on using this application.

    Installation

    composer require gnello/php-openfire-restapi
    

    Authentication There are two ways to authenticate:

    Basic HTTP Authentication

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

    Shared secret key

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

    Start

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

    Users

    //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');
    

    Then print Result.

    Open Link Fore more. https://github.com/gnello/php-openfire-restapi

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘