增加而外的字段

pull/23/head
陶士涵 3 years ago
parent ecedda4dd6
commit 4289b49939

@ -30,7 +30,8 @@ CREATE TABLE `visitor` (
`status` tinyint(4) NOT NULL DEFAULT '0', `status` tinyint(4) NOT NULL DEFAULT '0',
`refer` varchar(500) NOT NULL DEFAULT '', `refer` varchar(500) NOT NULL DEFAULT '',
`city` varchar(100) NOT NULL DEFAULT '', `city` varchar(100) NOT NULL DEFAULT '',
`client_ip` varchar(100) NOT NULL, `client_ip` varchar(100) NOT NULL DEFAULT '',
`extra` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `visitor_id` (`visitor_id`), UNIQUE KEY `visitor_id` (`visitor_id`),
KEY `to_id` (`to_id`) KEY `to_id` (`to_id`)

@ -1,70 +1,68 @@
package controller package controller
import ( import (
"encoding/json"
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
"github.com/taoshihan1991/imaptool/config" "github.com/taoshihan1991/imaptool/config"
"github.com/taoshihan1991/imaptool/models" "github.com/taoshihan1991/imaptool/models"
"github.com/taoshihan1991/imaptool/tools" "github.com/taoshihan1991/imaptool/tools"
"github.com/taoshihan1991/imaptool/ws" "github.com/taoshihan1991/imaptool/ws"
"log"
"math/rand" "math/rand"
"strconv" "strconv"
) )
func PostVisitor(c *gin.Context) { //func PostVisitor(c *gin.Context) {
name := c.PostForm("name") // name := c.PostForm("name")
avator := c.PostForm("avator") // avator := c.PostForm("avator")
toId := c.PostForm("to_id") // toId := c.PostForm("to_id")
id := c.PostForm("id") // id := c.PostForm("id")
refer := c.PostForm("refer") // refer := c.PostForm("refer")
city := c.PostForm("city") // city := c.PostForm("city")
client_ip := c.PostForm("client_ip") // client_ip := c.PostForm("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,
"msg": "error", // "msg": "error",
}) // })
return // return
} // }
kefuInfo := models.FindUser(toId) // kefuInfo := models.FindUser(toId)
if kefuInfo.ID == 0 { // if kefuInfo.ID == 0 {
c.JSON(200, gin.H{ // c.JSON(200, gin.H{
"code": 400, // "code": 400,
"msg": "用户不存在", // "msg": "用户不存在",
}) // })
return // 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)
//
userInfo := make(map[string]string) // userInfo := make(map[string]string)
userInfo["uid"] = id // userInfo["uid"] = id
userInfo["username"] = name // userInfo["username"] = name
userInfo["avator"] = avator // userInfo["avator"] = avator
msg := TypeMessage{ // msg := TypeMessage{
Type: "userOnline", // Type: "userOnline",
Data: userInfo, // Data: userInfo,
} // }
str, _ := json.Marshal(msg) // str, _ := json.Marshal(msg)
kefuConns := kefuList[toId] // kefuConns := kefuList[toId]
if kefuConns != nil { // if kefuConns != nil {
for k, kefuConn := range kefuConns { // for k, kefuConn := range kefuConns {
log.Println(k, "xxxxxxxx") // log.Println(k, "xxxxxxxx")
kefuConn.WriteMessage(websocket.TextMessage, str) // kefuConn.WriteMessage(websocket.TextMessage, str)
} // }
} // }
c.JSON(200, gin.H{ // c.JSON(200, gin.H{
"code": 200, // "code": 200,
"msg": "ok", // "msg": "ok",
}) // })
} //}
func PostVisitorLogin(c *gin.Context) { func PostVisitorLogin(c *gin.Context) {
ipcity := tools.ParseIp(c.ClientIP()) ipcity := tools.ParseIp(c.ClientIP())
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("visitor_id") id := c.PostForm("visitor_id")
extra := c.PostForm("extra")
if id == "" { if id == "" {
id = tools.Uuid() id = tools.Uuid()
} }
@ -97,7 +95,7 @@ func PostVisitorLogin(c *gin.Context) {
}) })
return 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, extra)
visitor := models.FindVisitorByVistorId(id) visitor := models.FindVisitorByVistorId(id)
//各种通知 //各种通知

