package local import ( "fmt" "time" "kpt.notice/apiserver/model" "kpt.notice/apiserver/service" "kpt.notice/middleware/notice" ) var s *service.Service func Init(svc *service.Service) { s = svc } func TestMsg() { Job() } func SendDBMsg() { m := new(model.Message) if e := s.DB.Table("message").Where("id = ?", 4120).Find(&m).Error; e != nil { fmt.Println(e) } m.Target = `["oLd1b56PwpexCa0QK4NCkza9TKyY"]` e := service.SendMsg(m) fmt.Println(e) e = s.UpdateMessage(m) fmt.Println(e) } func SendAllMsg() { service.ReadMsgs() } func Job() { time.Sleep(time.Minute * 10) } func SendMsg() { p := `{ "miniprogram": { "appid": "wx9ab2b5b25701da0a", "pagepath": "pages/login/login" }, "template_id": "RLPlaCnqQZt_6s4HZuaFJYbQ9gmTfIYipTYDoKJInY8", "touser": "oLd1b56PwpexCa0QK4NCkza9TKyY", "data": { "first": { "value": "恭喜你购买成功!", "color": "#173177" }, "keyword1": { "value": "巧克力", "color": "#173177" }, "keyword2": { "value": "39.8元", "color": "#173177" }, "keyword3": { "value": "2014年9月22日", "color": "#173177" }, "remark": { "value": "欢迎再次购买!", "color": "#173177" } } }` resp, e := notice.MsgTemplate([]byte(p)) fmt.Printf("%s\n", resp) fmt.Println(e) }