This commit is contained in:
wangchuxiao
2022-04-08 15:40:07 +08:00
parent 59cc45eaab
commit 4efdabc1ff
14 changed files with 240 additions and 43 deletions
+23 -10
View File
@@ -10,14 +10,29 @@ import (
"net/http"
)
type JPushResp struct {
var (
JPushClient *JPush
)
func init() {
JPushClient = newGetuiClient()
}
type JPush struct {
type JPush struct{}
func newGetuiClient() *JPush {
return &JPush{}
}
func JGAccountListPush(accounts []string, alert, detailContent, platform string) ([]byte, error) {
func (j *JPush) Auth(apiKey, secretKey string, timeStamp int64) (token string, err error) {
return token, nil
}
func (j *JPush) SetAlias(cid, alias string) (resp string, err error) {
return resp, nil
}
func (j *JPush) Push(accounts []string, alert, detailContent, platform, operationID string) (string, error) {
var pf requestBody.Platform
_ = pf.SetPlatform(platform)
var au requestBody.Audience
@@ -37,25 +52,23 @@ func JGAccountListPush(accounts []string, alert, detailContent, platform string)
con, err := json.Marshal(po)
if err != nil {
return nil, err
return "", err
}
client := &http.Client{}
req, err := http.NewRequest("POST", config.Config.Push.Jpns.PushUrl, bytes.NewBuffer(con))
if err != nil {
return nil, err
return "", err
}
req.Header.Set("Authorization", common.GetAuthorization(config.Config.Push.Jpns.AppKey, config.Config.Push.Jpns.MasterSecret))
resp, err := client.Do(req)
if err != nil {
return nil, err
return "", err
}
defer resp.Body.Close()
result, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
return "", err
}
return result, nil
return string(result), nil
}