Git Product home page Git Product logo

message_system's Introduction

message_system

这是一个基于yii2的消息系统

install

composer require --prefer-dist johnnylei/message-system

usage

imgrate

打开imgrate/文件夹,建好相关的表

配置文件

'messageManager'=>[
    'class'=>'johnnylei\message_system\MessageManager',
    // userInformation 是一个用户表的activeRecord,主要作用当你发送消息的时候,将用户表里面的消息总数+1,当你阅读完消息的时候,将用户表里面的消息数-1,
    // 通过实现UserInformationInterface,里面的两个方法
    'userInformation'=>[
        'class'=>'xxx',
    ]
]

监听一个队列

// 原理就是往message_queue_subscription表里面插入一条数据,表示某个用户监听了某个队列
$subscription = new MessageQueueSubscription();
$subscription->subscription($userId, $queueId);

发送消息

// 发送消息就是往某个消息队列里面写数据,谁监听了这个消息队列,谁就会收到一条数据
// 原理,1.生产一条消息记录,2.在message_queue_subscription表里面查看谁监听了这个队列 3.根据获取到的user_id,将第一步生成消息id,和user_id写入到message_user_map表里面,这样就表示该用户收到这条消息了
Yii::$app->messageManager->send([
                'title'=> 'this is title',
                'body'=> 'this is body',
                // 后面的参数不重要,但是可以配置
                // type就是你自定义一个消息type
                'type'=>'this is message type',
                // 这个参数也是你自定的显示风格,我们用到的弹窗和打开新的页面,具体怎么用,自己写规则
                'show_style'=>'this is show style',
            ], $queue_id);

接受消息

// 获取所有消息的列表
$messageList = Yii::$app->messageManager->myMessageList();

// 获取一个消息
$messageList = Yii::$app->messageManager->receive();

message_system's People

Contributors

johnnylei avatar

Watchers

Charles avatar

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.