@ -11,9 +11,10 @@ type Visitor struct {
Refer string `json:"refer"` Refer string `json:"refer"`
City string `json:"city"` City string `json:"city"`
ClientIp string `json:"client_ip"` ClientIp string `json:"client_ip"`
Extra string `json:"extra"`
} }
func CreateVisitor(name string, avator string, sourceIp string, toId string, visitorId string, refer string, city string, clientIp string) { func CreateVisitor(name, avator, sourceIp, toId, visitorId, refer, city, clientIp, extra string) {
old := FindVisitorByVistorId(visitorId) old := FindVisitorByVistorId(visitorId)
if old.Name != "" { if old.Name != "" {
//更新状态上线 //更新状态上线
@ -30,6 +31,7 @@ func CreateVisitor(name string, avator string, sourceIp string, toId string, vis
Refer: refer, Refer: refer,
City: city, City: city,
ClientIp: clientIp, ClientIp: clientIp,
Extra: extra,
} }
DB.Create(v) DB.Create(v)
} }

@ -69,7 +69,7 @@ func InitApiRouter(engine *gin.Engine) {
engine.GET("/visitors_kefu_online", middleware.JwtApiMiddleware, controller.GetKefusVisitorOnlines) engine.GET("/visitors_kefu_online", middleware.JwtApiMiddleware, controller.GetKefusVisitorOnlines)
engine.GET("/clear_online_tcp", controller.DeleteOnlineTcp) engine.GET("/clear_online_tcp", controller.DeleteOnlineTcp)
engine.POST("/visitor_login", middleware.Ipblack, 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)
engine.GET("/statistics", middleware.JwtApiMiddleware, controller.GetStatistics) engine.GET("/statistics", middleware.JwtApiMiddleware, controller.GetStatistics)

@ -161,12 +161,6 @@
<span slot="title">ClientIP<{visitor.source_ip}></span> <span slot="title">ClientIP<{visitor.source_ip}></span>
</el-menu-item> </el-menu-item>
</el-tooltip> </el-tooltip>
<el-tooltip content="点击加入黑名单" placement="left">
<el-menu-item v-on:click="addIpblack(visitor.client_ip)" title="点击加入黑名单" style="padding-left:2px;">
<i class="el-icon-s-tools"></i>
<span slot="title">IP<{visitor.client_ip}></span>
</el-menu-item>
</el-tooltip>
<el-menu-item v-on:click="openUrl('https://www.baidu.com/s?wd='+visitor.client_ip)" style="padding-left:2px;"> <el-menu-item v-on:click="openUrl('https://www.baidu.com/s?wd='+visitor.client_ip)" style="padding-left:2px;">
<i class="el-icon-s-tools"></i> <i class="el-icon-s-tools"></i>
<span slot="title">城市:<{visitor.city}></span> <span slot="title">城市:<{visitor.city}></span>
@ -192,6 +186,12 @@
<span slot="title">状态:<{visitor.status}></span> <span slot="title">状态:<{visitor.status}></span>
</el-menu-item> </el-menu-item>
</el-tooltip> </el-tooltip>
<el-tooltip v-for="v in visitorExtra" :content="v.val" placement="left">
<el-menu-item :title="v.val" style="padding-left:2px;">
<i class="el-icon-s-tools"></i>
<span slot="title"><{v.key}><{v.val}></span>
</el-menu-item>
</el-tooltip>
</el-menu> </el-menu>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="黑名单" name="blackList"> <el-tab-pane label="黑名单" name="blackList">

@ -25,7 +25,7 @@
GOFLY_URL:"", GOFLY_URL:"",
GOFLY_KEFU_ID: "kefu2", GOFLY_KEFU_ID: "kefu2",
GOFLY_BTN_TEXT: "{{.OnlineChat}}", GOFLY_BTN_TEXT: "{{.OnlineChat}}",
GOFLY_LANG:"{{.Lang}}" GOFLY_LANG:"{{.Lang}}",
}) })
</script> </script>
<!--//对接客服代码--> <!--//对接客服代码-->

