增加而外的字段

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

@ -30,7 +30,8 @@ CREATE TABLE `visitor` (
`status` tinyint(4) NOT NULL DEFAULT '0',
`refer` varchar(500) 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`),
UNIQUE KEY `visitor_id` (`visitor_id`),
KEY `to_id` (`to_id`)

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

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

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

@ -161,12 +161,6 @@
<span slot="title">ClientIP<{visitor.source_ip}></span>
</el-menu-item>
</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;">
<i class="el-icon-s-tools"></i>
<span slot="title">城市:<{visitor.city}></span>
@ -192,6 +186,12 @@
<span slot="title">状态:<{visitor.status}></span>
</el-menu-item>
</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-tab-pane>
<el-tab-pane label="黑名单" name="blackList">

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

@ -31,6 +31,7 @@ var app=new Vue({
source_ip:"",
created_at:"",
},
visitorExtra:[],
visitors:[],
visitorCount:0,
visitorCurrentPage:1,
@ -377,9 +378,18 @@ var app=new Vue({
// _this.visitor.client_ip=r.client_ip;
// _this.visitor.source_ip=r.source_ip;
_this.visitor.status=r.status==1?"在线":"离线";
//_this.visitor.visitor_id=r.visitor_id;
_this.chatTitle="#"+r.id+"|"+r.name;
_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){
_this.$message({

@ -159,8 +159,9 @@ new Vue({
visitor_id=obj.visitor_id;
}
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){
_this.$message({
message: res.msg,

@ -136,4 +136,10 @@ function getQuery(key) {
}
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_BTN_TEXT:"Chat with me",
GOFLY_LANG:"en",
GOFLY_EXTRA:"",
};
GOFLY.launchButtonFlag=false;
GOFLY.titleTimer=0;
@ -26,6 +27,9 @@ GOFLY.init=function(config){
if (typeof config.GOFLY_BTN_TEXT!="undefined"){
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(){
if (typeof config.GOFLY_LANG!="undefined"){
@ -33,6 +37,7 @@ GOFLY.init=function(config){
}else{
_this.GOFLY_LANG=checkLang();
}
_this.GOFLY_EXTRA=utf8ToB64(_this.GOFLY_EXTRA);
});
if (typeof $!="function"){
@ -187,7 +192,7 @@ GOFLY.layerOpen=function (){
area: ['520px', '530px'],
offset: 'rb', //右下角弹出
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(){
_this.launchButtonFlag=false;
$(".launchButtonBox").show();
@ -195,7 +200,7 @@ GOFLY.layerOpen=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 () {
this.titleNum++;

Loading…
Cancel
Save