You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/push/jpush/push.go

75 lines
1.6 KiB

package push
import (
"Open_IM/internal/push/jpush/common"
"Open_IM/internal/push/jpush/requestBody"
"Open_IM/pkg/common/config"
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
)
3 years ago
var (
JPushClient *JPush
)
func init() {
JPushClient = newGetuiClient()
}
type JPush struct{}
func newGetuiClient() *JPush {
return &JPush{}
}
3 years ago
func (j *JPush) Auth(apiKey, secretKey string, timeStamp int64) (token string, err error) {
return token, nil
}
3 years ago
func (j *JPush) SetAlias(cid, alias string) (resp string, err error) {
return resp, nil
}
3 years ago
func (j *JPush) Push(accounts []string, alert, detailContent, operationID string) (string, error) {
var pf requestBody.Platform
3 years ago
pf.SetAll()
var au requestBody.Audience
au.SetAlias(accounts)
var no requestBody.Notification
3 years ago
no.SetAlert(alert)
var me requestBody.Message
me.SetMsgContent(detailContent)
var o requestBody.Options
o.SetApnsProduction(false)
var po requestBody.PushObj
po.SetPlatform(&pf)
po.SetAudience(&au)
po.SetNotification(&no)
po.SetMessage(&me)
po.SetOptions(&o)
con, err := json.Marshal(po)
if err != nil {
3 years ago
return "", err
}
client := &http.Client{}
req, err := http.NewRequest("POST", config.Config.Push.Jpns.PushUrl, bytes.NewBuffer(con))
if err != nil {
3 years ago
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 {
3 years ago
return "", err
}
defer resp.Body.Close()
result, err := ioutil.ReadAll(resp.Body)
if err != nil {
3 years ago
return "", err
}
3 years ago
return string(result), nil
}