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 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line