forked from isdamir/jpush
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpushclient.go
executable file
·51 lines (41 loc) · 1.2 KB
/
pushclient.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
package jpush
import (
"encoding/base64"
"encoding/json"
//"fmt"
"github.com/aiwuTech/jpush/common"
)
const (
SUCCESS_FLAG = "msg_id"
HOST_NAME_SSL = "https://api.jpush.cn/v3/push"
BASE64_TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
)
var base64Coder = base64.NewEncoding(BASE64_TABLE)
type PushClient struct {
MasterSecret string
AppKey string
AuthCode string
BaseUrl string
}
func NewPushClient(secret, appKey string) *PushClient {
//base64
auth := "Basic " + base64Coder.EncodeToString([]byte(appKey+":"+secret))
pusher := &PushClient{secret, appKey, auth, HOST_NAME_SSL}
return pusher
}
func (this *PushClient) Send(builder interface{}) (*common.RetData, error) {
content, err := json.Marshal(builder)
//fmt.Println(string(content))
if err != nil {
return nil, err
}
return this.SendPushBytes(content)
}
func (this *PushClient) SendPushString(content string) (ret *common.RetData, err error) {
ret, err = common.SendPostString(this.BaseUrl, content, this.AuthCode)
return
}
func (this *PushClient) SendPushBytes(content []byte) (ret *common.RetData, err error) {
ret, err = common.SendPostBytes(this.BaseUrl, content, this.AuthCode)
return
}