@ -31,6 +31,7 @@ var app=new Vue({
source_ip:"", source_ip:"",
created_at:"", created_at:"",
}, },
visitorExtra:[],
visitors:[], visitors:[],
visitorCount:0, visitorCount:0,
visitorCurrentPage:1, visitorCurrentPage:1,
@ -377,9 +378,18 @@ var app=new Vue({
// _this.visitor.client_ip=r.client_ip; // _this.visitor.client_ip=r.client_ip;
// _this.visitor.source_ip=r.source_ip; // _this.visitor.source_ip=r.source_ip;
_this.visitor.status=r.status==1?"在线":"离线"; _this.visitor.status=r.status==1?"在线":"离线";
//_this.visitor.visitor_id=r.visitor_id; //_this.visitor.visitor_id=r.visitor_id;
_this.chatTitle="#"+r.id+"|"+r.name; _this.chatTitle="#"+r.id+"|"+r.name;
_this.chatTitleType="success"; _this.chatTitleType="success";
if(r.extra!=""){
var extra=JSON.parse(b64ToUtf8(r.extra));
for(var key in extra){
var temp={key:key,val:extra[key]}
_this.visitorExtra.push(temp);
}
}
} }
if(data.code!=200){ if(data.code!=200){
_this.$message({ _this.$message({

@ -159,8 +159,9 @@ new Vue({
visitor_id=obj.visitor_id; visitor_id=obj.visitor_id;
} }
let _this=this; let _this=this;
var extra=getQuery("extra");
//发送消息 //发送消息
$.post("/visitor_login",{visitor_id:visitor_id,refer:REFER,to_id:KEFU_ID,client_ip:'',},function(res){ $.post("/visitor_login",{visitor_id:visitor_id,refer:REFER,to_id:KEFU_ID,extra:extra},function(res){
if(res.code!=200){ if(res.code!=200){
_this.$message({ _this.$message({
message: res.msg, message: res.msg,

@ -136,4 +136,10 @@ function getQuery(key) {
} }
return ""; return "";
} }
function utf8ToB64(str) {
return window.btoa(unescape(encodeURIComponent(str)));
}
function b64ToUtf8(str) {
return decodeURIComponent(escape(window.atob(str)));
}
; ;

@ -3,6 +3,7 @@ var GOFLY={
GOFLY_KEFU_ID:"", GOFLY_KEFU_ID:"",
GOFLY_BTN_TEXT:"Chat with me", GOFLY_BTN_TEXT:"Chat with me",
GOFLY_LANG:"en", GOFLY_LANG:"en",
GOFLY_EXTRA:"",
}; };
GOFLY.launchButtonFlag=false; GOFLY.launchButtonFlag=false;
GOFLY.titleTimer=0; GOFLY.titleTimer=0;
@ -26,6 +27,9 @@ GOFLY.init=function(config){
if (typeof config.GOFLY_BTN_TEXT!="undefined"){ if (typeof config.GOFLY_BTN_TEXT!="undefined"){
this.GOFLY_BTN_TEXT=config.GOFLY_BTN_TEXT; this.GOFLY_BTN_TEXT=config.GOFLY_BTN_TEXT;
} }
if (typeof config.GOFLY_EXTRA!="undefined"){
this.GOFLY_EXTRA=config.GOFLY_EXTRA;
}
this.dynamicLoadJs(this.GOFLY_URL+"/static/js/functions.js?v=1",function(){ this.dynamicLoadJs(this.GOFLY_URL+"/static/js/functions.js?v=1",function(){
if (typeof config.GOFLY_LANG!="undefined"){ if (typeof config.GOFLY_LANG!="undefined"){
@ -33,6 +37,7 @@ GOFLY.init=function(config){
}else{ }else{
_this.GOFLY_LANG=checkLang(); _this.GOFLY_LANG=checkLang();
} }
_this.GOFLY_EXTRA=utf8ToB64(_this.GOFLY_EXTRA);
}); });
if (typeof $!="function"){ if (typeof $!="function"){
@ -187,7 +192,7 @@ GOFLY.layerOpen=function (){
area: ['520px', '530px'], area: ['520px', '530px'],
offset: 'rb', //右下角弹出 offset: 'rb', //右下角弹出
anim: 2, anim: 2,
content: [this.GOFLY_URL+'/chatIndex?kefu_id='+this.GOFLY_KEFU_ID+'&lang='+this.GOFLY_LANG+'&refer='+window.document.title, 'yes'], //iframe的urlno代表不显示滚动条 content: [this.GOFLY_URL+'/chatIndex?kefu_id='+this.GOFLY_KEFU_ID+'&lang='+this.GOFLY_LANG+'&refer='+window.document.title+'&extra='+this.GOFLY_EXTRA , 'yes'], //iframe的urlno代表不显示滚动条
end: function(){ end: function(){
_this.launchButtonFlag=false; _this.launchButtonFlag=false;
$(".launchButtonBox").show(); $(".launchButtonBox").show();
@ -195,7 +200,7 @@ GOFLY.layerOpen=function (){
}); });
} }
GOFLY.windowOpen=function (){ GOFLY.windowOpen=function (){
window.open(this.GOFLY_URL+'/chatIndex?kefu_id='+this.GOFLY_KEFU_ID+'&lang='+this.GOFLY_LANG+'&refer='+window.document.title); window.open(this.GOFLY_URL+'/chatIndex?kefu_id='+this.GOFLY_KEFU_ID+'&lang='+this.GOFLY_LANG+'&refer='+window.document.title+'&extra='+this.GOFLY_EXTRA);
} }
GOFLY.flashTitle=function () { GOFLY.flashTitle=function () {
this.titleNum++; this.titleNum++;

Loading…
Cancel
Save