maniaplanet/php-openfire-restapi

使用Rest Api管理Openfire服务器

dev-master 2017-05-19 17:23 UTC

This package is auto-updated.

Last update: 2024-09-19 09:29:05 UTC


README

A simple PHP class designed to work with Openfire Rest Api plugin. It is used to remote manage the Openfire server. Originally forked from gidkom/php-openfire-restapi.

许可证

php-openfire-restapi遵循MIT风格许可协议,详细信息请参阅LICENCE文件。

需求

  • PHP 5.4+

安装

使用Composer

最简单的安装方式是通过Composer。创建以下composer.json文件,并运行composer.phar install命令进行安装。

{
    "require": {
        "maniaplanet/php-openfire-restapi": "v1.x"
    }
}

用法

初始化

include "vendor/autoload.php";

// Create the Openfire Rest api object
$api = new Maniaplanet\OpenFireRestApi\OpenFireRestApi;

// Set the required config parameters
$api->secret = "MySecret";
$api->host = "jabber.myserver.com";
$api->port = "9090";  // default 9090

// Optional parameters (showing default values)

$api->useSSL = false;
$api->plugin = "/plugins/restapi/v1";  // plugin 

添加新用户

// Add a new user to OpenFire and add to a group
$newUser = new Maniaplanet\OpenFireRestApi\Entity\;
$newUser->username  = 'Username';
$newUser->password  = 'Password';
$newUser->name      = 'Real Name';
$newUser->email     = 'johndoe@domain.com';
$newUser->groups    =  array('Group 1');

$result = $api->createUser($newUser);

// Check result if command is succesful
if($result['status']) {
    echo 'Success: ';
} else {
    // Something went wrong, probably connection issues
    echo 'Error: ';
    echo $result['error'];
}