如何使用RESTAPI插件和PHP连接OpenFire(xmpp)



我正在使用OpenFire来管理我的xmpp服务器,我想使用PHP添加新用户,所以我已经在OpenFire中安装了RESETAPI插件来管理http请求。我也在使用gidkom项目。但是得到一个错误

Parse error: syntax error, unexpected T_VARIABLE in C:wampwwwIMregistration.php on line 12

我的registration.php代码是:

<?php 
if(isset($_POST["User_Name"]) && isset($_POST["Name"]) )
{
$User_ID = $_POST["User_Name"];
$User_Name = $_POST["Name"];
$User_Email = $_POST["Email"];
include "Gidkom/OpenFireRestApi/OpenFireRestApi.php";
// Create the OpenfireUserservice object
$api = new GidkomOpenFireRestApi
// Set the required config parameters
$api->secret = "my keys";
$api->host = "domain.my.org";
$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
$result = $api->addUser($User_ID, 'Password', $User_Name, $User_Email, array('welcome'));
// Check result if command is succesful
if($result['status']) {
    // Display result, and check if it's an error or correct response
    echo 'Success: ';
    echo $result['message'];
} else {
    // Something went wrong, probably connection issues
    echo 'Error: ';
    echo $result['message'];
}



//Add to roster
$api->addToRoster('Administrator', 'admin');
}
else
{
echo 'Error: Something went wrong..... <a href="registration.html">please go back</a> ';
}

我希望页面在openfire中添加一个新用户,并将管理员添加到他的名册中。谢谢

缺少分号。

$api = new GidkomOpenFireRestApiOpenFireRestApi;

错误是由于PHP的过时版本引起的,将PHP更新到最新版本修复了它…

前提条件:必须在您的机器上安装composer.exe

来自cmd.exe然后转到您的web根服务器(htdocs)进入包含其他api源的目录

然后从这个cmd.exe(或创建一个批)

c:/…./….>composer安装

备注:-此commnad(composer安装)必须在同一目录中具有composer.json-该命令(composer install)将创建一个名为的子目录"vendor"

现在必须在index.php的顶部插入以下行:

<?php
include "vendor/autoload.php";
....
and continue your actual program
and is trully must to end the lines with ;
...
?

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

用于Openfire REST API插件的Easy Php REST API客户端,通过向服务器发送REST/HTTP请求来提供管理Openfire实例的能力

有关使用此应用程序的更多信息,请阅读文档。

安装

composer require gnello/php-openfire-restapi

身份验证有两种身份验证方法:

基本HTTP身份验证

$authenticationToken = new GnelloOpenFireRestAPIAuthenticationToken('your_user', 'your_password');

共享密钥

$authenticationToken = new GnelloOpenFireRestAPIAuthenticationToken('your_secret_key');

启动

$api = new GnelloOpenFireRestAPIAPI('your_host', 9090, $authenticationToken);

用户

//Add a new user
$properties = array('key1' => 'value1', 'key2' => 'value2');
$result = $api->Users()->createUser('Username', 'Password', 'Full Name', 'email@domain.com', $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');

打开链接Fore更多

最新更新