Commit 5264054d176ce561968aa59b242e27e7f1450581

Authored by aarongao
1 parent 5ce75bb4
Exists in v1.2 and in 2 other branches master, v1.1

..

API/User.go
... ... @@ -21,6 +21,13 @@ var Regular = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|1
21 21 // @Produce json
22 22 // @Param Mobile aaron string true "手机号"
23 23 // @Param Code 1 string true "验证码(使用验证码的新手机号自动注册)"
  24 +// @Param DeviceId abc123 string false "手机唯一识别码,不重复(存放于http.header中)"
  25 +// @Param Mac abc123 string false "网卡Mac地址(存放于http.header中)"
  26 +// @Param SystemType ios string false "ios,android(存放于http.header中)"
  27 +// @Param SystemVersion 13.01 string false "手机版本(存放于http.header中)"
  28 +// @Param SystemModel iphone8 string false "手机型号(存放于http.header中)"
  29 +// @Param AppVersion 1.0 string false "app版本号(存放于http.header中)"
  30 +// @Param DeviceToken abc string false "推送token(存放于http.header中)"
24 31 // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":{"Id":"5e09c64c1c09c6f0f7ca2fa9","Token":"640bf934e425aba5d3c90998b2641f2f0ca07261d334d9615d1cd4790b5f34e7"}} 调用其它需要登陆的接口时携带token,有过期时间"
25 32 // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
26 33 // @Router /LoginUser? [post]
... ... @@ -70,6 +77,17 @@ func LoginUser(c *gin.Context) {
70 77 "",
71 78 "",
72 79 "",
  80 + DB.SDevice{
  81 + c.Request.Header.Get("DeviceId"),
  82 + c.Request.Host,
  83 + c.Request.Header.Get("Mac"),
  84 + c.Request.Header.Get("UDID"),
  85 + c.Request.Header.Get("SystemVersion"),
  86 + c.Request.Header.Get("SystemModel"),
  87 + c.Request.Header.Get("AppVersion"),
  88 + c.Request.Header.Get("AppVersion"),
  89 + c.Request.Header.Get("DeviceToken"),
  90 + },
73 91 }
74 92 DB.CMember.Insert(User)
75 93 }
... ... @@ -132,6 +150,7 @@ func UserInfo(c *gin.Context) {
132 150 var User DB.SMember
133 151 DB.CMember.Find(bson.M{"_id": bson.ObjectIdHex(c.Query("id"))}).One(&User)
134 152  
  153 + User.Device = DB.SDevice{}
135 154 c.JSON(200, tools.ResponseSeccess{
136 155 0,
137 156 User,
... ...
API/UserLog.go
... ... @@ -25,7 +25,8 @@ import (
25 25 // @Param SystemType ios string true "ios,android(存放于http.header中)"
26 26 // @Param SystemVersion 13.01 string true "手机版本(存放于http.header中)"
27 27 // @Param SystemModel iphone8 string true "手机型号(存放于http.header中)"
28   -// @Param AppVersion 1.0 string true "app版本号"
  28 +// @Param AppVersion 1.0 string true "app版本号(存放于http.header中)"
  29 +// @Param DeviceToken abc string true "推送token(存放于http.header中)"
29 30 // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}"
30 31 // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
31 32 // @Router /UserLog? [post]
... ... @@ -50,10 +51,12 @@ func UserLog(c *gin.Context) {
50 51 c.Request.Header.Get("DeviceId"),
51 52 c.Request.Host,
52 53 c.Request.Header.Get("Mac"),
53   - c.Request.Header.Get("SystemType"),
  54 + c.Request.Header.Get("UDID"),
54 55 c.Request.Header.Get("SystemVersion"),
55 56 c.Request.Header.Get("SystemModel"),
56 57 c.Request.Header.Get("AppVersion"),
  58 + c.Request.Header.Get("AppVersion"),
  59 + c.Request.Header.Get("DeviceToken"),
57 60 },
58 61 })
59 62  
... ...
DB/db.go
... ... @@ -71,11 +71,14 @@ type SDevice struct {
71 71 DeviceId string `bson:"DeviceId" json:"DeviceId"`
72 72 Ip string `bson:"Ip" json:"Ip"`
73 73 Mac string `bson:"Mac" json:"Mac"`
  74 + UDID string `bson:"UDID" json:"UDID"`
74 75 SystemType string `bson:"SystemType" json:"SystemType"` //ios,android
75 76 SystemVersion string `bson:"SystemVersion" json:"SystemVersion"` //系统版本
76 77 SystemModel string `bson:"SystemModel" json:"SystemModel"` //机型
77 78 AppVersion string `bson:"AppVersion" json:"AppVersion"` //app版本
  79 + DeviceToken string `bson:"DeviceToken" json:"DeviceToken"` //用于推送的token
78 80 }
  81 +
79 82 type SUserLog struct {
80 83 Type string `bson:"Type" json:"Type"` // Log(事件)类型
81 84 SubType string `bson:"SubType" json:"SubType"` // 分类
... ... @@ -145,6 +148,7 @@ type SMember struct {
145 148 Openid string `bson:"Openid" json:"Openid"`
146 149 Token string `bson:"Token" json:"Token"`
147 150 Sex string `bson:"Sex" json:"Sex"`
  151 + Device SDevice `bson:"Device" json:"Device"` //设备信息
148 152 }
149 153  
150 154 type STag struct {
... ...
Lib/DelayMessage/delaymessage.go
... ... @@ -3,6 +3,7 @@ package DelayMessage
3 3 import (
4 4 "encoding/json"
5 5 "fmt"
  6 + "github.com/aliyun/alibaba-cloud-sdk-go/services/push"
6 7 "github.com/pkg/errors"
7 8 "gopkg.in/mgo.v2"
8 9 "gopkg.in/mgo.v2/bson"
... ... @@ -141,6 +142,17 @@ func Callback(key *bson.ObjectId, message *Message) {
141 142  
142 143 } else if message.Type == 1 {
143 144  
  145 + // 推送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)
144 156 }
145 157  
146 158 json, _ := json.Marshal(message)
... ...
README.md
... ... @@ -447,6 +447,13 @@
447 447 |-----|-----|-----|-----|-----|
448 448 | Mobile | aaron | string | 手机号 | Yes |
449 449 | Code | 1 | string | 验证码(使用验证码的新手机号自动注册) | Yes |
  450 +| DeviceId | abc123 | string | 手机唯一识别码,不重复(存放于http.header中) | |
  451 +| Mac | abc123 | string | 网卡Mac地址(存放于http.header中) | |
  452 +| SystemType | ios | string | ios,android(存放于http.header中) | |
  453 +| SystemVersion | 13.01 | string | 手机版本(存放于http.header中) | |
  454 +| SystemModel | iphone8 | string | 手机型号(存放于http.header中) | |
  455 +| AppVersion | 1.0 | string | app版本号(存放于http.header中) | |
  456 +| DeviceToken | abc | string | 推送token(存放于http.header中) | |
450 457  
451 458  
452 459 | Code | Type | Model | Message |
... ... @@ -750,7 +757,8 @@
750 757 | SystemType | ios | string | ios,android(存放于http.header中) | Yes |
751 758 | SystemVersion | 13.01 | string | 手机版本(存放于http.header中) | Yes |
752 759 | SystemModel | iphone8 | string | 手机型号(存放于http.header中) | Yes |
753   -| AppVersion | 1.0 | string | app版本号 | Yes |
  760 +| AppVersion | 1.0 | string | app版本号(存放于http.header中) | Yes |
  761 +| DeviceToken | abc | string | 推送token(存放于http.header中) | Yes |
754 762  
755 763  
756 764 | Code | Type | Model | Message |
... ...