From 1fb183f63b7bf44ddfd889e185ff47e55e2f55d9 Mon Sep 17 00:00:00 2001 From: aarongao Date: Fri, 14 Feb 2020 13:27:41 +0800 Subject: [PATCH] . --- API/DealyMessage.go | 6 +++--- API/EventLog.go | 54 ------------------------------------------------------ API/Sms.go | 6 +++--- API/User.go | 12 +++++++----- API/UserLog.go | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Config/AccessType/AccessType.go | 43 ------------------------------------------- Config/config.go | 9 ++++++--- Config/config.json | 3 +++ DB/db.go | 25 +++++++++++++++++++------ Lib/Token/token.go | 3 +++ Policy/Privacy.html | 0 Policy/User.html | 0 README.md | 58 ++++++++++++++++++++++++++++++++-------------------------- main.go | 20 ++++++++++++-------- 14 files changed, 154 insertions(+), 151 deletions(-) delete mode 100644 API/EventLog.go create mode 100644 API/UserLog.go delete mode 100644 Config/AccessType/AccessType.go create mode 100644 Policy/Privacy.html create mode 100644 Policy/User.html diff --git a/API/DealyMessage.go b/API/DealyMessage.go index 04e52b1..1212f54 100644 --- a/API/DealyMessage.go +++ b/API/DealyMessage.go @@ -24,7 +24,7 @@ func DealyMessageInfo(c *gin.Context) { if c.Query("Token") == "" || bson.IsObjectIdHex(c.Query("UserId")) == false { c.JSON(200, tools.ResponseError{ 1, - "参数不正确", + "Token或者用户id不正确", }) return } @@ -69,7 +69,7 @@ func CreateDealyMessage(c *gin.Context) { if c.PostForm("Token") == "" || bson.IsObjectIdHex(c.PostForm("UserId")) == false { c.JSON(200, tools.ResponseError{ 1, - "参数不正确", + "Token或者用户id不正确", }) return } @@ -117,7 +117,7 @@ func RemoveDealyMessage(c *gin.Context) { if c.PostForm("Token") == "" || bson.IsObjectIdHex(c.PostForm("UserId")) == false { c.JSON(200, tools.ResponseError{ 1, - "参数不正确", + "Token或者用户id不正确", }) return } diff --git a/API/EventLog.go b/API/EventLog.go deleted file mode 100644 index 8d63722..0000000 --- a/API/EventLog.go +++ /dev/null @@ -1,54 +0,0 @@ -package Api - -import ( - "encoding/json" - "github.com/aarongao/tools" - "github.com/gin-gonic/gin" - "letu/DB" - "strconv" -) - -// @Title 增加访问日志 -// @Description 增加访问日志 -// @Accept json -// @Produce json -// @Param UserId 5dfb03070a9ac17ac7a82054 string true "用户ID" -// @Param UserName Aaron string true "用户名称" -// @Param TypeNum 9 int true "类型编号" -// @Param TypeName 点击个人中心 string true "类型名称" -// @Param DateTime 1578556751220 int true "时间戳" -// @Param Location {"Latitude": 119, "Longitude": 39} string true "位置" -// @Param Remarks 备注 string true "备注" -// @Success 200 {object} tools.ResponseSeccess "" -// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" -// @Router /EventLog? [post] -func EventLog(c *gin.Context) { - c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) - c.Header("Access-Control-Allow-Credentials", "true") - - if c.Request.Method == "post" { - - var Location DB.SLocation - json.Unmarshal([]byte(c.PostForm("Location")), &Location) - - DateTime, _ := strconv.ParseInt(c.PostForm("DateTime"), 0, 64) - - TypeNum, _ := strconv.ParseInt("TypeNum", 0, 64) - - DB.CEventLog.Insert(DB.SEventLog{ - c.PostForm("UserId"), - c.PostForm("UserName"), - TypeNum, - c.PostForm("TypeName"), - DateTime, - Location, - c.PostForm("Remarks"), - }) - - c.JSON(200, tools.ResponseSeccess{ - 0, - "ok", - }) - } - -} diff --git a/API/Sms.go b/API/Sms.go index db8ac09..ed39595 100644 --- a/API/Sms.go +++ b/API/Sms.go @@ -75,12 +75,12 @@ func Send(c *gin.Context) { json.Unmarshal([]byte(c.PostForm("Location")), &Location) //go func(res *dysmsapi.SendSmsResponse) { - DB.CActionLog.Insert(DB.SActionLog{ + DB.CSystemLog.Insert(DB.SSystemLog{ "", "", c.PostForm("Mobile"), - 1, - "注册验证码", + 6001, + "调用第三方发送短信接口", time.Now().Unix(), Location, string(code), diff --git a/API/User.go b/API/User.go index 4ea3384..c6841d9 100644 --- a/API/User.go +++ b/API/User.go @@ -69,6 +69,7 @@ func LoginUser(c *gin.Context) { c.PostForm("Mobile"), "", "", + "", } DB.CMember.Insert(User) } @@ -90,6 +91,7 @@ func LoginUser(c *gin.Context) { // 更新token Token.SaveToken(User.Id.Hex(), token) + User.Token = token c.JSON(200, tools.ResponseSeccess{ 0, User, @@ -114,7 +116,7 @@ func UserInfo(c *gin.Context) { if c.Query("Token") == "" || bson.IsObjectIdHex(c.Query("id")) == false{ c.JSON(200, tools.ResponseError{ 1, - "参数不正确", + "Token或者用户id不正确", }) return } @@ -153,15 +155,15 @@ func CheckToken(c *gin.Context) { c.Header("Access-Control-Allow-Credentials", "true") - if c.Query("Token") == "" || bson.IsObjectIdHex(c.Query("id")) == false{ + if c.PostForm("Token") == "" || bson.IsObjectIdHex(c.PostForm("id")) == false{ c.JSON(200, tools.ResponseError{ 1, - "参数不正确", + "Token或者用户id不正确", }) return } - if Token.GetToken(c.Query("id")) != c.Query("Token"){ + if Token.GetToken(c.PostForm("id")) != c.PostForm("Token"){ c.JSON(200, tools.ResponseError{ 401, "token过期", @@ -200,7 +202,7 @@ func UpdateUser(c *gin.Context) { if c.PostForm("Token") == "" || bson.IsObjectIdHex(c.PostForm("id")) == false{ c.JSON(200, tools.ResponseError{ 1, - "参数不正确", + "Token或者用户id不正确", }) return } diff --git a/API/UserLog.go b/API/UserLog.go new file mode 100644 index 0000000..0759ca2 --- /dev/null +++ b/API/UserLog.go @@ -0,0 +1,66 @@ +package Api + +import ( + "encoding/json" + "github.com/aarongao/tools" + "github.com/gin-gonic/gin" + "letu/DB" + "time" +) + +// @Title 增加访问日志 +// @Description 增加访问日志 +// @Accept json +// @Produce json +// @Param Type 安装app string true "安装;卸载;访问页面;使用功能;缩放地图" +// @Param SubType 景区详情 string true "推荐;景区详情;登陆;商城;投诉建议;问券调查...." +// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id" +// @Param UserId 5dfb03070a9ac17ac7a82054 string true "用户ID" +// @Param UserName Aaron string true "用户名称" +// @Param Location {"Latitude": 119, "Longitude": 39} string true "位置" +// @Param Remarks 备注 string true "备注" +// @Param Source 用户分享 string true "Source" +// @Param DeviceId abc123 string true "手机唯一识别码,不重复(存放于http.header中)" +// @Param Mac abc123 string true "网卡Mac地址(存放于http.header中)" +// @Param SystemType ios string true "ios,android(存放于http.header中)" +// @Param SystemVersion 13.01 string true "手机版本(存放于http.header中)" +// @Param SystemModel iphone8 string true "手机型号(存放于http.header中)" +// @Success 200 {object} tools.ResponseSeccess "" +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" +// @Router /UserLog? [post] +func UserLog(c *gin.Context) { + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) + c.Header("Access-Control-Allow-Credentials", "true") + + if c.Request.Method == "post" { + + var Location DB.SLocation + json.Unmarshal([]byte(c.PostForm("Location")), &Location) + + DB.CUserLog.Insert(DB.SUserLog{ + c.PostForm("Type"), + c.PostForm("SubType"), + c.PostForm("ScenicId"), + c.PostForm("UserId"), + c.PostForm("UserName"), + time.Now().Unix(), + Location, + c.PostForm("Remarks"), + c.PostForm("Source"), + DB.SDevice{ + c.Request.Header.Get("DeviceId"), + c.Request.Host, + c.Request.Header.Get("Mac"), + c.Request.Header.Get("SystemType"), + c.Request.Header.Get("SystemVersion"), + c.Request.Header.Get("SystemModel"), + }, + }) + + c.JSON(200, tools.ResponseSeccess{ + 0, + "ok", + }) + } + +} diff --git a/Config/AccessType/AccessType.go b/Config/AccessType/AccessType.go deleted file mode 100644 index fd6fb86..0000000 --- a/Config/AccessType/AccessType.go +++ /dev/null @@ -1,43 +0,0 @@ -package EventType - -type EventType int32 - -const ( - PageForIndex EventType = 1 - PageForRecommendMenu EventType = 2 - PageForPlayItemMenu EventType = 3 - PageForPerformMenu EventType = 4 - PageForServiceMenu EventType = 5 - PageForRestaurantMenu EventType = 6 - TouchAnnotation EventType = 7 - TouchShopMenu EventType = 8 - TouchMyMenu EventType = 9 - TouchComplaintMenu EventType = 10 -) - -func (o EventType) String() string { - switch (o) { - case PageForIndex: - return "首页" - case PageForRecommendMenu: - return "推荐" - case PageForPlayItemMenu: - return "游玩项目" - case PageForPerformMenu: - return "演出活动" - case PageForServiceMenu: - return "服务设施" - case PageForRestaurantMenu: - return "餐饮购物" - case TouchAnnotation: - return "点击建筑图标" - case TouchShopMenu: - return "点击商店" - case TouchMyMenu: - return "点击个人中心" - case TouchComplaintMenu: - return "点击投诉&意见" - default: - return "UNKNOWN" - } -} diff --git a/Config/config.go b/Config/config.go index ff60bfa..130a491 100644 --- a/Config/config.go +++ b/Config/config.go @@ -1,7 +1,10 @@ package Config type Config struct { - TagType []string - DbPath string - RedisPath string + TagType []string + DbPath string + DbName string + DbUser string + DbPassword string + RedisPath string } diff --git a/Config/config.json b/Config/config.json index 47c9d38..eddf812 100644 --- a/Config/config.json +++ b/Config/config.json @@ -1,5 +1,8 @@ { "tagType": ["menu","normal"], "dbPath": "127.0.0.1:27017", + "dbName": "LeYouTu", + "dbUser": "leyoutu", + "dbPassword": "leyoutu123456", "redisPath": "127.0.0.1:6379" } diff --git a/DB/db.go b/DB/db.go index 3a45dc3..54d096e 100644 --- a/DB/db.go +++ b/DB/db.go @@ -17,8 +17,8 @@ var CCommodity *mgo.Collection //商城 var CTags *mgo.Collection //标签 var CScenic *mgo.Collection //景区 var CLine *mgo.Collection //推荐线路 -var CEventLog *mgo.Collection //用户行为记录 -var CActionLog *mgo.Collection //操作记录 +var CUserLog *mgo.Collection //用户行为记录 +var CSystemLog *mgo.Collection //操作记录 var CTrajectory *mgo.Collection //移动轨迹 var CIcons *mgo.Collection //图标信息 var DB *mgo.Database @@ -59,16 +59,28 @@ type SLocation struct { Latitude float64 `bson:"Latitude" json:"Latitude"` //纬度 Longitude float64 `bson:"Longitude" json:"Longitude"` //经度 } -type SEventLog struct { + +type SDevice struct { + DeviceId string `bson:"DeviceId" json:"DeviceId"` + Ip string `bson:"Ip" json:"Ip"` + Mac string `bson:"Mac" json:"Mac"` + SystemType string `bson:"SystemType" json:"SystemType"` //ios,android + SystemVersion string `bson:"SystemVersion" json:"SystemVersion"` //系统版本 + SystemModel string `bson:"SystemModel" json:"SystemModel"` //机型 +} +type SUserLog struct { + Type string `bson:"Type" json:"Type"` // Log(事件)类型 + SubType string `bson:"SubType" json:"SubType"` // 分类 + ScenicId string `bson:"ScenicId" json:"ScenicId"` UserId string `bson:"UserId" json:"UserId"` // 用户ID UserName string `bson:"UserName" json:"UserName"` //用户名称 - TypeNum int64 `bson:"TypeNum" json:"TypeNum"` //类型编号 - TypeName string `bson:"TypeName" json:"TypeName"` //类型名称 DateTime int64 `bson:"DateTime" json:"DateTime"` //时间戳 Location SLocation `bson:"Location" json:"Location"` //位置 Remarks string `bson:"Remarks" json:"Remarks"` //备注 + Source string `bson:"Source" json:"Source"` //来源 + Device SDevice `bson:"Device" json:"Device"` //设备信息 } -type SActionLog struct { +type SSystemLog struct { UserId string `bson:"UserId" json:"UserId"` // 用户ID UserName string `bson:"UserName" json:"UserName"` //用户名称 Mobile string `bson:"Mobile" json:"Mobile"` //手机号 @@ -123,6 +135,7 @@ type SMember struct { FullName string `bson:"FullName" json:"FullName"` Mobile string `bson:"Mobile" json:"Mobile"` Openid string `bson:"Openid" json:"Openid"` + Token string `bson:"Token" json:"Token"` Sex string `bson:"Sex" json:"Sex"` } diff --git a/Lib/Token/token.go b/Lib/Token/token.go index 57a76dd..4586a02 100644 --- a/Lib/Token/token.go +++ b/Lib/Token/token.go @@ -7,6 +7,9 @@ import ( func GetToken(mobile string) string { token := DB.Redis.Get("token_" + mobile) + if token == nil { + return "" + } return token.(string) } diff --git a/Policy/Privacy.html b/Policy/Privacy.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Policy/Privacy.html diff --git a/Policy/User.html b/Policy/User.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Policy/User.html diff --git a/README.md b/README.md index 49d1362..1d8688c 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,6 @@ 1. [查询用户的定时提醒](#dealymessage-info-get) 1. [创建提醒](#dealymessage-create-post) 1. [删除提醒](#dealymessage-remove-post) -1. [增加访问日志](#eventlog-post) 1. [图标管理 - 返回图标基础信息](#icon-info-get) 1. [图标管理 - 增加或修改图标信息](#icon-update-post) 1. [图标管理 - 所有图标](#icon-all-get) @@ -41,6 +40,7 @@ 1. [用户管理 - 修改用户信息](#updateuser-post) 1. [上传](#upload-post) 1. [用户管理 - 获取用户信息](#userinfo-get) +1. [增加访问日志](#userlog-post) @@ -261,31 +261,6 @@ - - -#### /EventLog (POST) - - -增加访问日志 - -| Param Name | Example | Data Type | Description | Required? | -|-----|-----|-----|-----|-----| -| UserId | 5dfb03070a9ac17ac7a82054 | string | 用户ID | Yes | -| UserName | Aaron | string | 用户名称 | Yes | -| TypeNum | 9 | int | 类型编号 | Yes | -| TypeName | 点击个人中心 | string | 类型名称 | Yes | -| DateTime | 1578556751220 | int | 时间戳 | Yes | -| Location | {"Latitude": 119, "Longitude": 39} | string | 位置 | Yes | -| Remarks | 备注 | string | 备注 | Yes | - - -| Code | Type | Model | Message | -|-----|-----|-----|-----| -| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | | -| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | - - - #### /Icon/Info (GET) @@ -655,3 +630,34 @@ | 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | + + + +#### /UserLog (POST) + + +增加访问日志 + +| Param Name | Example | Data Type | Description | Required? | +|-----|-----|-----|-----|-----| +| Type | 安装app | string | 安装;卸载;访问页面;使用功能;缩放地图 | Yes | +| SubType | 景区详情 | string | 推荐;景区详情;登陆;商城;投诉建议;问券调查.... | Yes | +| ScenicId | 5dfb03070a9ac17ac7a82054 | string | 景区id | Yes | +| UserId | 5dfb03070a9ac17ac7a82054 | string | 用户ID | Yes | +| UserName | Aaron | string | 用户名称 | Yes | +| Location | {"Latitude": 119, "Longitude": 39} | string | 位置 | Yes | +| Remarks | 备注 | string | 备注 | Yes | +| Source | 用户分享 | string | Source | Yes | +| DeviceId | abc123 | string | 手机唯一识别码,不重复(存放于http.header中) | Yes | +| Mac | abc123 | string | 网卡Mac地址(存放于http.header中) | Yes | +| SystemType | ios | string | ios,android(存放于http.header中) | Yes | +| SystemVersion | 13.01 | string | 手机版本(存放于http.header中) | Yes | +| SystemModel | iphone8 | string | 手机型号(存放于http.header中) | Yes | + + +| Code | Type | Model | Message | +|-----|-----|-----|-----| +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | | +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | + + diff --git a/main.go b/main.go index eab8bb9..7dcaab7 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,7 @@ func main() { // 连接数据库 DB.DBSession, err = mgo.Dial(conf.DbPath) + defer DB.DBSession.Close() // 连接redis @@ -47,7 +48,9 @@ func main() { //设置模式 DB.DBSession.SetMode(mgo.Monotonic, true) //获取文档集 - DB.DB = DB.DBSession.DB("LeYouTu") + DB.DB = DB.DBSession.DB(conf.DbName) + DB.DB.Login(conf.DbUser, conf.DbPassword) + DB.CItem = DB.DB.C("Item") DB.CComplaint = DB.DB.C("Complaint") DB.CInvestigation = DB.DB.C("Investigation") @@ -56,8 +59,8 @@ func main() { DB.CTags = DB.DB.C("Tags") DB.CScenic = DB.DB.C("Scenic") DB.CLine = DB.DB.C("Line") - DB.CEventLog = DB.DB.C("EventLog") - DB.CActionLog = DB.DB.C("ActionLog") + DB.CUserLog = DB.DB.C("UserLog") + DB.CSystemLog = DB.DB.C("SystemLog") DB.CInvestigation = DB.DB.C("Investigation") DB.CTrajectory = DB.DB.C("Trajectory") DB.CIcons = DB.DB.C("Icons") @@ -66,8 +69,6 @@ func main() { r := gin.Default() //r.Static("/.well-known", "./.well-known/") - //r.Static("/tiles", dir+"/tiles") - r.GET("/Tiles", Api.Tiles) r.GET("/AllItems", Api.AllItems) r.GET("/AllItemTime", Api.AllItemTime) r.GET("/AllCommodity", Api.AllCommodity) @@ -90,8 +91,8 @@ func main() { r.POST("/UpdateScenic", Api.UpdateScenic) r.POST("/UpdateItemTime", Api.UpdateItemTime) r.GET("/AllScenic", Api.AllScenic) - r.POST("/EventLog", Api.EventLog) - r.GET("/EventLog", Api.EventLog) + r.POST("/UserLog", Api.UserLog) + r.GET("/UserLog", Api.UserLog) r.POST("/Sms/Send", Api.Send) r.POST("/Investigation/Save", Api.SaveInvestigation) r.GET("/Investigation/List", Api.AllInvestigation) @@ -102,11 +103,14 @@ func main() { r.POST("/Icon/Update", Api.UpdateIcon) r.GET("/Icon/All", Api.AllIcons) r.GET("/Icon/Info", Api.IconInfo) - r.GET("/CheckToken", Api.CheckToken) + r.POST("/CheckToken", Api.CheckToken) + r.GET("/Tiles", Api.Tiles) //r.GET("/ws", Api.WsPage) r.Static("/Upload", "./Upload") r.Static("/Console", "./Console") + r.Static("/Policy", dir+"/Policy") + r.Static("/tiles2", dir+"/tiles") // go Ws.Manager.Start() // 创建延迟消息 -- libgit2 0.21.0