sendwxtmpljyschoolmsglogic.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/MessageCenter/rpc/internal/common"
  4. "app.yhyue.com/moapp/MessageCenter/rpc/internal/config"
  5. "app.yhyue.com/moapp/MessageCenter/rpc/internal/svc"
  6. "app.yhyue.com/moapp/MessageCenter/rpc/type/message"
  7. "app.yhyue.com/moapp/MessageCenter/util"
  8. qrpc "app.yhyue.com/moapp/jybase/rpc"
  9. "context"
  10. "strings"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type SendWxTmplJySchoolMsgLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewSendWxTmplJySchoolMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendWxTmplJySchoolMsgLogic {
  19. return &SendWxTmplJySchoolMsgLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. // SendWxTmplJySchoolMsg 发送剑鱼学堂微信模版消息
  26. func (l *SendWxTmplJySchoolMsgLogic) SendWxTmplJySchoolMsg(in *message.JySchoolMsg) (*message.SendMsgResponse, error) {
  27. var total int
  28. userIdArr := strings.Split(in.UserIds, ",")
  29. for index, userId := range userIdArr {
  30. p := &common.WxTmplPush{
  31. MgoId: userId,
  32. MessageClass: "o_msg_jyschool",
  33. PushTmplId: config.ConfigJson.WxTmplConfig.TmplSetting.JySchoolTmplId,
  34. }
  35. err := p.SendMsg(in.Url, func() map[string]*qrpc.TmplItem {
  36. // 消息模版 课程名称 {{thing1.DATA}} 课程时间 {{time7.DATA}} 课程地点 {{thing6.DATA}} 课程类型 {{const11.DATA}}
  37. return map[string]*qrpc.TmplItem{
  38. "thing1": &qrpc.TmplItem{
  39. Value: in.Title,
  40. },
  41. "time7": &qrpc.TmplItem{
  42. Value: in.Date,
  43. },
  44. "thing6": &qrpc.TmplItem{
  45. Value: in.Address,
  46. },
  47. "const11": &qrpc.TmplItem{
  48. Value: config.ConfigJson.WxTmplConfig.TmplSetting.CloseNotice,
  49. },
  50. }
  51. })
  52. if err != nil {
  53. logx.Error(err)
  54. } else {
  55. total++
  56. }
  57. if index%10 == 0 {
  58. logx.Infof("共%d条,已送达%d条,失败%d条", len(userIdArr), total, index-total)
  59. }
  60. }
  61. return &message.SendMsgResponse{
  62. Total: util.Int64All(total),
  63. Message: "",
  64. }, nil
  65. }