12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- package reminder
- import (
- "context"
- "encoding/json"
- "fmt"
- "git.getensh.com/common/gopkgs/logger"
- "go.uber.org/zap"
- "property-task/parser"
- "property-task/pb"
- pb_v1 "property-task/pb/v1"
- "time"
- )
- // 发送公众号消息
- func sendMsgWx(publicOpenids []string, gardenName string) {
- remark := "详情请进入小程序查看"
- for _, popenId := range publicOpenids {
- content := []*pb_v1.WxPublicMsgKeyValue{
- &pb_v1.WxPublicMsgKeyValue{Key: "first", Value: "您在" + gardenName + "的房屋/车位有欠费账单"},
- &pb_v1.WxPublicMsgKeyValue{Key: "remark", Value: remark},
- }
- mreq := pb_v1.WxPublicMsgSendRequest{
- PublicOpenId: popenId,
- Content: content,
- TemplateId: parser.Conf.ThirdParty.Wx.PublicMsgTmpId,
- }
- _, err := pb.Thirdparty.WxPublicMsgSend(context.Background(), &mreq)
- if err != nil {
- logger.Error("func",
- zap.String("call", "pb.Thirdparty.WxPublicMsgSend "),
- zap.String("error", err.Error()))
- continue
- }
- }
- }
- // 发送短信消息
- func sendMsgPhone(phones []string, gardenName string) {
- for _, phone := range phones {
- mreq := pb_v1.TencentMsgSendRequest{
- Phone: phone,
- MsgType: 1,
- Datas: []string{gardenName},
- }
- _, err := pb.Thirdparty.TencentMsgSend(context.Background(), &mreq)
- if err != nil {
- logger.Error("func",
- zap.String("call", "pb.Garden.TencentMsgSend "),
- zap.String("error", err.Error()))
- continue
- }
- }
- }
- // 定时发送消息
- func SendUrgeMsg() {
- fmt.Printf("开始发送催缴信息\n")
- now := time.Now()
- nowDay := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
- str := getGardenInfo(nowDay.Unix())
- if str == "" {
- return
- }
- gardens := []pb_v1.GardenIdInfo{}
- _ = json.Unmarshal([]byte(str), &gardens)
- for _, garden := range gardens {
- if garden.GardenId == 0 {
- continue
- }
- phones := popAllObjUsersPhones(nowDay.Unix(), garden.GardenId)
- openids := popAllObjUsersOpenids(nowDay.Unix(), garden.GardenId)
- fmt.Printf("phones:%v\n", phones)
- if len(phones) > 0 {
- sendMsgPhone(phones, garden.GardenName)
- }
- fmt.Printf("openids:%v\n", openids)
- if len(openids) > 0 {
- sendMsgWx(openids, garden.GardenName)
- }
- }
- }
|