Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions deviceclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package jpushclient

import (
"io/ioutil"
"net/http"
)

const (
HOST_DEVICE = "https://device.jpush.cn"
)

type DeviceClient struct {
MasterSecret string
AppKey string
AuthCode string
BaseUrl string
}

func NewDeviceClient(secret, appKey string) *DeviceClient {
//base64
auth := "Basic " + base64Coder.EncodeToString([]byte(appKey+":"+secret))
devicer := &DeviceClient{secret, appKey, auth, HOST_DEVICE}
return devicer
}

func (this *DeviceClient) DeleteAlias(alias string) (string, error) {
path := "/v3/aliases/" + alias
url := this.BaseUrl + path
client := &http.Client{}
req, err := http.NewRequest("DELETE", url, nil)
req.Header.Add("Authorization", this.AuthCode)
req.Header.Add("Accept", CONTENT_TYPE_JSON)
resp, err := client.Do(req)

if resp != nil {
defer resp.Body.Close()
} else {
return "", nil
}
if err != nil {
return "", err
}

r, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
return string(r), nil
}
10 changes: 6 additions & 4 deletions notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ type Notice struct {
}

type AndroidNotice struct {
Alert string `json:"alert"`
Title string `json:"title,omitempty"`
BuilderId int `json:"builder_id,omitempty"`
Extras map[string]interface{} `json:"extras,omitempty"`
Alert string `json:"alert"`
Sound string `json:"sound,omitempty"`
Title string `json:"title,omitempty"`
UriActivity string `json:"uri_activity,omitempty"`
BuilderId int `json:"builder_id,omitempty"`
Extras map[string]interface{} `json:"extras,omitempty"`
}

type IOSNotice struct {
Expand Down
11 changes: 6 additions & 5 deletions option.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package jpushclient

type Option struct {
SendNo int `json:"sendno,omitempty"`
TimeLive int `json:"time_to_live,omitempty"`
ApnsProduction bool `json:"apns_production"`
OverrideMsgId int64 `json:"override_msg_id,omitempty"`
BigPushDuration int `json:"big_push_duration,omitempty"`
SendNo int `json:"sendno,omitempty"`
TimeLive int `json:"time_to_live,omitempty"`
ApnsProduction bool `json:"apns_production"`
OverrideMsgId int64 `json:"override_msg_id,omitempty"`
BigPushDuration int `json:"big_push_duration,omitempty"`
ThirdPartyChannel map[string]map[string]interface{} `json:"third_party_channel,omitempty"`
}

func (this *Option) SetSendno(no int) {
Expand Down