Commit 76d39dbf741dd8c89ec33529e0feb22a9fa97e4b

Authored by aarongao
1 parent 5264054d
Exists in v1.2 and in 2 other branches master, v1.1

.

Showing 4 changed files with 90 additions and 22 deletions   Show diff stats
API/User.go
... ... @@ -117,6 +117,52 @@ func LoginUser(c *gin.Context) {
117 117  
118 118 }
119 119  
  120 +// @Title 注册客户端
  121 +// @Description 用户管理 - 注册客户端
  122 +// @Accept json
  123 +// @Produce json
  124 +// @Param DeviceId abc123 string false "手机唯一识别码,不重复(存放于http.header中)"
  125 +// @Param Mac abc123 string false "网卡Mac地址(存放于http.header中)"
  126 +// @Param SystemType ios string false "ios,android(存放于http.header中)"
  127 +// @Param SystemVersion 13.01 string false "手机版本(存放于http.header中)"
  128 +// @Param SystemModel iphone8 string false "手机型号(存放于http.header中)"
  129 +// @Param AppVersion 1.0 string false "app版本号(存放于http.header中)"
  130 +// @Param DeviceToken abc string false "推送token(存放于http.header中)"
  131 +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":{"Id":"5e09c64c1c09c6f0f7ca2fa9","Token":"640bf934e425aba5d3c90998b2641f2f0ca07261d334d9615d1cd4790b5f34e7"}} 调用其它需要登陆的接口时携带token,有过期时间"
  132 +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
  133 +// @Router /RegisterDevice? [post]
  134 +func RegisterDevice(c *gin.Context) {
  135 + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
  136 + c.Header("Access-Control-Allow-Credentials", "true")
  137 +
  138 + selected := bson.M{}
  139 + var SDevice *DB.SDevice
  140 + selected["DeviceId"] = c.Request.Header.Get("DeviceId")
  141 + DB.CDevice.Find(selected).One(&SDevice)
  142 +
  143 + if SDevice == nil {
  144 + Device := DB.SDevice{
  145 + c.Request.Header.Get("DeviceId"),
  146 + c.Request.Host,
  147 + c.Request.Header.Get("Mac"),
  148 + c.Request.Header.Get("UDID"),
  149 + c.Request.Header.Get("SystemVersion"),
  150 + c.Request.Header.Get("SystemModel"),
  151 + c.Request.Header.Get("AppVersion"),
  152 + c.Request.Header.Get("AppVersion"),
  153 + c.Request.Header.Get("DeviceToken"),
  154 + }
  155 +
  156 + DB.CDevice.Insert(Device)
  157 + }
  158 +
  159 + c.JSON(200, tools.ResponseSeccess{
  160 + 0,
  161 + "ok",
  162 + })
  163 +
  164 +}
  165 +
