[Node.js + html] bored at home writing an online customer service chat system

【System Overview】

  • Use Node.js + socket.io establish a socket connection
  • Writing individual client page
  • Writing individual customer to enter the page

Writing a can a (customer service) multi (customer) online customer service system, while receiving more advice.

System Interface [Preview]

Client Interface
Customer Interface Preview
Customer service chat interface

[] Implementation steps

First, install node.js

Can node.js official website to download and install, after installation can enter cmd command node -v, Enter and npm -v, carriage return, appear the version number indicates the installation was successful!

Second, the installation socket.io

cd to the website root directory (such as my website directory in the D drive> phpStudy> www> next chat directory), enter the npm install socket.io回车installationsocket.io

Third, write and chat interface logic

Chat interface nothing to say, interested can directly download the source code

① how to achieve one to one chat?

Set room (the room), the corresponding room displays a corresponding message. Room Each message parameters passed, the client parses the message format is as follows:

 msg={
     type:0,//type表示用户角色,0为咨询客户,1为客服
     room:room,//房间id,对应的房间才能接收到消息
     username:uname,//发送人姓名
     message:text,//消息字符串
     msg_type:0//消息类别,0为文字,1为xls文件,2为pdf
     time:''//发送时间
 }

② how to achieve a (customer service) multi (customer) service?

In fact, in the page, all of the messages we have received, and this easy to handle, we have all received the message classification can be realized according to the customer service advisory services to many senders.

[Late] Optimization

First, when the customer service did not enter the system, how to save the message sent by the client

The most basic should still be stored in the database, the customer service to be extracted after landing page to load data into.

Former customer did not enter the page, to keep the message sent by the client

Second, message encryption

In the above method, each page can receive all messages, it is not safe. We can improve information security through encryption string, refer to the article: https://blog.csdn.net/gzyh_tech/article/details/94592829 

In addition to the above, the system is also complicated by the presence of high network latency and other issues, we welcome the discussion!

发布了44 篇原创文章 · 获赞 21 · 访问量 3万+

Guess you like

Origin blog.csdn.net/gzyh_tech/article/details/104091196