Giter Site home page Giter Site logo

gzydong / hyperf-chat Goto Github PK

View Code? Open in Web Editor NEW
329.0 7.0 121.0 675 KB

Lumen IM 是一个网页版在线聊天项目,前端使用 Element-ui + Vue,后端采用了基于 Swoole 开发的 Hyperf 协程框架进行接口开发,并使用 WebSocket 服务进行消息实时推送。

Home Page: http://im.gzydong.com

Dockerfile 0.35% PHP 98.53% Blade 1.12%

hyperf-chat's Introduction

Lumen-IM

1、简介

Lumen-IM 是一个网页版在线即时聊天项目,前端使用 Element-ui + Vue ,后端使用 PHP + Swoole 进行开发。项目后端采用 Hyperf 框架。

  • 基于 Swoole WebSocket 服务做消息即时推送
  • 支持私聊及群聊
  • 支持聊天消息类型有文本、代码块、图片及其它类型文件,并支持文件下载
  • 支持聊天消息撤回、删除或批量删除、转发消息(逐条转发、合并转发)及群投票功能
  • 支持编写个人笔记、支持笔记分享(好友或群)

2、项目DEMO

3、环境要求

  • PHP >= 7.3
  • MySQL >= 5.7
  • Redis >= 5.0
  • Swoole >= 4.5
  • OpenSSL
  • JSON
  • PDO

4、相关文档

Hyperf 框架

5、项目安装

  1. 下载源码包
  2. 安装框架依赖包执行 composer install 命令 [项目根目录下执行]
  3. 拷贝项目根目录下 .env.example 文件为 .env 并正确配置相关参数(mysql、redis)
  4. 执行项目安装命令(安装数据库及测试数据) php bin/hyperf.php system:install
  5. 启动运行项目 php bin/hyperf.php start

注 :[项目运行之前请确保 MySQL、Redis 及 Nginx 服务]

Nginx 相关配置(代理 swoole 服务)

配置 Http 服务
upstream hyperf_http {
    # Hyperf HTTP Server 的 IP 及 端口
    server 127.0.0.1:9503;
}

server {
    # 监听端口
    listen 80;
    # 绑定的域名,填写您的域名
    server_name im-serve.xxx.com;

    location / {
        client_max_body_size    20m;
        # 将客户端的 Host 和 IP 信息一并转发到对应节点
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # 转发Cookie,设置 SameSite
        proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";

        # 执行代理访问真实服务器
        proxy_pass http://hyperf_http;
    }
}
配置 WebSocket 服务
# 至少需要一个 Hyperf 节点,多个配置多行
upstream hyperf_websocket {
    server 127.0.0.1:9504;
}

server {
    listen 80;
    server_name im-socket.xxx.com;

    location / {
        # WebSocket Header
        proxy_http_version 1.1;
        proxy_set_header Upgrade websocket;
        proxy_set_header Connection "Upgrade";

        # 将客户端的 Host 和 IP 信息一并转发到对应节点
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;

        # 客户端与服务端无交互 60s 后自动断开连接,请根据实际业务场景设置
        proxy_read_timeout 60s ;

        # 执行代理访问真实服务器
        proxy_pass http://hyperf_websocket;
    }
}
配置图片域名
server {
    listen 80;
    server_name  im-img.xxx.xxx;
    index  index.html;

    # 默认禁止访问
    location / {
        deny all;
    }

    # 只允许 访问 images 文件夹下的文件
    location ^~ /media/{
        # 设置目录别名(确保是项目上传文件目录)
        # 例如 upload_dir = /www/data/lumenim
        # 此时应配置 alias /www/data/lumenim/media/
        
        alias /www/data/lumenim/media/;

        # 设置缓存时间(3天)
        expires 3d;

        # 关闭访问日志
        access_log off;
    }
}

前端地址

https://github.com/gzydong/LumenIM

注意事项

  1. 请确保 PHP 安装 openssl、redis 扩展
  2. 请确保 Swoole 扩展开启 openssl 扩展
[root@iZuf6cs69fbc86cwpu9iv3Z vhost]# php --ri swoole
swoole
Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 4.5.9
...
openssl => OpenSSL 1.0.2k-fips  26 Jan 2017 (请确保此处开启)