120 166 // @Title 用户信息
121 167 // @Description 用户管理 - 获取用户信息
122 168 // @Accept json
... ... @@ -130,8 +176,7 @@ func UserInfo(c *gin.Context) {
130 176 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
131 177 c.Header("Access-Control-Allow-Credentials", "true")
132 178  
133   -
134   - if c.Query("Token") == "" || bson.IsObjectIdHex(c.Query("id")) == false{
  179 + if c.Query("Token") == "" || bson.IsObjectIdHex(c.Query("id")) == false {
135 180 c.JSON(200, tools.ResponseError{
136 181 1,
137 182 "Token或者用户id不正确",
... ... @@ -139,7 +184,7 @@ func UserInfo(c *gin.Context) {
139 184 return
140 185 }
141 186  
142   - if Token.GetToken(c.Query("id")) != c.Query("Token"){
  187 + if Token.GetToken(c.Query("id")) != c.Query("Token") {
143 188 c.JSON(200, tools.ResponseError{
144 189 401,
145 190 "token过期",
... ... @@ -158,8 +203,6 @@ func UserInfo(c *gin.Context) {
158 203  
159 204 }
160 205  
161   -
162   -
163 206 // @Title 用户信息
164 207 // @Description 用户管理 - 检查Token是否过期
165 208 // @Accept json
... ... @@ -173,8 +216,7 @@ func CheckToken(c *gin.Context) {
173 216 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
174 217 c.Header("Access-Control-Allow-Credentials", "true")
175 218  
176   -
177   - if c.PostForm("Token") == "" || bson.IsObjectIdHex(c.PostForm("id")) == false{
  219 + if c.PostForm("Token") == "" || bson.IsObjectIdHex(c.PostForm("id")) == false {
178 220 c.JSON(200, tools.ResponseError{
179 221 1,
180 222 "Token或者用户id不正确",
... ... @@ -182,7 +224,7 @@ func CheckToken(c *gin.Context) {
182 224 return
183 225 }
184 226  
185   - if Token.GetToken(c.PostForm("id")) != c.PostForm("Token"){
  227 + if Token.GetToken(c.PostForm("id")) != c.PostForm("Token") {
186 228 c.JSON(200, tools.ResponseError{
187 229 401,
188 230 "token过期",
... ... @@ -190,7 +232,6 @@ func CheckToken(c *gin.Context) {
190 232 return
191 233 }
192 234  
193   -
194 235 c.JSON(200, tools.ResponseSeccess{
195 236 0,
196 237 "ok",
... ... @@ -217,8 +258,7 @@ func UpdateUser(c *gin.Context) {
217 258 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
218 259 c.Header("Access-Control-Allow-Credentials", "true")
219 260  
220   -
221   - if c.PostForm("Token") == "" || bson.IsObjectIdHex(c.PostForm("id")) == false{
  261 + if c.PostForm("Token") == "" || bson.IsObjectIdHex(c.PostForm("id")) == false {
222 262 c.JSON(200, tools.ResponseError{
223 263 1,
224 264 "Token或者用户id不正确",
... ... @@ -226,7 +266,7 @@ func UpdateUser(c *gin.Context) {
226 266 return
227 267 }
228 268  
229   - if Token.GetToken(c.PostForm("id")) != c.PostForm("Token"){
  269 + if Token.GetToken(c.PostForm("id")) != c.PostForm("Token") {
230 270 c.JSON(200, tools.ResponseError{
231 271 401,
232 272 "token过期",
... ... @@ -234,7 +274,6 @@ func UpdateUser(c *gin.Context) {
234 274 return
235 275 }
236 276  
237   -
238 277 reg := regexp.MustCompile(Regular)
239 278 if !reg.MatchString(c.PostForm("Mobile")) {
240 279  
... ...
DB/db.go
... ... @@ -22,6 +22,7 @@ var CSystemLog *mgo.Collection //操作记录
22 22 var CTrajectory *mgo.Collection //移动轨迹
23 23 var CIcons *mgo.Collection //图标信息
24 24 var CTopMenus *mgo.Collection //菜单
  25 +var CDevice *mgo.Collection //设备清单
25 26 var DB *mgo.Database
26 27  
27 28 type SItem struct {
... ... @@ -68,15 +69,15 @@ type STopMenus struct {
68 69 }
69 70  
70 71 type SDevice struct {
71   - DeviceId string `bson:"DeviceId" json:"DeviceId"`
72   - Ip string `bson:"Ip" json:"Ip"`
73   - Mac string `bson:"Mac" json:"Mac"`
74   - UDID string `bson:"UDID" json:"UDID"`
75   - SystemType string `bson:"SystemType" json:"SystemType"` //ios,android
76   - SystemVersion string `bson:"SystemVersion" json:"SystemVersion"` //系统版本
77   - SystemModel string `bson:"SystemModel" json:"SystemModel"` //机型
78   - AppVersion string `bson:"AppVersion" json:"AppVersion"` //app版本
79   - DeviceToken string `bson:"DeviceToken" json:"DeviceToken"` //用于推送的token
  72 + DeviceId string `bson:"DeviceId" json:"DeviceId"`
  73 + Ip string `bson:"Ip" json:"Ip"`
  74 + Mac string `bson:"Mac" json:"Mac"`
  75 + UDID string `bson:"UDID" json:"UDID"`
  76 + SystemType string `bson:"SystemType" json:"SystemType"` //ios,android
  77 + SystemVersion string `bson:"SystemVersion" json:"SystemVersion"` //系统版本
  78 + SystemModel string `bson:"SystemModel" json:"SystemModel"` //机型
  79 + AppVersion string `bson:"AppVersion" json:"AppVersion"` //app版本
  80 + DeviceToken string `bson:"DeviceToken" json:"DeviceToken"` //用于推送的token
80 81 }
81 82  
82 83 type SUserLog struct {
... ...
README.md
... ... @@ -30,6 +30,7 @@
30 30 1. [设备管理 - 查询设备信息](#iteminfo-get)
31 31 1. [查询线路信息](#lineinfo-get)
32 32 1. [用户管理 - 用户登录&注册](#loginuser-post)
  33 +1. [用户管理 - 注册客户端](#registerdevice-post)
33 34 1. [返回景区基础信息](#scenicinfo-get)
34 35 1. [发送短信验证码](#sms-send-post)
35 36 1. [标签 - 增加标签](#tag-create-post)
... ... @@ -463,6 +464,31 @@
463 464  
464 465  
465 466  
  467 +<a name="registerdevice-post"></a>
  468 +
  469 +#### /RegisterDevice (POST)
  470 +
  471 +
  472 +用户管理 - 注册客户端
  473 +
  474 +| Param Name | Example | Data Type | Description | Required? |
  475 +|-----|-----|-----|-----|-----|
  476 +| DeviceId | abc123 | string | 手机唯一识别码,不重复(存放于http.header中) | |
  477 +| Mac | abc123 | string | 网卡Mac地址(存放于http.header中) | |
  478 +| SystemType | ios | string | ios,android(存放于http.header中) | |
  479 +| SystemVersion | 13.01 | string | 手机版本(存放于http.header中) | |
  480 +| SystemModel | iphone8 | string | 手机型号(存放于http.header中) | |
  481 +| AppVersion | 1.0 | string | app版本号(存放于http.header中) | |
  482 +| DeviceToken | abc | string | 推送token(存放于http.header中) | |
  483 +
  484 +
  485 +| Code | Type | Model | Message |
  486 +|-----|-----|-----|-----|
  487 +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | {"errcode":0,"result":{"Id":"5e09c64c1c09c6f0f7ca2fa9","Token":"640bf934e425aba5d3c90998b2641f2f0ca07261d334d9615d1cd4790b5f34e7"}} 调用其它需要登陆的接口时携带token,有过期时间 |
  488 +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} |
  489 +
  490 +
  491 +
466 492 <a name="scenicinfo-get"></a>
467 493  
468 494 #### /ScenicInfo (GET)
... ...
main.go
... ... @@ -65,6 +65,7 @@ func main() {
65 65 DB.CTrajectory = DB.DB.C("Trajectory")
66 66 DB.CIcons = DB.DB.C("Icons")
67 67 DB.CTopMenus = DB.DB.C("TopMenus")
  68 + DB.CDevice = DB.DB.C("Device")
68 69 DelayMessage.CDelayMessage = DB.DB.C("DelayMessage")
69 70 DelayMessage.CDelayErrorLog = DB.DB.C("DelayErrorLog")
70 71  
... ... @@ -116,6 +117,7 @@ func main() {
116 117 r.GET("/Tiles", Api.Tiles)
117 118 r.POST("/TopMenus/Update", Api.UpdateTopMenus)
118 119 r.GET("/TopMenus/All", Api.AllTopMenus)
  120 + r.POST("/RegisterDevice", Api.RegisterDevice)
119 121 //r.GET("/ws", Api.WsPage)
120 122  
121 123 r.Static("/Upload", "./Upload")
... ...