jestillore/php-openfire-userservice

dev-master 2015-04-24 07:51 UTC

This package is auto-updated.

Last update: 2024-09-06 08:40:06 UTC


README

Openfire Userservice PHP 封装

require "jestillore/php-openfire-userservice": "dev-master"

use Jestillore\PhpOpenfireUserservice\PHPOpenfireUserservice;

$us = new PHPOpenfireUserservice;
$us->setEndpoint('http://example.com:9090/plugins/userService');

有两种可用的授权类型

  • HTTP Basic 身份验证
  • 共享密钥

要使用 HTTP Basic 身份验证

$us->setAuthType(PHPOpenfireUserservice::AUTH_BASIC)
   ->setUsername('username')
   ->setPassword('password');

要使用共享密钥

$us->setAuthType(PHPOpenfireUserservice::AUTH_SHARED_KEY)
   ->setSharedKey('thisisthesharedkey');

获取所有用户

$us->getAllUsers();

返回用户数组

[
    {
        "username": "user1",
        "name": "User One",
        "properties": []
    },
    {
    	"username": "user2",
    	"name": "User Two",
    	"properties": []
    }
]

获取用户信息

$us->getUser('username');

返回用户对象

{
    "username": "user1",
    "name": "User One",
    "email": "user@one.com",
    "properties": []
}

创建用户

$user1 = array(
    'username' => 'user1',
    'password' => 'password1'
);

$user2 = array(
    'username' => 'user2',
    'password' => 'password2',
    'name' => 'User Two',
    'email' => 'user@two.com'
);

$res1 = $us->createUser($user1);
$res2 = $us->createUser($user2);

返回 Response 类的实例。

if($res1->isSuccess()) {
    // account created successfully
}
else {
    // account was not created
    $res1->getMessage(); // information about the error
}

删除用户

$res = $us->deleteUser('username');
if ($res->isSuccess()) {
    // account deleted
}
else {
    // account not deleted
}

更新用户

$user = array(
    'password' => 'password1'
);
$res = $us->updateUser($user);
if($res->isSuccess()) {
    // account updated
}
else {
    // account not updated
}

锁定用户

$res = $us->lockUser('username');
if($res->isSuccess()) {
    // account locked
}
else {
    // account not locked
}

解锁用户

$res = $us->unlockUser('username');
if($res->isSuccess()) {
    // account unlocked
}
else {
    // account not unlocked
}

获取用户组

$groups = $us->getUserGroups('jestillore');

返回组数组

[
    "group1",
    "group2"
]

将用户添加到组中

$groups = array(
	'group1',
	'group2'
);
$res = $us->addUserToGroups('username', $groups);
if($res->isSuccess()) {
    // user added to groups
}
else {
    // user not added to groups
}

待办事项

  • 从组中删除用户
  • 通过属性获取用户
  • 获取罗列表
  • 添加罗列表条目
  • 删除罗列表条目
  • 更新罗列表条目