How to create a chat room and add users to a room in openfire using PHP

I am new to XMPP server. I want to make a multi-user chat application.

I installed Openfire, and one or one chat is working correctly, but I can not create a conference (chat) room and add users to the room using PHP for multi-user chat.

Although I installed the MUC service plugin available in openfire, I don’t know how to implement MUT Service REST / HTTP with PHP.

Does anyone have an example PHP script for the MUC service to create a chat and add users to the chat room?

Thanks at Advance

+4
source share
1 answer

Help Information Base:

HTTP Basic Authentication

REST HTTP-.

Openfire .

. : : YWRtaW46MTIzNDU = ( : admin/ : 12345)

c = Client.create(); c.addFilter( HTTPBasicAuthFilter (, ));

POST/mucservice/       .

: Chatroom : HTTP- 201 ()

servicename @QueryParam

: : YWRtaW46MTIzNDU =

: Content-Type: application/xml

POST http://example.org:9090/plugins/mucservice/chatrooms

1 ( ):

     1          

PHP- ( MUCservice 0.2.3 Openfire 3.10.0):

function createRoom($naturalName, $roomName, $description) {
    $url = "http://localhost:9090/plugins/mucservice/chatrooms";
    $data = "<chatRoom>
                <naturalName>$naturalName</naturalName>
                <roomName>$roomName</roomName>
                <description>$description</description>
            </chatRoom>";
    $username = "admin";
    $password = "12345";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_PORT, "9090");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($ch, CURLOPT_HTTPHEADER,
                     array('Content-Type: application/xml',
                           'Authorization: Basic '.base64_encode("$username:$password")));
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $res = curl_exec($ch);
    echo "code " . $code;
    print_r($res);
    curl_close($ch);
}

createRoom("room", "room", "room");
+1

All Articles