Commit ee5ad688aa294e9a3f0d6d268a017c1bfe92208d
1 parent
a318bbae
Exists in
v1.2
and in
2 other branches
..
Showing
6 changed files
with
65 additions
and
45 deletions
Show diff stats
API/User.go
| @@ -79,7 +79,6 @@ func LoginUser(c *gin.Context) { | @@ -79,7 +79,6 @@ func LoginUser(c *gin.Context) { | ||
| 79 | "", | 79 | "", |
| 80 | DB.SDevice{ | 80 | DB.SDevice{ |
| 81 | c.Request.Header.Get("DeviceId"), | 81 | c.Request.Header.Get("DeviceId"), |
| 82 | - c.Request.Host, | ||
| 83 | c.Request.Header.Get("Mac"), | 82 | c.Request.Header.Get("Mac"), |
| 84 | c.Request.Header.Get("UDID"), | 83 | c.Request.Header.Get("UDID"), |
| 85 | c.Request.Header.Get("SystemVersion"), | 84 | c.Request.Header.Get("SystemVersion"), |
| @@ -135,27 +134,27 @@ func RegisterDevice(c *gin.Context) { | @@ -135,27 +134,27 @@ func RegisterDevice(c *gin.Context) { | ||
| 135 | c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | 134 | c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) |
| 136 | c.Header("Access-Control-Allow-Credentials", "true") | 135 | c.Header("Access-Control-Allow-Credentials", "true") |
| 137 | 136 | ||
| 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) | 137 | + if c.Request.Header.Get("DeviceId") == "" { |
| 138 | + c.JSON(200, tools.ResponseError{ | ||
| 139 | + 1, | ||
| 140 | + "DeviceId不正确", | ||
| 141 | + }) | ||
| 142 | + return | ||
| 157 | } | 143 | } |
| 158 | 144 | ||
| 145 | + DB.CDevice.Upsert( | ||
| 146 | + bson.M{"DeviceId":c.Request.Header.Get("DeviceId")}, | ||
| 147 | + bson.M{"$set": bson.M{ | ||
| 148 | + "Mac":c.Request.Header.Get("Mac"), | ||
| 149 | + "UDID":c.Request.Header.Get("UDID"), | ||
| 150 | + "SystemType":c.Request.Header.Get("SystemType"), | ||
| 151 | + "SystemVersion":c.Request.Header.Get("SystemVersion"), | ||
| 152 | + "SystemModel":c.Request.Header.Get("SystemModel"), | ||
| 153 | + "AppVersion":c.Request.Header.Get("AppVersion"), | ||
| 154 | + "DeviceToken":c.Request.Header.Get("DeviceToken"), | ||
| 155 | + }}, | ||
| 156 | + ) | ||
| 157 | + | ||
| 159 | c.JSON(200, tools.ResponseSeccess{ | 158 | c.JSON(200, tools.ResponseSeccess{ |
| 160 | 0, | 159 | 0, |
| 161 | "ok", | 160 | "ok", |
API/UserLog.go
| @@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
| 4 | "encoding/json" | 4 | "encoding/json" |
| 5 | "github.com/aarongao/tools" | 5 | "github.com/aarongao/tools" |
| 6 | "github.com/gin-gonic/gin" | 6 | "github.com/gin-gonic/gin" |
| 7 | + "gopkg.in/mgo.v2/bson" | ||
| 7 | "letu/DB" | 8 | "letu/DB" |
| 8 | "time" | 9 | "time" |
| 9 | ) | 10 | ) |
| @@ -34,6 +35,14 @@ func UserLog(c *gin.Context) { | @@ -34,6 +35,14 @@ func UserLog(c *gin.Context) { | ||
| 34 | c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | 35 | c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) |
| 35 | c.Header("Access-Control-Allow-Credentials", "true") | 36 | c.Header("Access-Control-Allow-Credentials", "true") |
| 36 | 37 | ||
| 38 | + if c.Request.Header.Get("DeviceId") == "" { | ||
| 39 | + c.JSON(200, tools.ResponseError{ | ||
| 40 | + 1, | ||
| 41 | + "DeviceId不正确", | ||
| 42 | + }) | ||
| 43 | + return | ||
| 44 | + } | ||
| 45 | + | ||
| 37 | var Location DB.SLocation | 46 | var Location DB.SLocation |
| 38 | json.Unmarshal([]byte(c.PostForm("Location")), &Location) | 47 | json.Unmarshal([]byte(c.PostForm("Location")), &Location) |
| 39 | 48 | ||
| @@ -46,10 +55,10 @@ func UserLog(c *gin.Context) { | @@ -46,10 +55,10 @@ func UserLog(c *gin.Context) { | ||
| 46 | time.Now().Unix(), | 55 | time.Now().Unix(), |
| 47 | Location, | 56 | Location, |
| 48 | c.PostForm("Remarks"), | 57 | c.PostForm("Remarks"), |
| 58 | + c.Request.Host, | ||
| 49 | c.PostForm("Source"), | 59 | c.PostForm("Source"), |
| 50 | DB.SDevice{ | 60 | DB.SDevice{ |
| 51 | c.Request.Header.Get("DeviceId"), | 61 | c.Request.Header.Get("DeviceId"), |
| 52 | - c.Request.Host, | ||
| 53 | c.Request.Header.Get("Mac"), | 62 | c.Request.Header.Get("Mac"), |
| 54 | c.Request.Header.Get("UDID"), | 63 | c.Request.Header.Get("UDID"), |
| 55 | c.Request.Header.Get("SystemVersion"), | 64 | c.Request.Header.Get("SystemVersion"), |
| @@ -60,6 +69,19 @@ func UserLog(c *gin.Context) { | @@ -60,6 +69,19 @@ func UserLog(c *gin.Context) { | ||
| 60 | }, | 69 | }, |
| 61 | }) | 70 | }) |
| 62 | 71 | ||
| 72 | + DB.CDevice.Upsert( | ||
| 73 | + bson.M{"DeviceId": c.Request.Header.Get("DeviceId")}, | ||
| 74 | + bson.M{"$set": bson.M{ | ||
| 75 | + "Mac": c.Request.Header.Get("Mac"), | ||
| 76 | + "UDID": c.Request.Header.Get("UDID"), | ||
| 77 | + "SystemType": c.Request.Header.Get("SystemType"), | ||
| 78 | + "SystemVersion": c.Request.Header.Get("SystemVersion"), | ||
| 79 | + "SystemModel": c.Request.Header.Get("SystemModel"), | ||
| 80 | + "AppVersion": c.Request.Header.Get("AppVersion"), | ||
| 81 | + "DeviceToken": c.Request.Header.Get("DeviceToken"), | ||
| 82 | + }}, | ||
| 83 | + ) | ||
| 84 | + | ||
| 63 | c.JSON(200, tools.ResponseSeccess{ | 85 | c.JSON(200, tools.ResponseSeccess{ |
| 64 | 0, | 86 | 0, |
| 65 | "ok", | 87 | "ok", |
DB/db.go
| @@ -69,15 +69,14 @@ type STopMenus struct { | @@ -69,15 +69,14 @@ type STopMenus struct { | ||
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | type SDevice struct { | 71 | type SDevice struct { |
| 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 | 72 | + DeviceId string `bson:"DeviceId" json:"DeviceId"` |
| 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 | ||
| 81 | } | 80 | } |
| 82 | 81 | ||
| 83 | type SUserLog struct { | 82 | type SUserLog struct { |
| @@ -89,8 +88,9 @@ type SUserLog struct { | @@ -89,8 +88,9 @@ type SUserLog struct { | ||
| 89 | DateTime int64 `bson:"DateTime" json:"DateTime"` //时间戳 | 88 | DateTime int64 `bson:"DateTime" json:"DateTime"` //时间戳 |
| 90 | Location SLocation `bson:"Location" json:"Location"` //位置 | 89 | Location SLocation `bson:"Location" json:"Location"` //位置 |
| 91 | Remarks string `bson:"Remarks" json:"Remarks"` //备注 | 90 | Remarks string `bson:"Remarks" json:"Remarks"` //备注 |
| 92 | - Source string `bson:"Source" json:"Source"` //来源 | ||
| 93 | - Device SDevice `bson:"Device" json:"Device"` //设备信息 | 91 | + Ip string `bson:"Ip" json:"Ip"` |
| 92 | + Source string `bson:"Source" json:"Source"` //来源 | ||
| 93 | + Device SDevice `bson:"Device" json:"Device"` //设备信息 | ||
| 94 | } | 94 | } |
| 95 | type SSystemLog struct { | 95 | type SSystemLog struct { |
| 96 | UserId string `bson:"UserId" json:"UserId"` // 用户ID | 96 | UserId string `bson:"UserId" json:"UserId"` // 用户ID |
Lib/DelayMessage/delaymessage.go
| @@ -3,7 +3,6 @@ package DelayMessage | @@ -3,7 +3,6 @@ package DelayMessage | ||
| 3 | import ( | 3 | import ( |
| 4 | "encoding/json" | 4 | "encoding/json" |
| 5 | "fmt" | 5 | "fmt" |
| 6 | - "github.com/aliyun/alibaba-cloud-sdk-go/services/push" | ||
| 7 | "github.com/pkg/errors" | 6 | "github.com/pkg/errors" |
| 8 | "gopkg.in/mgo.v2" | 7 | "gopkg.in/mgo.v2" |
| 9 | "gopkg.in/mgo.v2/bson" | 8 | "gopkg.in/mgo.v2/bson" |
| @@ -143,16 +142,16 @@ func Callback(key *bson.ObjectId, message *Message) { | @@ -143,16 +142,16 @@ func Callback(key *bson.ObjectId, message *Message) { | ||
| 143 | } else if message.Type == 1 { | 142 | } else if message.Type == 1 { |
| 144 | 143 | ||
| 145 | // 推送app消息 | 144 | // 推送app消息 |
| 146 | - client, err := push.NewClientWithAccessKey("cn-hangzhou", "28332889", "4c0b32d5fd0822a9de703e177798e8ca") | ||
| 147 | - | ||
| 148 | - request := push.CreatePushMessageToiOSRequest() | ||
| 149 | - request.Scheme = "https" | ||
| 150 | - | ||
| 151 | - response, err := client.PushMessageToiOS(request) | ||
| 152 | - if err != nil { | ||
| 153 | - fmt.Print(err.Error()) | ||
| 154 | - } | ||
| 155 | - fmt.Printf("response is %#v\n", response) | 145 | + //client, err := push.NewClientWithAccessKey("cn-hangzhou", "28332889", "4c0b32d5fd0822a9de703e177798e8ca") |
| 146 | + // | ||
| 147 | + //request := push.CreatePushMessageToiOSRequest() | ||
| 148 | + //request.Scheme = "https" | ||
| 149 | + // | ||
| 150 | + //response, err := client.PushMessageToiOS(request) | ||
| 151 | + //if err != nil { | ||
| 152 | + // fmt.Print(err.Error()) | ||
| 153 | + //} | ||
| 154 | + //fmt.Printf("response is %#v\n", response) | ||
| 156 | } | 155 | } |
| 157 | 156 | ||
| 158 | json, _ := json.Marshal(message) | 157 | json, _ := json.Marshal(message) |
README.md
| @@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
| 3 | | Specification | Value | | 3 | | Specification | Value | |
| 4 | |-----|-----| | 4 | |-----|-----| |
| 5 | | API Version | 1.0.0 | | 5 | | API Version | 1.0.0 | |
| 6 | -| BasePath | https://letu.api.imagchina.com | | 6 | +| BasePath | 正式 leyoutu.st-i.com.cn | 测试 letu.api.imagchina.com | |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 |
main.go
| @@ -17,7 +17,7 @@ import ( | @@ -17,7 +17,7 @@ import ( | ||
| 17 | 17 | ||
| 18 | // @APIVersion 1.0.0 | 18 | // @APIVersion 1.0.0 |
| 19 | // @APITitle 乐游图后端接口文档 | 19 | // @APITitle 乐游图后端接口文档 |
| 20 | -// @BasePath https://letu.api.imagchina.com | 20 | +// @BasePath 正式 leyoutu.st-i.com.cn | 测试 letu.api.imagchina.com |
| 21 | func main() { | 21 | func main() { |
| 22 | 22 | ||
| 23 | // 读取配置文件 | 23 | // 读取配置文件 |