send.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package reminder
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "git.getensh.com/common/gopkgs/logger"
  7. "go.uber.org/zap"
  8. "property-task/parser"
  9. "property-task/pb"
  10. pb_v1 "property-task/pb/v1"
  11. "time"
  12. )
  13. // 发送公众号消息
  14. func sendMsgWx(publicOpenids []string, gardenName string) {
  15. remark := "详情请进入小程序查看"
  16. for _, popenId := range publicOpenids {
  17. content := []*pb_v1.WxPublicMsgKeyValue{
  18. &pb_v1.WxPublicMsgKeyValue{Key: "first", Value: "您在" + gardenName + "的房屋/车位有欠费账单"},
  19. &pb_v1.WxPublicMsgKeyValue{Key: "remark", Value: remark},
  20. }
  21. mreq := pb_v1.WxPublicMsgSendRequest{
  22. PublicOpenId: popenId,
  23. Content: content,
  24. TemplateId: parser.Conf.ThirdParty.Wx.PublicMsgTmpId,
  25. }
  26. _, err := pb.Thirdparty.WxPublicMsgSend(context.Background(), &mreq)
  27. if err != nil {
  28. logger.Error("func",
  29. zap.String("call", "pb.Thirdparty.WxPublicMsgSend "),
  30. zap.String("error", err.Error()))
  31. continue
  32. }
  33. }
  34. }
  35. // 发送短信消息
  36. func sendMsgPhone(phones []string, gardenName string) {
  37. for _, phone := range phones {
  38. mreq := pb_v1.TencentMsgSendRequest{
  39. Phone: phone,
  40. MsgType: 1,
  41. Datas: []string{gardenName},
  42. }
  43. _, err := pb.Thirdparty.TencentMsgSend(context.Background(), &mreq)
  44. if err != nil {
  45. logger.Error("func",
  46. zap.String("call", "pb.Garden.TencentMsgSend "),
  47. zap.String("error", err.Error()))
  48. continue
  49. }
  50. }
  51. }
  52. // 定时发送消息
  53. func SendUrgeMsg() {
  54. fmt.Printf("开始发送催缴信息\n")
  55. now := time.Now()
  56. nowDay := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
  57. str := getGardenInfo(nowDay.Unix())
  58. if str == "" {
  59. return
  60. }
  61. gardens := []pb_v1.GardenIdInfo{}
  62. _ = json.Unmarshal([]byte(str), &gardens)
  63. for _, garden := range gardens {
  64. if garden.GardenId == 0 {
  65. continue
  66. }
  67. phones := popAllObjUsersPhones(nowDay.Unix(), garden.GardenId)
  68. openids := popAllObjUsersOpenids(nowDay.Unix(), garden.GardenId)
  69. fmt.Printf("phones:%v\n", phones)
  70. if len(phones) > 0 {
  71. sendMsgPhone(phones, garden.GardenName)
  72. }
  73. fmt.Printf("openids:%v\n", openids)
  74. if len(openids) > 0 {
  75. sendMsgWx(openids, garden.GardenName)
  76. }
  77. }
  78. }