-
Notifications
You must be signed in to change notification settings - Fork 0
/
tagupdate.go
68 lines (58 loc) · 1.95 KB
/
tagupdate.go
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
/**
* Created by GoLand.
* User: 姜伟
* Date: 2020/2/4 0004
* Time: 12:19
*/
package device
import (
"regexp"
"github.com/a07061625/gompf/mpf"
"github.com/a07061625/gompf/mpf/api/mppush"
"github.com/a07061625/gompf/mpf/mpconstant/errorcode"
"github.com/a07061625/gompf/mpf/mpconstant/project"
"github.com/a07061625/gompf/mpf/mperr"
"github.com/valyala/fasthttp"
)
// 更新标签
type tagUpdate struct {
mppush.BaseJPush
tag string // 标签名
registrationList map[string]interface{} // 设备列表
}
func (tu *tagUpdate) SetTag(tag string) {
match, _ := regexp.MatchString(project.RegexDigitAlpha, tag)
if match {
tu.tag = tag
} else {
panic(mperr.NewPushJPush(errorcode.PushJPushParam, "标签名不合法", nil))
}
}
func (tu *tagUpdate) SetRegistrationList(registrationList map[string]interface{}) {
if len(registrationList) > 0 {
tu.registrationList = registrationList
} else {
panic(mperr.NewPushJPush(errorcode.PushJPushParam, "设备列表不能为空", nil))
}
}
func (tu *tagUpdate) CheckData() (*fasthttp.Client, *fasthttp.Request) {
if len(tu.tag) == 0 {
panic(mperr.NewPushJPush(errorcode.PushJPushParam, "标签名不能为空", nil))
}
if len(tu.registrationList) == 0 {
panic(mperr.NewPushJPush(errorcode.PushJPushParam, "设备列表不能为空", nil))
}
tu.ServiceUri = "/v3/tags/" + tu.tag
tu.ExtendData["registration_ids"] = tu.registrationList
tu.ReqURI = tu.GetServiceUrl()
reqBody := mpf.JSONMarshal(tu.ExtendData)
client, req := tu.GetRequest()
req.SetBody([]byte(reqBody))
return client, req
}
func NewTagUpdate(key string) *tagUpdate {
tu := &tagUpdate{mppush.NewBaseJPush(mppush.JPushServiceDomainDevice, key, "app"), "", make(map[string]interface{})}
tu.ReqContentType = project.HTTPContentTypeJSON
tu.ReqMethod = fasthttp.MethodPost
return tu
}