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