hyperf-chat's People

Contributors

gzydong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

hyperf-chat's Issues

请问可以商用吗?

想搭建用来给公司做售后聊天系统,但是看到仓库没有LICENSE,
代码中存在

/**

不太敢用...可以明确一下开源类型和代码和仓库声明以什么为准吗...感谢

源码,登录接口报 Cannot call constructor

[INFO] Process[RedisWebsocketSubscribe.0] start. [ERROR] Cannot call constructor[32] in /var/www/hyperf-chat/app/Controller/Api/V1/AuthController.php [ERROR] #0 /var/www/hyperf-chat/vendor/hyperf/di/src/Resolver/ObjectResolver.php(99): App\Controller\Api\V1\AuthController->__construct() #1 /var/www/hyperf-chat/vendor/hyperf/di/src/Resolver/ObjectResolver.php(66): Hyperf\Di\Resolver\ObjectResolver->createInstance() #2 /var/www/hyperf-chat/vendor/hyperf/di/src/Resolver/ResolverDispatcher.php(62): Hyperf\Di\Resolver\ObjectResolver->resolve() #3 /var/www/hyperf-chat/vendor/hyperf/di/src/Resolver/DepthGuard.php(73): Hyperf\Di\Resolver\ResolverDispatcher->Hyperf\Di\Resolver\{closure}() #4 /var/www/hyperf-chat/vendor/hyperf/di/src/Resolver/ResolverDispatcher.php(63): Hyperf\Di\Resolver\DepthGuard->call() #5 /var/www/hyperf-chat/vendor/hyperf/di/src/Container.php(184): Hyperf\Di\Resolver\ResolverDispatcher->resolve() #6 /var/www/hyperf-chat/vendor/hyperf/di/src/Container.php(82): Hyperf\Di\Container->resolveDefinition() #7 /var/www/hyperf-chat/vendor/hyperf/di/src/Container.php(117): Hyperf\Di\Container->make() #8 /var/www/hyperf-chat/vendor/hyperf/http-server/src/CoreMiddleware.php(155): Hyperf\Di\Container->get() #9 /var/www/hyperf-chat/vendor/hyperf/http-server/src/CoreMiddleware.php(113): Hyperf\HttpServer\CoreMiddleware->handleFound() #10 /var/www/hyperf-chat/vendor/hyperf/dispatcher/src/AbstractRequestHandler.php(64): Hyperf\HttpServer\CoreMiddleware->process() #11 /var/www/hyperf-chat/vendor/hyperf/dispatcher/src/HttpRequestHandler.php(26): Hyperf\Dispatcher\AbstractRequestHandler->handleRequest() #12 /var/www/hyperf-chat/app/Middleware/CorsMiddleware.php(36): Hyperf\Dispatcher\HttpRequestHandler->handle() #13 /var/www/hyperf-chat/vendor/hyperf/dispatcher/src/AbstractRequestHandler.php(64): App\Middleware\CorsMiddleware->process() #14 /var/www/hyperf-chat/vendor/hyperf/dispatcher/src/HttpRequestHandler.php(26): Hyperf\Dispatcher\AbstractRequestHandler->handleRequest() #15 /var/www/hyperf-chat/vendor/hyperf/dispatcher/src/HttpDispatcher.php(40): Hyperf\Dispatcher\HttpRequestHandler->handle() #16 /var/www/hyperf-chat/vendor/hyperf/http-server/src/Server.php(116): Hyperf\Dispatcher\HttpDispatcher->dispatch() #17 {main}

websorket 连接报错 返回400错误

其他服务都已正常
websorket 连接报错 返回400错误
服务端报错提示:[WARNING] WebSocket hande shake failed, because the class does not exists.
9504端口能打开 但是 浏览器访问 返回400
请问大神 这个问题如何解决 java党 对php不是很熟悉

关于SQL 脚本

此后项目提供的SQL脚本目录为: SQL
其中只有一个文件: <LumenIM 同步SQL.sql> 但是这明显不是完整的SQL文件, 而是某一次的更新SQL文件,
能麻烦作者提供一下完整的SQL脚本吗? 不胜感激

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.