DealyMessage.go
4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package Api
import (
"github.com/aarongao/tools"
"github.com/gin-gonic/gin"
"gopkg.in/mgo.v2/bson"
"letu/Lib/DelayMessage"
"letu/Lib/Token"
)
// @Title 查询用户的定时提醒
// @Description 查询用户的定时提醒
// @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]
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,
"Token或者用户id不正确",
})
return
}
if Token.GetToken(c.Query("UserId")) != c.Query("Token") {
c.JSON(200, tools.ResponseError{
401,
"token过期",
})
return
}
var aDelayMessage []DelayMessage.Message
DelayMessage.CDelayMessage.Find(bson.M{"UserId": c.Query("UserId")}).All(&aDelayMessage)
if aDelayMessage == nil {
aDelayMessage = []DelayMessage.Message{}
}
c.JSON(200, tools.ResponseSeccess{
0,
aDelayMessage,
})
}
// @Title 创建提醒
// @Description 创建提醒
// @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 "内容"
// @Param DelayTime 1579066863 string true "到达这个时间戳就执行"
// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /DealyMessage/Create? [post]
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,
"Token或者用户id不正确",
})
return
}
if Token.GetToken(c.PostForm("UserId")) != c.PostForm("Token") {
c.JSON(200, tools.ResponseError{
401,
"token过期",
})
return
}
err := DelayMessage.GlobalDM.AddTaskForAppMessage(c.PostForm("DelayTime"), c.PostForm("UDID"), c.PostForm("Title"), c.PostForm("Content"), c.PostForm("UserId"))
if err == nil {
c.JSON(200, tools.ResponseSeccess{
0,
"ok",
})
} else {
c.JSON(200, tools.ResponseError{
1,
err.Error(),
})
}
}
// @Title 删除提醒
// @Description 删除提醒
// @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]
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,
"Token或者用户id不正确",
})
return
}
if Token.GetToken(c.PostForm("UserId")) != c.PostForm("Token") {
c.JSON(200, tools.ResponseError{
401,
"token过期",
})
return
}
DelayMessage.GlobalDM.DelTaskForId(c.PostForm("id"))
c.JSON(200, tools.ResponseSeccess{
0,
"ok",
})
}