diff --git a/API/Complaint.go b/API/Complaint.go index 5f45e2b..8ea55ab 100644 --- a/API/Complaint.go +++ b/API/Complaint.go @@ -52,7 +52,7 @@ func CreateComplaint(c *gin.Context) { // 检查验证码 - cacheCode := DB.Redis.Get(c.PostForm("Mobile")) + cacheCode := DB.Redis.Get("code_"+c.PostForm("Mobile")) if cacheCode != c.PostForm("Code") { c.JSON(200, tools.ResponseError{ diff --git a/API/DealyMessage.go b/API/DealyMessage.go index 938c35c..cc6f27e 100644 --- a/API/DealyMessage.go +++ b/API/DealyMessage.go @@ -5,6 +5,7 @@ import ( "github.com/gin-gonic/gin" "gopkg.in/mgo.v2/bson" "letu/Lib/DelayMessage" + "letu/Lib/Token" ) // @Title 查询用户的定时提醒 @@ -12,6 +13,7 @@ import ( // @Accept json // @Produce json // @Param UserId 5dfb03070a9ac17ac7a82054 string true "用户id" +// @Param Token wgergejfwe string true "用户token" // @Success 200 {object} tools.ResponseSeccess "DelayTime=执行时间;Type=类型(0请求url地址1发送app通知);Fail失败次数;Title=通知标题;Content=通知内容;UDID=设备id" // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" // @Router /DealyMessage/Info? [get] @@ -19,6 +21,22 @@ func DealyMessageInfo(c *gin.Context) { c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) c.Header("Access-Control-Allow-Credentials", "true") + if c.Query("Token") == "" || bson.IsObjectIdHex(c.Query("UserId")) == false { + c.JSON(200, tools.ResponseError{ + 1, + "参数不正确", + }) + return + } + + if Token.GetToken(c.Query("UserId")) != c.Query("Token") { + c.JSON(200, tools.ResponseError{ + 1, + "token不正确", + }) + return + } + var aDelayMessage []DelayMessage.Message DelayMessage.CDelayMessage.Find(bson.M{"UserId": c.Query("UserId")}).All(&aDelayMessage) @@ -36,6 +54,7 @@ func DealyMessageInfo(c *gin.Context) { // @Accept json // @Produce json // @Param UserId 5dfb03070a9ac17ac7a82054 string true "用户id" +// @Param Token wgergejfwe string true "用户token" // @Param UDID 5dfb03070a9ac17ac7a82054 string true "设备id" // @Param Title 表演时间提醒 string true "标题" // @Param Content 5分钟后有表演 string true "内容" @@ -47,6 +66,22 @@ func CreateDealyMessage(c *gin.Context) { c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) c.Header("Access-Control-Allow-Credentials", "true") + if c.PostForm("Token") == "" || bson.IsObjectIdHex(c.PostForm("UserId")) == false { + c.JSON(200, tools.ResponseError{ + 1, + "参数不正确", + }) + return + } + + if Token.GetToken(c.PostForm("UserId")) != c.PostForm("Token") { + c.JSON(200, tools.ResponseError{ + 1, + "token不正确", + }) + return + } + err := DelayMessage.GlobalDM.AddTaskForAppMessage(c.PostForm("DelayTime"), c.PostForm("UDID"), c.PostForm("Title"), c.PostForm("Content"), c.PostForm("UserId")) if err == nil { @@ -70,6 +105,8 @@ func CreateDealyMessage(c *gin.Context) { // @Accept json // @Produce json // @Param id 5dfb03070a9ac17ac7a82054 string true "提醒id" +// @Param UserId 5dfb03070a9ac17ac7a82054 string true "用户id" +// @Param Token wgergejfwe string true "用户token" // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}" // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" // @Router /DealyMessage/Remove? [post] @@ -77,11 +114,18 @@ func RemoveDealyMessage(c *gin.Context) { c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) c.Header("Access-Control-Allow-Credentials", "true") + if c.PostForm("Token") == "" || bson.IsObjectIdHex(c.PostForm("UserId")) == false { + c.JSON(200, tools.ResponseError{ + 1, + "参数不正确", + }) + return + } - if bson.IsObjectIdHex(c.PostForm("id")) == false { + if Token.GetToken(c.PostForm("UserId")) != c.PostForm("Token") { c.JSON(200, tools.ResponseError{ 1, - "id不正确", + "token不正确", }) return } diff --git a/API/Icon.go b/API/Icon.go new file mode 100644 index 0000000..2c0cb66 --- /dev/null +++ b/API/Icon.go @@ -0,0 +1,113 @@ +package Api + +import ( + "github.com/aarongao/tools" + "github.com/gin-gonic/gin" + "gopkg.in/mgo.v2/bson" + "letu/DB" +) + +// @Title 返回图标基础信息 +// @Description 图标管理 - 返回图标基础信息 +// @Accept json +// @Produce json +// @Param id 5dfb03070a9ac17ac7a82054 string true "图标id" +// @Success 200 {object} tools.ResponseSeccess "Name名称:Picture图片地址:id图标id" +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" +// @Router /Icon/Info? [get] +func IconInfo(c *gin.Context) { + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) + c.Header("Access-Control-Allow-Credentials", "true") + + if c.Query("id") == "" { + c.JSON(200, tools.ResponseError{ + 1, + "id为空", + }) + return + } + + var SIcon *DB.SIcons + DB.CIcons.Find(bson.M{"_id": bson.ObjectIdHex(c.Query("id"))}).One(&SIcon) + + c.JSON(200, tools.ResponseSeccess{ + 0, + SIcon, + }) + +} + +// @Title 更新图标信息 +// @Description 图标管理 - 增加或修改图标信息 +// @Accept json +// @Produce json +// @Param id 5dfb03070a9ac17ac7a82054 string true "图标id" +// @Success 200 {object} tools.ResponseSeccess "Name名称:Picture图片地址:id图标id:ScenicId景区id" +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" +// @Router /Icon/Update? [post] +func UpdateIcon(c *gin.Context) { + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) + c.Header("Access-Control-Allow-Credentials", "true") + + ScenicId := c.PostForm("ScenicId") + if ScenicId == "" || ScenicId == "undefined" { + c.JSON(200, tools.ResponseError{ + 1, + "缺少scenicid(景区id)", + }) + return + } + + var id bson.ObjectId + if pid := c.PostForm("id"); pid == "null" { + id = bson.NewObjectId() + } else { + id = bson.ObjectIdHex(pid) + } + + DB.CIcons.UpsertId( + id, + bson.M{"$set": bson.M{ + "Name": c.PostForm("Name"), + "Picture": c.PostForm("Picture"), + "ScenicId": ScenicId, + }}, + ) + + c.JSON(200, tools.ResponseSeccess{ + 0, + "ok", + }) + +} + +// @Title 所有图标 +// @Description 图标管理 - 所有图标 +// @Accept json +// @Produce json +// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id" +// @Success 200 {object} tools.ResponseSeccess "Name名称:Picture图片地址:id图标id:ScenicId景区id" +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" +// @Router /Icon/All? [get] +func AllIcons(c *gin.Context) { + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) + c.Header("Access-Control-Allow-Credentials", "true") + + ScenicId := c.Query("ScenicId") + if ScenicId == "" || ScenicId == "undefined" { + c.JSON(200, tools.ResponseError{ + 1, + "缺少scenicid(景区id)", + }) + return + } + + var SIcons = []*DB.SIcons{} + DB.CIcons.Find(bson.M{"ScenicId": ScenicId}).All(&SIcons) + + c.JSON(200, tools.ResponseSeccess{ + 0, + SIcons, + }) + +} diff --git a/API/Sms.go b/API/Sms.go index 28e4074..db8ac09 100644 --- a/API/Sms.go +++ b/API/Sms.go @@ -38,7 +38,7 @@ func Send(c *gin.Context) { return } - cacheCode := DB.Redis.Get(c.PostForm("Mobile")) + cacheCode := DB.Redis.Get("code_"+c.PostForm("Mobile")) if cacheCode != nil { c.JSON(200, tools.ResponseError{ 1, @@ -67,7 +67,7 @@ func Send(c *gin.Context) { } else { reserr = response.Code if response.Code == "OK" { - DB.Redis.Set(c.PostForm("Mobile"), code, time.Second*60) + DB.Redis.Set("code_"+c.PostForm("Mobile"), code, time.Second*60) } } diff --git a/API/User.go b/API/User.go index 46709d9..b338896 100644 --- a/API/User.go +++ b/API/User.go @@ -7,12 +7,12 @@ import ( "github.com/gin-gonic/gin" "gopkg.in/mgo.v2/bson" "letu/DB" + "letu/Lib/Token" "regexp" "strconv" "time" ) - var Regular = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$" // @Title 登录 @@ -51,7 +51,7 @@ func LoginUser(c *gin.Context) { token := hex.EncodeToString(tokenunit8[:32]) // 检查验证码 - cacheCode := DB.Redis.Get(c.PostForm("Mobile")) + cacheCode := DB.Redis.Get("code_" + c.PostForm("Mobile")) selected := bson.M{} var User *DB.SMember if cacheCode == c.PostForm("Code") { @@ -61,46 +61,35 @@ func LoginUser(c *gin.Context) { // 验证码匹配,但手机号不存在 if User == nil { objectID := bson.NewObjectId() - oUser := DB.SMember{ + User := DB.SMember{ &objectID, "", "", "", c.PostForm("Mobile"), "", - token, "", } - DB.CMember.Insert(oUser) - //if err == nil { - c.JSON(200, tools.ResponseSeccess{ - 0, - oUser, - }) - return - //} + DB.CMember.Insert(User) } } else { - selected["Mobile"] = c.PostForm("Mobile") - selected["Code"] = c.PostForm("Code") - DB.CMember.Find(selected).One(&User) - if User == nil { - c.JSON(200, tools.ResponseError{ - 1, - "用户不存在或密码不正确", - }) - return - } + c.JSON(200, tools.ResponseError{ + 1, + "验证码不正确", + }) + return } // 更新用户信息 - DB.CMember.Update( - bson.M{"_id": User.Id}, - bson.M{"$set": bson.M{"Token": token}}, - ) + //DB.CMember.Update( + // bson.M{"_id": User.Id}, + // bson.M{"$set": bson.M{"Token": token}}, + //) + + // 更新token + Token.SaveToken(User.Id.Hex(), token) - User.Token = token c.JSON(200, tools.ResponseSeccess{ 0, User, @@ -113,6 +102,7 @@ func LoginUser(c *gin.Context) { // @Accept json // @Produce json // @Param id aaron string true "用户id" +// @Param Token wgergejfwe string true "用户token" // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":{"Id":"5e09c64c1c09c6f0f7ca2fa9","Token":"640bf934e425aba5d3c90998b2641f2f0ca07261d334d9615d1cd4790b5f34e7"}}" // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" // @Router /UserInfo? [get] @@ -120,10 +110,19 @@ func UserInfo(c *gin.Context) { c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) c.Header("Access-Control-Allow-Credentials", "true") - if c.Query("id") == "" { + + if c.Query("Token") == "" || bson.IsObjectIdHex(c.Query("id")) == false{ c.JSON(200, tools.ResponseError{ 1, - "空", + "参数不正确", + }) + return + } + + if Token.GetToken(c.Query("id")) != c.Query("Token"){ + c.JSON(200, tools.ResponseError{ + 1, + "token不正确", }) return } @@ -142,6 +141,8 @@ func UserInfo(c *gin.Context) { // @Description 用户管理 - 修改用户信息 // @Accept json // @Produce json +// @Param id aaron string true "用户id"" +// @Param Token wgergejfwe string true "用户token" // @Param Birthday 2010.10.10 string true "生日" // @Param FullName aarongao string true "全名" // @Param Code 12345678 string true "6位验证码" @@ -155,6 +156,24 @@ func UpdateUser(c *gin.Context) { c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) c.Header("Access-Control-Allow-Credentials", "true") + + if c.PostForm("Token") == "" || bson.IsObjectIdHex(c.PostForm("id")) == false{ + c.JSON(200, tools.ResponseError{ + 1, + "参数不正确", + }) + return + } + + if Token.GetToken(c.PostForm("id")) != c.PostForm("Token"){ + c.JSON(200, tools.ResponseError{ + 1, + "token不正确", + }) + return + } + + reg := regexp.MustCompile(Regular) if !reg.MatchString(c.PostForm("Mobile")) { @@ -182,7 +201,7 @@ func UpdateUser(c *gin.Context) { //} // 检查验证码 - code := DB.Redis.Get(c.PostForm("Mobile")) + code := DB.Redis.Get("code_" + c.PostForm("Mobile")) if code == "" || code != c.PostForm("Code") { c.JSON(200, tools.ResponseError{ 1, @@ -192,19 +211,18 @@ func UpdateUser(c *gin.Context) { } err := DB.CMember.Update( - bson.M{"Mobile": c.PostForm("Mobile")}, + bson.M{"_id": bson.ObjectIdHex(c.PostForm("id"))}, bson.M{"$set": bson.M{ "Birthday": c.PostForm("Birthday"), "FullName": c.PostForm("FullName"), "Mobile": c.PostForm("Mobile"), - "Sex": c.PostForm("Sex"), + "Sex": c.PostForm("Sex"), }}, ) if err == nil { - var User *DB.SMember - DB.CMember.Find(bson.M{"Mobile": c.PostForm("Mobile")}).One(&User) + DB.CMember.Find(bson.M{"_id": bson.ObjectIdHex(c.PostForm("id"))}).One(&User) c.JSON(200, tools.ResponseSeccess{ 0, diff --git a/DB/db.go b/DB/db.go index b879832..3a45dc3 100644 --- a/DB/db.go +++ b/DB/db.go @@ -20,6 +20,7 @@ var CLine *mgo.Collection //推荐线路 var CEventLog *mgo.Collection //用户行为记录 var CActionLog *mgo.Collection //操作记录 var CTrajectory *mgo.Collection //移动轨迹 +var CIcons *mgo.Collection //图标信息 var DB *mgo.Database type SItem struct { @@ -43,6 +44,12 @@ type SItem struct { Reminder string `bson:"Reminder" json:"Reminder"` //温馨提示 State int `bson:"State" json:"State"` // 运行状态0=正常1=停运 } +type SIcons struct { + Id *bson.ObjectId `bson:"_id" json:"Id" valid:"required"` + ScenicId string `bson:"ScenicId" json:"ScenicId"` + Name string `bson:"Name" json:"Name"` + Picture string `bson:"Picture" json:"Picture"` +} type STrajectory struct { UserId string `bson:"UserId" json:"UserId"` // 用户ID Location SLocation `bson:"Location" json:"Location"` @@ -116,7 +123,6 @@ 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 new file mode 100644 index 0000000..57a76dd --- /dev/null +++ b/Lib/Token/token.go @@ -0,0 +1,15 @@ +package Token + +import ( + "letu/DB" + "time" +) + +func GetToken(mobile string) string { + token := DB.Redis.Get("token_" + mobile) + return token.(string) +} + +func SaveToken(mobile, token string) { + DB.Redis.Set("token_"+mobile, token, time.Second*3600*24*7) +} diff --git a/README.md b/README.md index ddcdf8a..4127658 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ 1. [创建提醒](#dealymessage-create-post) 1. [删除提醒](#dealymessage-remove-post) 1. [增加访问日志](#eventlog-post) +1. [图标管理 - 返回图标基础信息](#icon-info-get) +1. [图标管理 - 增加或修改图标信息](#icon-update-post) +1. [图标管理 - 所有图标](#icon-all-get) 1. [问券调查 - 增加调查](#investigation-save-post) 1. [问券调查 - 查询所有问券调查](#investigation-list-get) 1. [设备管理 - 查询设备信息](#iteminfo-get) @@ -184,6 +187,7 @@ | Param Name | Example | Data Type | Description | Required? | |-----|-----|-----|-----|-----| | UserId | 5dfb03070a9ac17ac7a82054 | string | 用户id | Yes | +| Token | wgergejfwe | string | 用户token | Yes | | Code | Type | Model | Message | @@ -202,6 +206,7 @@ | Param Name | Example | Data Type | Description | Required? | |-----|-----|-----|-----|-----| | UserId | 5dfb03070a9ac17ac7a82054 | string | 用户id | Yes | +| Token | wgergejfwe | string | 用户token | Yes | | UDID | 5dfb03070a9ac17ac7a82054 | string | 设备id | Yes | | Title | 表演时间提醒 | string | 标题 | Yes | | Content | 5分钟后有表演 | string | 内容 | Yes | @@ -224,6 +229,8 @@ | Param Name | Example | Data Type | Description | Required? | |-----|-----|-----|-----|-----| | id | 5dfb03070a9ac17ac7a82054 | string | 提醒id | Yes | +| UserId | 5dfb03070a9ac17ac7a82054 | string | 用户id | Yes | +| Token | wgergejfwe | string | 用户token | Yes | | Code | Type | Model | Message | @@ -258,6 +265,61 @@ + + +#### /Icon/Info (GET) + + +图标管理 - 返回图标基础信息 + +| Param Name | Example | Data Type | Description | Required? | +|-----|-----|-----|-----|-----| +| id | 5dfb03070a9ac17ac7a82054 | string | 图标id | Yes | + + +| Code | Type | Model | Message | +|-----|-----|-----|-----| +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | Name名称:Picture图片地址:id图标id | +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | + + + + +#### /Icon/Update (POST) + + +图标管理 - 增加或修改图标信息 + +| Param Name | Example | Data Type | Description | Required? | +|-----|-----|-----|-----|-----| +| id | 5dfb03070a9ac17ac7a82054 | string | 图标id | Yes | + + +| Code | Type | Model | Message | +|-----|-----|-----|-----| +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | Name名称:Picture图片地址:id图标id:ScenicId景区id | +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | + + + + +#### /Icon/All (GET) + + +图标管理 - 所有图标 + +| Param Name | Example | Data Type | Description | Required? | +|-----|-----|-----|-----|-----| +| ScenicId | 5dfb03070a9ac17ac7a82054 | string | 景区id | Yes | + + +| Code | Type | Model | Message | +|-----|-----|-----|-----| +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | Name名称:Picture图片地址:id图标id:ScenicId景区id | +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | + + + #### /Investigation/Save (POST) @@ -517,6 +579,8 @@ | Param Name | Example | Data Type | Description | Required? | |-----|-----|-----|-----|-----| +| id | aaron | string | 用户id | Yes | +| Token | wgergejfwe | string | 用户token | Yes | | Birthday | 2010.10.10 | string | 生日 | Yes | | FullName | aarongao | string | 全名 | Yes | | Code | 12345678 | string | 6位验证码 | Yes | @@ -561,6 +625,7 @@ | Param Name | Example | Data Type | Description | Required? | |-----|-----|-----|-----|-----| | id | aaron | string | 用户id | Yes | +| Token | wgergejfwe | string | 用户token | Yes | | Code | Type | Model | Message | diff --git a/main.go b/main.go index e8f07e6..61efc67 100644 --- a/main.go +++ b/main.go @@ -60,6 +60,7 @@ func main() { DB.CActionLog = DB.DB.C("ActionLog") DB.CInvestigation = DB.DB.C("Investigation") DB.CTrajectory = DB.DB.C("Trajectory") + DB.CIcons = DB.DB.C("Icons") DelayMessage.CDelayMessage = DB.DB.C("DelayMessage") DelayMessage.CDelayErrorLog = DB.DB.C("DelayErrorLog") @@ -98,6 +99,9 @@ func main() { r.POST("/DealyMessage/Create", Api.CreateDealyMessage) r.GET("/DealyMessage/Info", Api.DealyMessageInfo) r.POST("/DealyMessage/Remove", Api.RemoveDealyMessage) + r.POST("/Icon/Update", Api.UpdateIcon) + r.GET("/Icon/All", Api.AllIcons) + r.GET("/Icon/Info", Api.IconInfo) //r.GET("/ws", Api.WsPage) r.Static("/Upload", "./Upload") -- libgit2 0.21.0