欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

PHP Chat Client 聊天 客户端 有大用

PHP Chat Client
Learn how to integrate our chat into your PHP website
How to integrate iFlyChat with any PHP based website
Step 1: You can get the iFlyChat PHP library via a composer package called iflychat-php. See https://packagist.org/packages/iflylabs/iflychat-php.
1
$ composer require iflylabs/iflychat-php
Copied!
Or add to composer.json:
1
"require": {
2
   iflylabs/iflychat-php": "^2.0"
3
}
Copied!
and then run composer update.
Or you can clone or download the library files.
We recommend you to use composer.
Step 2: Generate APP ID and API Key from iflychat.com and copy them.
Step 3: Use these credentials in your main php(index) file to create a new iFlyChat instance.
1
2
use Iflylabs\iFlyChat;
3
4
const APP_ID = 'YOUR_APP_ID';
5
const API_KEY = 'YOUR_API_KEY';
6
7
$iflychat = new iFlyChat(APP_ID, API_KEY);
Copied!
Step 4(optional): In case, you want to create a user for the chat, you just need to call the setUser() function with $user array as a parameter.
Example.
1
$user = array(
2
 'user_name' => 'testUser', // string(required)
3
 'user_id' => '2', // string (required)
4
 'is_admin' => FALSE, // boolean (optional)
5
 'user_avatar_url' => 'user-avatar-link', // string (optional)
6
 'user_profile_url' => 'user-profile-link', // string (optional)
7
);
8
9
$iflychat->setUser($user);
Copied!
Step 5: Now, you need to include iFlyChat HTML code in your website. As an example, check out basic-example.php (inside iflychat-php/examples folder). To do so, add the following line of code before printing anything on the webpage:
1
$iflychat_code = $iflychat->getHtmlCode();
Copied!
Step 6: Make sure to use the above code before printing any content via PHP, otherwise you will get an error. Next, use the following code anywhere in your PHP file (preferably before body tag ends) to render the chat:
1
<html>
2
<head>
3
</head>
4
<body>
5
<h1>How to include iFlyChat in your PHP website?</h1>
6
7
<!-- iFlyChat Engine Code Begins -->
8
<?php print $iflychat_code; ?>
9
<!-- iFlyChat Engine Code Ends -->
10
11
</body>
12
</html>

来自  https://docs.iflychat.com/installation/php-chat-client


普通分类: