蛋蛋星球-制度模式
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.

64 lines
1.6 KiB

  1. package jPush
  2. import (
  3. jpush "code.fnuoos.com/EggPlanet/egg_system_rules.git/jPush/sdk"
  4. "fmt"
  5. )
  6. // 极光推送 最大1000个用户
  7. func PushMoreUser(key, secret, title, content string, platform string, alias []string, extras map[string]interface{}) (map[string]interface{}, error) {
  8. var client = jpush.NewClient(key, secret)
  9. audience := &jpush.PushAudience{
  10. Alias: alias,
  11. }
  12. req := getMsg(title, content, platform, audience, extras)
  13. result, err := client.Push(req)
  14. if err != nil {
  15. return nil, err
  16. }
  17. return result, nil
  18. }
  19. // 广播推送 一天10次
  20. func PushAllUser(key, secret, title, content string, platform string, extras map[string]interface{}) (map[string]interface{}, error) {
  21. var client = jpush.NewClient(key, secret)
  22. audience := "all"
  23. req := getMsg(title, content, platform, audience, extras)
  24. result, err := client.Push(req)
  25. if err != nil {
  26. fmt.Println(err)
  27. return nil, err
  28. }
  29. fmt.Println(result)
  30. return result, nil
  31. }
  32. func getMsg(title, content string, platform string, audience interface{}, extras map[string]interface{}) *jpush.PushRequest {
  33. req := &jpush.PushRequest{
  34. Platform: platform,
  35. Audience: audience,
  36. Notification: &jpush.PushNotification{
  37. Alert: content,
  38. Android: &jpush.NotificationAndroid{
  39. Alert: content,
  40. Title: title,
  41. },
  42. Hmos: &jpush.NotificationHmos{
  43. Alert: content,
  44. Title: title,
  45. },
  46. IOS: &jpush.NotificationIOS{
  47. Alert: content,
  48. },
  49. },
  50. Message: &jpush.PushMessage{
  51. MsgContent: content,
  52. Extras: extras,
  53. },
  54. Options: &jpush.PushOptions{
  55. TimeToLive: 3 * 86400,
  56. ApnsProduction: false,
  57. },
  58. }
  59. return req
  60. }