Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the function of Private message in the Station by php

2025-03-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "how to realize the private message function of php". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

How does php realize the function of private messages in the station?

Design idea and Scheme of realizing Internal message in Station by PHP

I. background

At present, when users use the operation and maintenance platform to communicate, they rely more on Wechat and email notifications, and the operation and maintenance platform, as a whole product, also needs a kind of service capable of internal communication-internal message.

The design tone of the letter in the station

The design tone of the message depends on how the user uses the message:

Users will not stay on the page of the operation and maintenance platform, wait for the notification of the message, view the content of the message, and then jump to the page to operate.

In other words, the message on the station is not the first entrance, and the real-time significance of the message on the station is not great.

Unlike many social networking sites (Facebook, Zhihu, Weibo, etc.), users will stay on the main page of social networking sites, constantly refresh new content and check for new messages (mainly personal messages, replies from others, etc., not to check system notification messages).

According to the email notification, users will decide whether to enter the operation and maintenance platform to operate.

If there are a lot of emails, such as multiple work orders to be processed at the same time, the user will also do all the work on the "my to-do" page provided by the work order platform.

If the email is deleted by mistake, there is no email link to go directly to the module to be operated.

Then or by asking for the link / order number, go to the specified page

Or search directly in the relevant modules.

The above description means that users basically do not use internal messages, so on what occasions will they use internal messages?

Do not send e-mail, but only send message notifications of internal messages, such as site-wide notification, editing operation, Comment operation, etc.

When a specific module does not have a detailed operation record, you can check the occurrence time of the message on the station.

Currently, there is only product message notification, and there is no classification and aggregation for message display. When you add intra-site messages such as full site notification, mention, like, comment, etc., you need to consider aggregating messages by type.

II. Description of requirements

On-site messaging usually needs to address two requirements:

The user's message to the user, and the administrator's message to the user: that is, sent one to one

Internal messages sent by administrators to multiple users, user groups and the whole site: that is, one-to-many

