增加ip识别库和访客注册http接口

pull/23/head
陶士涵 4 years ago
parent 23e408ea47
commit b5ab613e4c

@ -2,11 +2,14 @@ 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"
"log"
"math/rand"
"strconv"
)
func PostVisitor(c *gin.Context) {
@ -55,6 +58,38 @@ func PostVisitor(c *gin.Context) {
"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("id")
refer := c.PostForm("refer")
var (
city string
name string
)
if ipcity!=nil{
city = ipcity.CountryName+ipcity.RegionName+ipcity.CityName
name=ipcity.CountryName+ipcity.RegionName+ipcity.CityName+"网友"
}else{
city="未识别地区"
name="匿名网友"
}
client_ip := c.PostForm("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,
"msg": "error",
})
return
}
models.CreateVisitor(name,avator,c.ClientIP(),toId,id,refer,city,client_ip)
c.JSON(200, gin.H{
"code": 200,
"msg": "ok",
})
}
func GetVisitor(c *gin.Context) {
visitorId:=c.Query("visitorId")
vistor:=models.FindVisitorByVistorId(visitorId)

@ -16,6 +16,7 @@ require (
github.com/go-sql-driver/mysql v1.5.0
github.com/gobuffalo/packr/v2 v2.5.1
github.com/gorilla/websocket v1.4.2
github.com/ipipdotnet/ipdb-go v1.3.0
github.com/jinzhu/gorm v1.9.14
github.com/spf13/cobra v0.0.5
github.com/swaggo/gin-swagger v1.2.0

@ -91,6 +91,8 @@ github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/ipipdotnet/ipdb-go v1.3.0 h1:FfkSkAI1do3bZ7F35ueGuF7Phur64jmikQ1C4IPl/gc=
github.com/ipipdotnet/ipdb-go v1.3.0/go.mod h1:yZ+8puwe3R37a/3qRftXo40nZVQbxYDLqls9o5foexs=
github.com/jinzhu/gorm v1.9.14 h1:Kg3ShyTPcM6nzVo148fRrcMO6MNKuqtOUwnzqMgVniM=
github.com/jinzhu/gorm v1.9.14/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=

@ -40,6 +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",controller.PostVisitor)
engine.GET("/visitor",middleware.JwtApiMiddleware, controller.GetVisitor)
engine.GET("/visitors",middleware.JwtApiMiddleware, controller.GetVisitors)

@ -19,73 +19,6 @@
height: 100%;
background: #fff;
}
.chatCenter{background: #fff;max-width: 800px;margin: 0 auto;}
.chatContext{
padding:0 10px;
width: 100%;
text-align: left;
position: relative;
margin-bottom: 86px;
}
.chatBox{
/*max-height: 600px;*/
/*overflow-y: auto;*/
/*overflow-x: hidden;*/
/*margin-bottom: 80px;*/
}
.chatBox .el-col{margin:10px 0;}
.chatUser{
line-height: 24px;
font-size: 12px;
white-space: nowrap;
color: #999;
text-align: left;
}
.chatContent{
background-color: rgb(166,212,242);
color: #000;
border: 1px solid rgb(152, 199, 230);
padding: 8px 15px;
min-height: 35px;
word-break: break-all;
position: relative;
border-radius: 5px;
display: inline-block;
margin-left: 6px;
}
.chatContent:after {
content: '';
position: absolute;
left: -10px;
top: 13px;
width: 0;
height: 0;
border-style: dashed;
border-color: transparent;
overflow: hidden;
border-width: 10px;
border-top-style: solid;
border-top-color: rgb(166,212,242);
}
.chatBoxMe .chatContent{float: right;background-color: rgb(152,225,101);border: 1px solid rgb(145, 215, 96);}
.chatBoxMe .chatContent:after{border-top-color: rgb(152,225,101);}
.chatBoxMe .el-col-3{float: right;text-align: right;}
.chatBoxMe .chatUser{text-align: right}
.chatBoxMe .chatContent:after{left:auto;right: -10px;}
/*.chatArea{float: left;width: 85%;margin: 4px 0 0 4px;}*/
.btnArea{width: 10%;float: right;}
@media screen and (max-width: 500px) {
body{background: #fff}
.chatArea {width: 70%;}
.btnArea{width: 20%;}
}
.chatTitle{height: 30px;line-height: 30px;color: #1989fa}
/*.chatBoxSend{background: #f5f5f5;position: fixed;bottom: 2px;width: 100%;height: 86px;max-width: 800px;}*/
.chatBoxSendBtn{float: right;margin: 12px 4px 0 0;}
.chatTime{text-align: center;color: #bbb;margin: 5px 0;font-size: 12px;}
.chatTimeHide{display: none;}
.clear{clear:both;}
</style>
</head>

@ -0,0 +1,18 @@
package tools
import (
"github.com/ipipdotnet/ipdb-go"
)
func ParseIp(myip string)(*ipdb.CityInfo) {
db, err := ipdb.NewCity("./config/city.free.ipdb")
if err != nil {
return nil
}
db.Reload("./config/city.free.ipdb")
c,err :=db.FindInfo(myip, "CN")
if err != nil {
return nil
}
return c
}
Loading…
Cancel
Save