golang-im聊天
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.
 
 
 
 

112 lines
3.7 KiB

  1. package service
  2. import (
  3. jg_push "code.fnuoos.com/go_rely_warehouse/zyos_go_jg_push.git/hdl"
  4. md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_jg_push.git/md"
  5. "fmt"
  6. svc "gim/internal/business/comm/service"
  7. "gim/internal/business/comm/utils"
  8. md3 "gim/internal/logic/domain/message/md"
  9. "gim/pkg/logger"
  10. "go.uber.org/zap"
  11. "strings"
  12. )
  13. func getChangeContent(args md3.PushParams, Content string) string {
  14. Content = strings.Replace(Content, "[MasterId]", args.MasterId, -1)
  15. Content = strings.Replace(Content, "[消息发送者-会员昵称]", args.SendUserNickname, -1)
  16. Content = strings.Replace(Content, "[消息发送者-会员头像]", args.SendUserAvatarUrl, -1)
  17. //Content = strings.Replace(Content, "[消息类型]", args.MessageType, -1)
  18. //Content = strings.Replace(Content, "[备注]", args.Memo, -1)
  19. Content = strings.Replace(Content, "[时间]", args.Times, -1)
  20. return Content
  21. }
  22. // CommAddPush 公共处理推送数据
  23. func CommAddPush(args md3.PushParams) {
  24. logger.Logger.Debug("CommAddPush",
  25. zap.String("master_id", args.MasterId),
  26. zap.String("uid", args.Uid),
  27. zap.String("push_alia", args.PushAlia),
  28. zap.String("title", args.Title),
  29. zap.String("content", args.Content),
  30. zap.String("push_type", args.PushType),
  31. zap.String("message_type", args.MessageType),
  32. zap.String("send_user_nickname", args.SendUserNickname),
  33. zap.String("send_user_avatar_url", args.SendUserAvatarUrl),
  34. zap.String("reason", args.Memo),
  35. zap.String("times", args.Times),
  36. )
  37. pushPlatform := svc.SysCfgGet(args.MasterId, "app_push_platform")
  38. if pushPlatform == "JgPush" { //极光
  39. //args.Content = getChangeContent(args, args.Content)
  40. JgPush(args)
  41. return
  42. }
  43. return
  44. }
  45. func JgPush(args md3.PushParams) {
  46. jgPushAppKey := svc.SysCfgGet(args.MasterId, "jg_push_app_key")
  47. jgPushAppSecret := svc.SysCfgGet(args.MasterId, "jg_push_app_secret")
  48. fmt.Println(">>>>>>>>>>>>>>>>>>>>jg_push_app_key<<<<<<<<<<<<<<<<<<<<<<", jgPushAppKey)
  49. fmt.Println(">>>>>>>>>>>>>>>>>>>>jg_push_app_secret<<<<<<<<<<<<<<<<<<<<<<", jgPushAppSecret)
  50. if jgPushAppKey == "" || jgPushAppSecret == "" {
  51. return
  52. }
  53. //alia := db.DbUserPushForJg.UserPushForJgGetWithDb(args.MasterId, args.Uid)
  54. var aud = md2.PushAudience{Alias: []string{args.PushAlia}}
  55. var extras = map[string]interface{}{
  56. "master_id": args.MasterId,
  57. "uid": args.Uid,
  58. "push_type": args.PushType,
  59. "message_type": args.MessageType,
  60. "send_user_nickname": args.SendUserNickname,
  61. "send_user_avatar_url": args.SendUserAvatarUrl,
  62. "memo": args.Memo,
  63. "times": args.Times,
  64. }
  65. var intent = map[string]interface{}{
  66. "url": "#Intent;action=android.intent.action.MAIN;end",
  67. }
  68. var param = md2.PushParam{
  69. Platform: "all",
  70. Audience: aud,
  71. Title: args.Title,
  72. Content: strings.Replace(args.Content, "\n\u0006", "", -1),
  73. Extras: extras,
  74. Intent: intent,
  75. }
  76. send, res, err := jg_push.Send(jgPushAppKey, jgPushAppSecret, param)
  77. utils.FilePutContents("JgPush", utils.SerializeStr(map[string]interface{}{
  78. "send": send,
  79. "res": res,
  80. "push_alia": args.PushAlia,
  81. "title": param.Title,
  82. "content": param.Content,
  83. "jg_push_app_key": jgPushAppKey,
  84. "jg_push_app_secret": jgPushAppSecret,
  85. }))
  86. logger.Logger.Debug("JgPush_log",
  87. zap.String("send", send),
  88. zap.String("res", res),
  89. zap.String("push_alia", args.PushAlia),
  90. zap.String("title", param.Title),
  91. zap.String("content", param.Content),
  92. zap.String("jg_push_app_key", jgPushAppKey),
  93. zap.String("jg_push_app_secret", jgPushAppSecret),
  94. )
  95. if err != nil {
  96. fmt.Println("send_error::::", err)
  97. return
  98. }
  99. if send == "" {
  100. return
  101. }
  102. //TODO::发送成功处理
  103. return
  104. }