# Think Chat
**Repository Path**: yg178/Think-Chat
## Basic Information
- **Project Name**: Think Chat
- **Description**: ✉️ Think Chat是使用ThinkPHP5和GatewayWorker实现的在线Web聊天项目
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 3
- **Created**: 2025-11-25
- **Last Updated**: 2025-11-25
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
### ✉️ 1.项目需求分析
1.文字发送
2.表情发送
3.图片发送
4.消息群发
5.对方在线状态及时更新
6.未读消息以及条数显示
7.聊天记录持久化
### 📜 2.项目结构
```
project 应用部署目录
├─application 应用目录(可设置)
├─extend 扩展类库目录(可定义)
├─public WEB 部署目录(对外访问目录)
├─runtime 应用的运行时目录(可写,可设置)
├─vendor 第三方类库目录(Composer)
├─thinkphp 框架系统目录
├───build.php 自动生成定义文件(参考)
├───composer.json composer 定义文件
├───LICENSE.txt 授权说明文件
├───README.md README 文件
├───think 命令行入口文件
```
### 🔧 3.部署项目
#### Apache部署
```
ServerName chat.com
ServerAlias chat.com
DocumentRoot Your Project Dir\public
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
```
#### Nginx部署
```
server
{
listen 80;
server_name your server_name;
index index.php index.html index.htm default.php default.htm default.html;
root Your Your Project Dir/public;
...
}
```
### ⚡️ 4.启动GatewayWorker
#### Linux启动
```
cd vendor/GatewayWorker-for-win
php start.php start -d
```
#### Windows 启动
```
click start_for_win.bat
```
### 🧪 5 方法分析
#### 5.1 用户列表
HTTP Request
>GET ../index/index/lists?fromid=86
请求参数
参数 | 数据类型 | 描述
:---- | :--- | :---
id | Int | 发件人id
```
public function lists(){
...
}
```
#### 5.2 会话界面
HTTP Request
>GET ../index/index/index?fromid=86&toid=85
请求参数
参数 | 数据类型 | 描述
:---- | :--- | :---
fromid | Int | 发件人id
toid | Int | 收件人id
```
public function index()
{
...
}
```
#### 5.3 客户连接到GatewayWorker
> ../vendeor/GatewayWorker-for-win/Application/YourApp/Events.php
请求参数
参数 | 数据类型 | 描述
:---- | :--- | :---
client_id | String | GatewayWorker产生的唯一客户id
```
public static function onConnect($client_id)
{
// 生成唯一client_id
...
// 将client_id推送到页面,可将client_id和用户id做绑定
...
}
```
#### 5.4 消息推送
> ../vendeor/GatewayWorker-for-win/Application/YourApp/Events.php
请求参数
参数 | 数据类型 | 描述
:---- | :--- | :---
client_id | String | GatewayWorker产生的唯一客户id
$message | String | 消息体
```
public static function onMessage($client_id, $message)
{
// 绑定用户和client_id
...
// 发送文字和表情
...
// 发送图片
...
// 信息持久化
...
// 上线,推送上线通知给好友
...
}
```
#### 5.5 关闭连接
> ../vendeor/GatewayWorker-for-win/Application/YourApp/Events.php
请求参数
参数 | 数据类型 | 描述
:---- | :--- | :---
client_id | String | GatewayWorker产生的唯一客户id
```
public static function onClose($client_id)
{
// 断开连接,推送下线状态给好友
...
}
```
### 🎨 6.项目预览
| | | |
|---------------------|---------------------|---------------------|
|  |  |  |
### 🎯 7.TODO
* 样式的优化