访客注册方式更改

pull/23/head
taoshihan1991 5 years ago
parent 28f0478547
commit e5b76d24fa

@ -34,6 +34,7 @@ type ClientMessage struct {
Name string `json:"name"`
Avator string `json:"avator"`
Id string `json:"id"`
VisitorId string `json:"visitor_id"`
Group string `json:"group"`
Time string `json:"time"`
ToId string `json:"to_id"`
@ -235,10 +236,10 @@ func singleBroadcaster(){
conn:conn,
name: clientMsg.Name,
avator: clientMsg.Avator,
id:clientMsg.Id,
id:clientMsg.VisitorId,
to_id:clientMsg.ToId,
}
clientList[clientMsg.Id] = user
clientList[clientMsg.VisitorId] = user
//插入数据表
models.CreateVisitor(clientMsg.Name,clientMsg.Avator,message.c.ClientIP(),clientMsg.ToId,clientMsg.Id,clientMsg.Refer,clientMsg.City,clientMsg.ClientIp)
userInfo := make(map[string]string)

@ -63,6 +63,9 @@ func PostVisitorLogin(c *gin.Context) {
avator := fmt.Sprintf("/static/images/%d.jpg",rand.Intn(14))
toId := c.PostForm("to_id")
id := c.PostForm("id")
if id==""{
id = tools.Uuid()
}
refer := c.PostForm("refer")
var (
city string
@ -76,7 +79,7 @@ func PostVisitorLogin(c *gin.Context) {
name="匿名网友"
}
client_ip := c.PostForm("client_ip")
log.Println(name,avator,c.ClientIP(),toId,id,refer,city,client_ip)
//log.Println(name,avator,c.ClientIP(),toId,id,refer,city,client_ip)
if name==""||avator==""||toId==""||id==""||refer==""||city==""||client_ip==""{
c.JSON(200, gin.H{
"code": 400,
@ -84,6 +87,14 @@ func PostVisitorLogin(c *gin.Context) {
})
return
}
kefuInfo:=models.FindUser(toId)
if kefuInfo.ID==0{
c.JSON(200, gin.H{
"code": 400,
"msg": "客服不存在",
})
return
}
models.CreateVisitor(name,avator,c.ClientIP(),toId,id,refer,city,client_ip)
visitor:=models.FindVisitorByVistorId(id)
c.JSON(200, gin.H{

@ -18,6 +18,7 @@ require (
github.com/gorilla/websocket v1.4.2
github.com/ipipdotnet/ipdb-go v1.3.0
github.com/jinzhu/gorm v1.9.14
github.com/satori/go.uuid v1.2.0
github.com/spf13/cobra v0.0.5
github.com/swaggo/gin-swagger v1.2.0
github.com/swaggo/swag v1.5.1

@ -150,6 +150,8 @@ github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=

@ -40,7 +40,7 @@ func InitApiRouter(engine *gin.Engine){
engine.POST("/mysql",middleware.JwtApiMiddleware,middleware.RbacAuth, controller.MysqlSetConf)
engine.GET("/visitors_online", controller.GetVisitorOnlines)
engine.GET("/clear_online_tcp", controller.DeleteOnlineTcp)
engine.POST("/visitor_login",controller.PostVisitorLogin)
engine.POST("/visitor_login",middleware.Ipblack,controller.PostVisitorLogin)
engine.POST("/visitor",controller.PostVisitor)
engine.GET("/visitor",middleware.JwtApiMiddleware, controller.GetVisitor)
engine.GET("/visitors",middleware.JwtApiMiddleware, controller.GetVisitors)

@ -1,10 +1,10 @@
var guest={};
guest.id = "";
guest.name = typeof(returnCitySN)!="undefined" ?returnCitySN["cname"]+"网友":"匿名";
guest.avator = "/static/images/"+Math.floor(Math.random()*(14-0+1)+0)+".jpg";
guest.group = "1";
guest.to_id=KEFU_ID!=""? KEFU_ID:"kefu2";
// var guest={};
// guest.id = "";
// guest.name = typeof(returnCitySN)!="undefined" ?returnCitySN["cname"]+"网友":"匿名";
// guest.avator = "/static/images/"+Math.floor(Math.random()*(14-0+1)+0)+".jpg";
// guest.group = "1";
// guest.to_id=KEFU_ID!=""? KEFU_ID:"kefu2";
KEFU_ID=KEFU_ID!=""? KEFU_ID:"kefu2";
new Vue({
el: '#app',
delimiters:["<{","}>"],
@ -31,23 +31,23 @@ new Vue({
OnOpen() {
this.chatTitle="连接成功!"
//从缓存中取出用户
let userinfo=this.getUserInfo();
// let userinfo=this.getUserInfo();
let mes = {}
mes.type = "userInit";
userinfo.client_ip=returnCitySN["cip"];
userinfo.city=returnCitySN["cname"];
userinfo.refer=REFER;
mes.data = userinfo;
// userinfo.client_ip=returnCitySN["cip"];
// userinfo.city=returnCitySN["cname"];
// userinfo.refer=REFER;
mes.data = this.visitor;
this.socket.send(JSON.stringify(mes));
},
OnMessage(e) {
const redata = JSON.parse(e.data);
if (redata.type == "kfOnline") {
let msg = redata.data
if(this.showKfonline && guest.to_id==msg.id){
if(this.showKfonline && this.visitor.to_id==msg.id){
return;
}
guest.to_id=msg.id;
this.visitor.to_id=msg.id;
this.chatTitle=msg.name+",正在与您沟通!"
$(".chatBox").append("<div class=\"chatTime\">"+this.chatTitle+"</div>");
this.scrollBottom();
@ -55,7 +55,7 @@ new Vue({
}
if (redata.type == "message") {
let msg = redata.data
guest.to_id=msg.id;
this.visitor.to_id=msg.id;
let content = {}
content.avator = msg.avator;
@ -65,7 +65,7 @@ new Vue({
content.time = msg.time;
this.msgList.push(content);
this.saveHistory(content);
//this.saveHistory(content);
this.scrollBottom();
flashTitle();//标题闪烁
}
@ -73,13 +73,13 @@ new Vue({
},
//发送给客户
chatToUser() {
if(guest.to_id==""){
this.$message({
message: '暂时没有客服接手',
type: 'warning'
});
return;
}
// if(guest.to_id==""){
// this.$message({
// message: '暂时没有客服接手',
// type: 'warning'
// });
// return;
// }
this.messageContent=this.messageContent.trim("\r\n");
if(this.messageContent==""||this.messageContent=="\r\n"){
this.$message({
@ -93,8 +93,8 @@ new Vue({
let mes = {};
mes.type = "visitor";
mes.content = this.messageContent;
mes.from_id = guest.id;
mes.to_id = guest.to_id;
mes.from_id = this.visitor.visitor_id;
mes.to_id = this.visitor.to_id;
mes.content = this.messageContent;
//发送消息
$.post("/message",mes,function(res){
@ -106,13 +106,13 @@ new Vue({
return;
}
let content = {}
content.avator=guest.avator;
content.avator=_this.visitor.avator;
content.content = replaceContent(_this.messageContent);
content.name = guest.name;
content.name = _this.visitor.name;
content.is_kefu = true;
content.time = _this.getNowDate();
_this.msgList.push(content);
_this.saveHistory(content);
//_this.saveHistory(content);
_this.scrollBottom();
_this.messageContent = "";
});
@ -125,46 +125,31 @@ new Vue({
getUserInfo(){
let obj=this.getCache("guest");
if(!obj){
guest.id=this.generateUUID();
this.setCache("guest",guest);
obj=this.getCache("guest");
}
guest=obj;
this.visitor=obj;
return obj;
},
//加载历史
getHistory:function(){
let history=this.getCache("history");
if(history==null){
history=[];
let _this=this;
//发送消息
$.post("/visitor_login",{refer:REFER,to_id:KEFU_ID,client_ip:returnCitySN["cip"],},function(res){
if(res.code!=200){
_this.$message({
message: res.msg,
type: 'error'
});
return;
}
_this.visitor=res.result;
_this.setCache("guest",res.result);
_this.initConn();
});
}else{
this.visitor=obj;
this.initConn();
}
$.each(history,function(i,val){
history[i]["show_time"]=false;
let lastKey=(i+1)>=history.length?i:i+1;
let lastTime=new Date(history[lastKey]["time"]).getTime();
let curTime=new Date(val["time"]).getTime();
let diffTime=lastTime-curTime
if(diffTime>(1000*60*5)){
history[i]["show_time"]=true;
}
});
console.log(history);
return history;
},
//保存历史
saveHistory:function(row){
let history=this.getHistory("history");
history.push(row);
this.setCache("history",history);
},
//获取信息列表
getMesssagesByVisitorId(){
let _this=this;
$.ajax({
type:"get",
url:"/messages?visitorId="+this.visitor.id,
url:"/messages?visitorId="+this.visitor.visitor_id,
success: function(data) {
if(data.code==200 && data.result!=null){
let msgList=data.result;
@ -232,7 +217,7 @@ new Vue({
//获取自动欢迎语句
getNotice : function (){
let _this=this;
$.get("/notice?kefu_id="+guest.to_id,function(res) {
$.get("/notice?kefu_id="+KEFU_ID,function(res) {
//debugger;
if (res.result != null) {
let msg = res.result;
@ -246,10 +231,6 @@ new Vue({
}
}
});
},
//获取聊天记录
getHistoryByApi(){
},
initCss(){
var _this=this;
@ -288,7 +269,6 @@ new Vue({
//初始化
init(){
this.initCss();
this.initConn();
window.onfocus = function () {
clearTimeout(titleTimer);
document.title = originTitle;

@ -0,0 +1,8 @@
package tools
import (
"github.com/satori/go.uuid"
)
func Uuid()string {
u2 := uuid.NewV4()
return u2.String()
}
Loading…
Cancel
Save