|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package jPush
-
- import (
- jpush "code.fnuoos.com/EggPlanet/egg_system_rules.git/jPush/sdk"
- "fmt"
- )
-
- // 极光推送 最大1000个用户
- func PushMoreUser(key, secret, title, content string, platform string, alias []string, extras map[string]interface{}) (map[string]interface{}, error) {
- var client = jpush.NewClient(key, secret)
- audience := &jpush.PushAudience{
- Alias: alias,
- }
- req := getMsg(title, content, platform, audience, extras)
- result, err := client.Push(req)
- if err != nil {
- return nil, err
- }
- return result, nil
- }
-
- // 广播推送 一天10次
- func PushAllUser(key, secret, title, content string, platform string, extras map[string]interface{}) (map[string]interface{}, error) {
- var client = jpush.NewClient(key, secret)
- audience := "all"
- req := getMsg(title, content, platform, audience, extras)
- result, err := client.Push(req)
- if err != nil {
- fmt.Println(err)
- return nil, err
- }
- fmt.Println(result)
- return result, nil
- }
- func getMsg(title, content string, platform string, audience interface{}, extras map[string]interface{}) *jpush.PushRequest {
- req := &jpush.PushRequest{
- Platform: platform,
- Audience: audience,
- Notification: &jpush.PushNotification{
- Alert: content,
- Android: &jpush.NotificationAndroid{
- Alert: content,
- Title: title,
- },
- Hmos: &jpush.NotificationHmos{
- Alert: content,
- Title: title,
- },
- IOS: &jpush.NotificationIOS{
- Alert: content,
- },
- },
- Message: &jpush.PushMessage{
- MsgContent: content,
- Extras: extras,
- },
- Options: &jpush.PushOptions{
- TimeToLive: 3 * 86400,
- ApnsProduction: false,
- },
- }
- return req
- }
|