首先確保你的openfire已安裝restapi
在openfire后臺管理->插件管理中下載并啟用restapi
部署以后默認是沒有開啟的,你需要到后臺開啟并且設置驗證碼(即為secret),為了確保安全你也許還要設置一個安全的ip
引入php-openfire-restapi
的代碼
在
github
上的托管地址:https://github.com/gidkom/php-openfire-restapi
使用composer
方式引入類
composer require "gidkom/php-openfire-restapi:dev-master"
可以在Gidkom\OpenFireRestApi\OpenFireRestApi
類中配置默認屬性
class OpenFireRestApi
{
public $host = 'xmpp.xxxxxx.net';
public $port = '9090';
public $plugin = '/plugins/restapi/v1';
public $secret = 'xxxxxxxx';
public $useSSL = false;
protected $params = array();
public $client;
/////////
}
或者實例化對象后,重新定義屬性
include "vendor/autoload.php";
$api = new Gidkom\OpenFireRestApi\OpenFireRestApi;
// 設置必須的配置項參數(shù)
$api->secret = "MySecret";
$api->host = "jabber.myserver.com";
$api->port = "9090"; // default 9090
// 可選的參數(shù) (沒有設置為默認值)
$api->useSSL = false;
$api->plugin = "/plugins/restapi/v1"; // plugin
// 創(chuàng)建一個新用戶
$result = $api->addUser('Username', 'Password', 'Real Name', 'Email', array('Group 1'));
//刪除一個用戶
$result = $api->deleteUser($username);
//禁用一個用戶
$result = $api->lockoutUser($username);
//啟用一個用戶
$result = $api->unlockUser($username);
/**
* 更新用戶信息
*
* The $password, $name, $email, $groups arguments are optional
*
*/
$result = $api->updateUser($username, $password, $name, $email, $groups)
// 添加到名冊中
$api->addToRoster($username, $jid);
// 從名冊中刪除
$api->addToRoster($username, $jid);
// 更新名冊的用戶信息
$api->updateRoster($username, $jid, $nickname, $subscription);
// 獲取所有組
$api->getGroup();
// 獲取某組信息
$api->getGroup($name);
// 創(chuàng)建一個組
$api->createGroup($group_name, $description);
// 更新某組的描述
$api->updateGroup($group_name, $description);
// 刪除某組
$api->deleteGroup($group_name);