【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]
![](https://img-blog.csdnimg.cn/20200127112624214.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2d6eWhfdGVjaA==,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/2020012710411437.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2d6eWhfdGVjaA==,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20200127104323524.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2d6eWhfdGVjaA==,size_16,color_FFFFFF,t_70)
[] 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.
![](https://img-blog.csdnimg.cn/20200127113358748.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2d6eWhfdGVjaA==,size_16,color_FFFFFF,t_70)
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!