1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package public_msg
- import (
- "context"
- "git.getensh.com/common/gopkgs/database"
- dbmodel "property-household/model"
- "property-household/parser"
- "property-household/pb"
- pb_v1 "property-household/pb/v1"
- "time"
- )
- type ServiceInfo struct {
- Name string
- State string
- }
- func getGardenInfos(ids []int64) (map[int64]pb_v1.GardenItem, error) {
- ret := map[int64]pb_v1.GardenItem{}
- if len(ids) == 0 {
- return ret, nil
- }
- mreq := pb_v1.GardenInfosRequest{
- Ids: ids,
- }
- mreply, err := pb.System.GardenInfos(context.Background(), &mreq)
- if err != nil {
- return nil, err
- }
- for _, v := range mreply.List {
- ret[v.Id] = *v
- }
- return ret, nil
- }
- // 发送公众号消息
- func SendMsgWx(uid int64, gardenId int64, info ServiceInfo) {
- remark := "详情请进入小程序查看"
- if parser.Conf.ThirdParty.Wx.PublicStateMsgTmpId == "" {
- return
- }
- p := dbmodel.TUser{}
- where := map[string]interface{}{
- "id": uid,
- }
- p.Find(database.DB(), where)
- if p.PublicOpenId == "" {
- return
- }
- gardenInfos, err := getGardenInfos([]int64{gardenId})
- if err != nil {
- return
- }
- gardenName := gardenInfos[gardenId].GardenName
- popenId := p.PublicOpenId
- content := []*pb_v1.WxPublicMsgKeyValue{
- &pb_v1.WxPublicMsgKeyValue{Key: "first", Value: "亲爱的用户,您在" + gardenName + "的服务状态发生变更"},
- &pb_v1.WxPublicMsgKeyValue{Key: "keyword1", Value: info.Name},
- &pb_v1.WxPublicMsgKeyValue{Key: "keyword2", Value: info.State},
- &pb_v1.WxPublicMsgKeyValue{Key: "keyword3", Value: time.Now().Format("2006-01-02 15:04:05")},
- &pb_v1.WxPublicMsgKeyValue{Key: "remark", Value: remark},
- }
- mreq := pb_v1.WxPublicMsgSendRequest{
- PublicOpenId: popenId,
- Content: content,
- TemplateId: parser.Conf.ThirdParty.Wx.PublicStateMsgTmpId,
- }
- _, err = pb.Thirdparty.WxPublicMsgSend(context.Background(), &mreq)
- if err == nil {
- return
- }
- }
|