(another is the user's internal message about the product, such as feedback on a module, questions, etc.)

Our current needs are:

1 the administrator sends internal messages to multiple users

Do not verify the authenticity of the user

Limit the length of title and content (45 bytes, 150 bytes, 15 and 50 Chinese characters, respectively).

Limit the length of the recipient's pinyin (up to 50 bytes)

[recommended study: "PHP Video tutorial"]

2 users can view their own internal messages

Filter by "all, read, unread"

Classified by source: work order platform, resource management, automatic installation, vulnerability platform, fault platform.

3 users can delete or delete messages in batches

4 users can read, batch read, all marked as read messages within the site

5 the message icon at the top of the operation and maintenance platform page

Show the number of unread messages, more than 99 show 99 +

When the mouse is up, there will be a drop-down box showing the last 10 unread messages (showing "time", "source", "title")

There are two buttons at the bottom of the drop-down box: "more" to load more unread messages, and "View all" to jump to the internal message list page (preferably another window)

Click the unread message in the drop-down box to show the details through the pop-up box; then delete the record in the unread list and mark it as read in the database, reducing the number of unread messages in the message icon by one

6 Administrator page:

Update user

Delete message

Statistical data

Add module

Increase the types of messages on the site

Send station-wide messages

IV. System flow

Send a message inside the station

Read the request body of the POST request

Check length

Insert database

Return

Get internal message list

Call sub-module to insert internal messages sent to the whole site or to the user group to which I belong

Return database data according to query conditions

Get the number of unread messages on the site

Call sub-module to insert internal messages sent to the whole site or to the user group to which I belong

Return quantity

Batch read

Check whether messageId belongs to the current user

Set read to 1 in the inbox_message table and modify update_time

All read

Update inbox_message set "read" = 1, "update_time" = now where "receiver_name" = currentUser () and "read" = 0 batch deletion

Check whether messageId belongs to the current user

Set deleted to 1 in the inbox_message table and modify update_time

Delete all update inbox_message set "deleted" = 1, "update_time" = now where "receiver_name" = currentUser () and "deleted" = 0 5. Database design site internal message content table CREATE TABLE `inbox_message_ text` (`id`bigint (20) NOT NULL AUTO_INCREMENT, `title`varchar NOT NULL DEFAULT'', `content` longtext NOT NULL, `create_ time` datetime NOT NULL, `update_ time` datetime NOT NULL, `send_ type` tinyint (4) NOT NULL DEFAULT '0mm, `creator_ name` varchar'' `deleted` tinyint (4) NOT NULL DEFAULT '0questions, `module_ id` bigint (20) NOT NULL, `link`varchar (255) NOT NULL DEFAULT'', PRIMARY KEY (`id`) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

In addition to the message source (module_name), the message itself also has a latitude description, called message type (message_type), such as security message, activity message, service message, etc., in each category, it can be divided into subcategories, such as activity message-preferential activity.

The message source and message type can be orthogonal, that is, the work order platform can also have active messages; the message source can also be one of the message types, called "product message"

Internal message sending table CREATE TABLE `inbox_ message` (`id`bigint (20) NOT NULL AUTO_INCREMENT, `receiver_ id` bigint (20) NOT NULL, `receiver_ name` varchar'', `read`tinyint (4) NOT NULL DEFAULT '0requests, `deleted` tinyint (4) NOT NULL DEFAULT' 0messages, `create_ time` datetime NOT NULL, `update_ time` datetime NOT NULL, PRIMARY KEY (`id`), KEY `inbox_message_receiver_name_deleted_read_ id` (`receiver_ name`, `deleted`, `read`, `id`) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4) Message source table CREATE TABLE `code` (`id` bigint (20) NOT NULL AUTO_INCREMENT, `code` varchar (12828) NOT NULL DEFAULT'', `name` varchar (128NOT NULL DEFAULT''), `create_ time` datetime NOT NULL, `update_ time` datetime NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`), UNIQUE KEY `name` (`name`) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 6, API design sending station internal message: POST / v1/message

Request body Content-Type: application/json

{"title": "work order approval", "content": "XXX has submitted a change request, please approve", "to": "sunzhongyuan,shenli,wangya", "module_name": "work order platform", "link": "xxx"}

Response

{"code": 200, "data": 32, "msg": "OK"} get internal message list: GET / v1/message User-Id: xxx http://127.0.0.1:10085/v1/message?query=message_text_id.module_id.name:xxx&limit=1{ "code": 200, "data": {"data": [{"id": 1 "message_text": {"id": 1, "title": "title 2", "content": "content 2", "create_time": "2018-01-12 11:13:48", "update_time": "2018-01-12 11:13:48" "send_type": 1, "creator_name": "sysadmin", "deleted": 0, "link": "xxx", "Messages": null, "module": {"id": 4 "code": "secure", "name": "xxx", "create_time": "2018-01-11 15:38:01", "update_time": "2018-01-11 15:38:01" "MessageTexts": null}}, "receiver_name": "xxx", "read": 0, "deleted": 0, "create_time": "2018-01-12 11:13:48" "update_time": "2018-01-12 11:13:48"}], "total": 2}, "msg": "OK"} read, batch read internal letter: PUT / v1/read_messages/:messageIds

Response

{"code": 200, "data": "OK", "msg": "OK"}

All read PUT:/v1/read_all_messages

Response ditto

Delete or batch delete internal messages: PUT / v1/delete_messages/:messageIds

Response ditto

Delete all internal messages: PUT / v1/delete_all_messages

Response ditto

Get a list of message sources: GET / v1/module

Response

{"code": 200, "data": [{"id": 1, "code": "worksheet", "name": "work order platform", "create_time": "2018-01-11 15:21:38", "update_time": "2018-01-11 15:21:38" "MessageTexts": null}, {"id": 2, "code": "cmdb", "name": "Resource Management", "create_time": "2018-01-11 15:22:28", "update_time": "2018-01-11 15:22:28" "MessageTexts": null},...], "msg": "OK"}

7. Pay attention to the test

1 sending internal message

Pure interface

The recipient is separated by a comma and the authenticity is not verified.

The pickup user has a length check of 50 bytes

Title content has a length check, which is 45150 bytes

Module_name is a list. You must choose one from here.

2 other interfaces can be tested by the front-end page

VIII. Optimization

The unread list can be shown in bold, while the read list is a normal font.

Classify the messages in the station and label them with different latitudes to facilitate filtering, searching and shielding.

Users can set the message source of the messages that are allowed to be received on the site.

The administrator can add, delete, change and check the messages, personnel and message attributes of the whole site, such as revoking a message on the site, so that no one can see it.

The administrator can count the number of messages sent in the station, the usage of each product, the proportion of messages being read, the time when messages are read, the way messages are read (click on or batch operation), etc.

IX. Design of key function points

Icon behavior in the upper right corner

1 Click the icon to show the most recent N unread messages

Show drop-down box

Get the last N unread messages in real time

N can be 5: 10, depending on the height limit of the drop-down box

When the unread is less than N, the drop-down box can adapt to the height.

If there are no unread messages, show "no new messages yet"

Stop the interface for getting unread messages every 10 seconds

2 in the drop-down box, show the source, time (relative to the current time: 10 minutes ago), title

Slide down the drop-down box to show more unread messages (only get id less than the minimum id in the list of displayed messages, that is, do not get new messages after clicking the icon)

3 Click a message in the drop-down box

The drop-down box does not disappear

Still stop the API for getting unread messages every 10 seconds

The number of unread messages minus 1

Unread message list deletes the current message (slice)

Show pop-up box

4 Pop-up box showing the source, time (absolute time), title, content of the message

5 close the pop-up box or click on the periphery:

Pop-up box disappears

The drop-down box does not disappear

You can continue to click on an unread message

6 Click the periphery of the drop-down box and icon again

The drop-down box disappears

Clear the list of existing unread messages

Recover the interface for getting unread messages every 10 seconds

7 Click the icon again to return to the # 1 state

This is the end of the content of "how to realize the function of private message in php". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report