Openfire:添加订阅状态为 "both" 的用户

Openfire: Add user with subscription status as "both"

我在使用 RestApi

添加用户时遇到问题
include "vendor/autoload.php";
$api = new Gidkom\OpenFireRestApi\OpenFireRestApi;
$api->secret = "mySecretKey";
$api->host = "HostName";
$api->port = "9090";
$api->useSSL = false;
$api->plugin = "/plugins/restapi/v1";  // plugin 

为了将用户添加到花名册,我使用以下代码

$jid="xyz@domainname";
//Add to roster
$data=$api->addToRoster("abc", $jid);

指向 OpenFireRestApi.php 的函数确实具有名为 addToRoster

的函数
 /**
     * Adds to this OpenFire user's roster
     *
     * @param   string          $username       Username
     * @param   string          $jid            JID
     * @param   string|false    $name           Name         (Optional)
     * @param   int|false       $subscription   Subscription (Optional)
     * @return  json|false                     Json with data or error, or False when something went fully wrong
     */
    public function addToRoster($username, $jid, $name=false, $subscription=false)
    {
        $endpoint = '/users/'.$username.'/roster';
        return $this->doRequest('post', $endpoint, compact('jid','name','subscription'));
    }

所以我用过

$data=$api->addToRoster("abc", $jid,"DummyName",3);

其中 3 是订阅类型,因为 both = 3 即 mentioned.

但是当我添加用户时,订阅类型仅显示为 none

UPDATE

我开始了解 subscription plugin

所以我已经安装插件配置了

插件本身说它会自动订阅两种方式。

之后我又尝试了

$data=$api->addToRoster("abc", $jid);

哪些方面可以正常工作,但订阅又是 none

如有任何帮助,我们将不胜感激。

php-openfire-restapi

有问题

需要更改参数名称 所以做以下更改:

//Add to roster
$username = "username in which you want to add roster";
$jid = "another users JID";
$nickname= "nick name of another user";
$subscription ="3";
$result = $api->addToRoster($username, $jid,$nickname,$subscription);

并更改 /src/Gidkom/OpenFireRestApi/OpenFireRestApi.php 文件中的以下行

public function addToRoster($username, $jid, $name=false, $subscription=false)
    {
        $nickname=$name;
        $subscriptionType=$subscription;
        $endpoint = '/users/'.$username.'/roster';
        return $this->doRequest('post', $endpoint, compact('jid','nickname','subscriptionType'));
    }

这里我更改了参数名称。

祝你好运。