访客注册方式更改

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

@ -34,6 +34,7 @@ type ClientMessage struct {
Name string `json:"name"` Name string `json:"name"`
Avator string `json:"avator"` Avator string `json:"avator"`
Id string `json:"id"` Id string `json:"id"`
VisitorId string `json:"visitor_id"`
Group string `json:"group"` Group string `json:"group"`
Time string `json:"time"` Time string `json:"time"`
ToId string `json:"to_id"` ToId string `json:"to_id"`
@ -235,10 +236,10 @@ func singleBroadcaster(){
conn:conn, conn:conn,
name: clientMsg.Name, name: clientMsg.Name,
avator: clientMsg.Avator, avator: clientMsg.Avator,
id:clientMsg.Id, id:clientMsg.VisitorId,
to_id:clientMsg.ToId, 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) models.CreateVisitor(clientMsg.Name,clientMsg.Avator,message.c.ClientIP(),clientMsg.ToId,clientMsg.Id,clientMsg.Refer,clientMsg.City,clientMsg.ClientIp)
userInfo := make(map[string]string) userInfo := make(map[string]string)

@ -63,6 +63,9 @@ func PostVisitorLogin(c *gin.Context) {
avator := fmt.Sprintf("/static/images/%d.jpg",rand.Intn(14)) avator := fmt.Sprintf("/static/images/%d.jpg",rand.Intn(14))
toId := c.PostForm("to_id") toId := c.PostForm("to_id")
id := c.PostForm("id") id := c.PostForm("id")
if id==""{
id = tools.Uuid()
}
refer := c.PostForm("refer") refer := c.PostForm("refer")
var ( var (
city string city string
@ -76,7 +79,7 @@ func PostVisitorLogin(c *gin.Context) {
name="匿名网友" name="匿名网友"
} }
client_ip := c.PostForm("client_ip") 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==""{ if name==""||avator==""||toId==""||id==""||refer==""||city==""||client_ip==""{
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"code": 400, "code": 400,
@ -84,6 +87,14 @@ func PostVisitorLogin(c *gin.Context) {
}) })
return 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) models.CreateVisitor(name,avator,c.ClientIP(),toId,id,refer,city,client_ip)
visitor:=models.FindVisitorByVistorId(id) visitor:=models.FindVisitorByVistorId(id)
c.JSON(200, gin.H{ c.JSON(200, gin.H{

@ -18,6 +18,7 @@ require (
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2
github.com/ipipdotnet/ipdb-go v1.3.0 github.com/ipipdotnet/ipdb-go v1.3.0
github.com/jinzhu/gorm v1.9.14 github.com/jinzhu/gorm v1.9.14
github.com/satori/go.uuid v1.2.0
github.com/spf13/cobra v0.0.5 github.com/spf13/cobra v0.0.5
github.com/swaggo/gin-swagger v1.2.0 github.com/swaggo/gin-swagger v1.2.0
github.com/swaggo/swag v1.5.1 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 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= 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/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 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= 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.POST("/mysql",middleware.JwtApiMiddleware,middleware.RbacAuth, controller.MysqlSetConf)
engine.GET("/visitors_online", controller.GetVisitorOnlines) engine.GET("/visitors_online", controller.GetVisitorOnlines)
engine.GET("/clear_online_tcp", controller.DeleteOnlineTcp) 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.POST("/visitor",controller.PostVisitor)
engine.GET("/visitor",middleware.JwtApiMiddleware, controller.GetVisitor) engine.GET("/visitor",middleware.JwtApiMiddleware, controller.GetVisitor)
engine.GET("/visitors",middleware.JwtApiMiddleware, controller.GetVisitors) engine.GET("/visitors",middleware.JwtApiMiddleware, controller.GetVisitors)

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