2016-09-30 120 views
0

我試圖從Openfire的文件夾Github的Openfire RESTAPI爲PHP配置

現在我已經安裝了插件RESTAPI連接到使用RESTAPI我的Openfire服務器。 我在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"); 

現在WhenI嘗試連接它顯示錯誤:

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

在httpd的日誌,它說未定義$結果是顯而易見的。

但我按照它的存儲庫中提到的步驟操作。

任何一個請指導我如何使用它?

#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!'; 
    } 
+0

在開發中,您可能需要訪問一些有用的信息,這些信息通常不可用。爲此,只需啓用調試模式,如下所示: //啓用調試模式 $ api-> Settings() - > setDebug(true); – JYoThI

+0

我試圖啓用調試模式,但沒有好處:(它不顯示任何東西在屏幕上@JYoThI – Rajan

+0

你必須執行任何事情,然後得到像這樣的$結果//添加一個新用戶 $ properties = array('key1'= >'value1','key2'=>'value2'); $ result = $ api-> Users() - > createUser('用戶名','密碼','全名','[email protected]' ,$ properties); if($ result ['response']){ echo $ result ['output']; } else { echo'Error!'; } – JYoThI

回答

1

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

易PHP REST API客戶端對的Openfire 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 protected]', $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'); 

然後打印結果。

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