appletterpushlogic.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/MessageCenter/rpc/internal/common"
  4. "app.yhyue.com/moapp/MessageCenter/rpc/internal/svc"
  5. "app.yhyue.com/moapp/MessageCenter/rpc/type/message"
  6. "app.yhyue.com/moapp/jybase/go-xweb/log"
  7. "context"
  8. "strings"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type AppLetterPushLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewAppLetterPushLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AppLetterPushLogic {
  17. return &AppLetterPushLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. // 发送剑鱼微信模版消息
  24. func (l *AppLetterPushLogic) AppLetterPush(in *message.WxTmplMsgRequest) (*message.SendMsgResponse, error) {
  25. var userArr []string
  26. log.Println("app私信push推送内容===", in)
  27. userArr = strings.Split(in.PositionIds, ",")
  28. pushConfig, err := common.GetWxTmplConfig(in.MsgType)
  29. if err != nil {
  30. return &message.SendMsgResponse{
  31. Total: 0,
  32. Message: err.Error(),
  33. }, nil
  34. }
  35. for _, uId := range userArr {
  36. if uId == "" {
  37. continue
  38. }
  39. p := &common.WxTmplPush{
  40. Config: pushConfig,
  41. }
  42. p.Position = uId
  43. uData := p.GetUserPushInfo()
  44. if err = common.AppPushMsg(uData, pushConfig.Switch, in.Url, in.Title, in.Detail, in.MsgType); err != nil {
  45. return &message.SendMsgResponse{
  46. Total: 0,
  47. Message: err.Error(),
  48. }, err
  49. }
  50. }
  51. return &message.SendMsgResponse{
  52. Total: 1,
  53. }, nil
  54. }