diff --git a/API/User.go b/API/User.go
index 3b72c11..5be1ae0 100644
--- a/API/User.go
+++ b/API/User.go
@@ -117,6 +117,52 @@ func LoginUser(c *gin.Context) {
}
+// @Title 注册客户端
+// @Description 用户管理 - 注册客户端
+// @Accept json
+// @Produce json
+// @Param DeviceId abc123 string false "手机唯一识别码,不重复(存放于http.header中)"
+// @Param Mac abc123 string false "网卡Mac地址(存放于http.header中)"
+// @Param SystemType ios string false "ios,android(存放于http.header中)"
+// @Param SystemVersion 13.01 string false "手机版本(存放于http.header中)"
+// @Param SystemModel iphone8 string false "手机型号(存放于http.header中)"
+// @Param AppVersion 1.0 string false "app版本号(存放于http.header中)"
+// @Param DeviceToken abc string false "推送token(存放于http.header中)"
+// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":{"Id":"5e09c64c1c09c6f0f7ca2fa9","Token":"640bf934e425aba5d3c90998b2641f2f0ca07261d334d9615d1cd4790b5f34e7"}} 调用其它需要登陆的接口时携带token,有过期时间"
+// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
+// @Router /RegisterDevice? [post]
+func RegisterDevice(c *gin.Context) {
+ c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
+ c.Header("Access-Control-Allow-Credentials", "true")
+
+ selected := bson.M{}
+ var SDevice *DB.SDevice
+ selected["DeviceId"] = c.Request.Header.Get("DeviceId")
+ DB.CDevice.Find(selected).One(&SDevice)
+
+ if SDevice == nil {
+ Device := DB.SDevice{
+ c.Request.Header.Get("DeviceId"),
+ c.Request.Host,
+ c.Request.Header.Get("Mac"),
+ c.Request.Header.Get("UDID"),
+ c.Request.Header.Get("SystemVersion"),
+ c.Request.Header.Get("SystemModel"),
+ c.Request.Header.Get("AppVersion"),
+ c.Request.Header.Get("AppVersion"),
+ c.Request.Header.Get("DeviceToken"),
+ }
+
+ DB.CDevice.Insert(Device)
+ }
+
+ c.JSON(200, tools.ResponseSeccess{
+ 0,
+ "ok",
+ })
+
+}
+
// @Title 用户信息
// @Description 用户管理 - 获取用户信息
// @Accept json
@@ -130,8 +176,7 @@ 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("Token") == "" || bson.IsObjectIdHex(c.Query("id")) == false{
+ if c.Query("Token") == "" || bson.IsObjectIdHex(c.Query("id")) == false {
c.JSON(200, tools.ResponseError{
1,
"Token或者用户id不正确",
@@ -139,7 +184,7 @@ func UserInfo(c *gin.Context) {
return
}
- if Token.GetToken(c.Query("id")) != c.Query("Token"){
+ if Token.GetToken(c.Query("id")) != c.Query("Token") {
c.JSON(200, tools.ResponseError{
401,
"token过期",
@@ -158,8 +203,6 @@ func UserInfo(c *gin.Context) {
}
-
-
// @Title 用户信息
// @Description 用户管理 - 检查Token是否过期
// @Accept json
@@ -173,8 +216,7 @@ func CheckToken(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{
+ if c.PostForm("Token") == "" || bson.IsObjectIdHex(c.PostForm("id")) == false {
c.JSON(200, tools.ResponseError{
1,
"Token或者用户id不正确",
@@ -182,7 +224,7 @@ func CheckToken(c *gin.Context) {
return
}
- if Token.GetToken(c.PostForm("id")) != c.PostForm("Token"){
+ if Token.GetToken(c.PostForm("id")) != c.PostForm("Token") {
c.JSON(200, tools.ResponseError{
401,
"token过期",
@@ -190,7 +232,6 @@ func CheckToken(c *gin.Context) {
return
}
-
c.JSON(200, tools.ResponseSeccess{
0,
"ok",
@@ -217,8 +258,7 @@ 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{
+ if c.PostForm("Token") == "" || bson.IsObjectIdHex(c.PostForm("id")) == false {
c.JSON(200, tools.ResponseError{
1,
"Token或者用户id不正确",
@@ -226,7 +266,7 @@ func UpdateUser(c *gin.Context) {
return
}
- if Token.GetToken(c.PostForm("id")) != c.PostForm("Token"){
+ if Token.GetToken(c.PostForm("id")) != c.PostForm("Token") {
c.JSON(200, tools.ResponseError{
401,
"token过期",
@@ -234,7 +274,6 @@ func UpdateUser(c *gin.Context) {
return
}
-
reg := regexp.MustCompile(Regular)
if !reg.MatchString(c.PostForm("Mobile")) {
diff --git a/DB/db.go b/DB/db.go
index 7696142..333bc2c 100644
--- a/DB/db.go
+++ b/DB/db.go
@@ -22,6 +22,7 @@ var CSystemLog *mgo.Collection //操作记录
var CTrajectory *mgo.Collection //移动轨迹
var CIcons *mgo.Collection //图标信息
var CTopMenus *mgo.Collection //菜单
+var CDevice *mgo.Collection //设备清单
var DB *mgo.Database
type SItem struct {
@@ -68,15 +69,15 @@ type STopMenus struct {
}
type SDevice struct {
- DeviceId string `bson:"DeviceId" json:"DeviceId"`
- Ip string `bson:"Ip" json:"Ip"`
- Mac string `bson:"Mac" json:"Mac"`
- UDID string `bson:"UDID" json:"UDID"`
- SystemType string `bson:"SystemType" json:"SystemType"` //ios,android
- SystemVersion string `bson:"SystemVersion" json:"SystemVersion"` //系统版本
- SystemModel string `bson:"SystemModel" json:"SystemModel"` //机型
- AppVersion string `bson:"AppVersion" json:"AppVersion"` //app版本
- DeviceToken string `bson:"DeviceToken" json:"DeviceToken"` //用于推送的token
+ DeviceId string `bson:"DeviceId" json:"DeviceId"`
+ Ip string `bson:"Ip" json:"Ip"`
+ Mac string `bson:"Mac" json:"Mac"`
+ UDID string `bson:"UDID" json:"UDID"`
+ SystemType string `bson:"SystemType" json:"SystemType"` //ios,android
+ SystemVersion string `bson:"SystemVersion" json:"SystemVersion"` //系统版本
+ SystemModel string `bson:"SystemModel" json:"SystemModel"` //机型
+ AppVersion string `bson:"AppVersion" json:"AppVersion"` //app版本
+ DeviceToken string `bson:"DeviceToken" json:"DeviceToken"` //用于推送的token
}
type SUserLog struct {
diff --git a/README.md b/README.md
index b496d81..05b4823 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,7 @@
1. [设备管理 - 查询设备信息](#iteminfo-get)
1. [查询线路信息](#lineinfo-get)
1. [用户管理 - 用户登录&注册](#loginuser-post)
+1. [用户管理 - 注册客户端](#registerdevice-post)
1. [返回景区基础信息](#scenicinfo-get)
1. [发送短信验证码](#sms-send-post)
1. [标签 - 增加标签](#tag-create-post)
@@ -463,6 +464,31 @@
+
+
+#### /RegisterDevice (POST)
+
+
+用户管理 - 注册客户端
+
+| Param Name | Example | Data Type | Description | Required? |
+|-----|-----|-----|-----|-----|
+| DeviceId | abc123 | string | 手机唯一识别码,不重复(存放于http.header中) | |
+| Mac | abc123 | string | 网卡Mac地址(存放于http.header中) | |
+| SystemType | ios | string | ios,android(存放于http.header中) | |
+| SystemVersion | 13.01 | string | 手机版本(存放于http.header中) | |
+| SystemModel | iphone8 | string | 手机型号(存放于http.header中) | |
+| AppVersion | 1.0 | string | app版本号(存放于http.header中) | |
+| DeviceToken | abc | string | 推送token(存放于http.header中) | |
+
+
+| Code | Type | Model | Message |
+|-----|-----|-----|-----|
+| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | {"errcode":0,"result":{"Id":"5e09c64c1c09c6f0f7ca2fa9","Token":"640bf934e425aba5d3c90998b2641f2f0ca07261d334d9615d1cd4790b5f34e7"}} 调用其它需要登陆的接口时携带token,有过期时间 |
+| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} |
+
+
+
#### /ScenicInfo (GET)
diff --git a/main.go b/main.go
index 93a2bf0..251f92a 100644
--- a/main.go
+++ b/main.go
@@ -65,6 +65,7 @@ func main() {
DB.CTrajectory = DB.DB.C("Trajectory")
DB.CIcons = DB.DB.C("Icons")
DB.CTopMenus = DB.DB.C("TopMenus")
+ DB.CDevice = DB.DB.C("Device")
DelayMessage.CDelayMessage = DB.DB.C("DelayMessage")
DelayMessage.CDelayErrorLog = DB.DB.C("DelayErrorLog")
@@ -116,6 +117,7 @@ func main() {
r.GET("/Tiles", Api.Tiles)
r.POST("/TopMenus/Update", Api.UpdateTopMenus)
r.GET("/TopMenus/All", Api.AllTopMenus)
+ r.POST("/RegisterDevice", Api.RegisterDevice)
//r.GET("/ws", Api.WsPage)
r.Static("/Upload", "./Upload")
--
libgit2 0.21.0