local.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package local
  2. import (
  3. "fmt"
  4. "time"
  5. "kpt.notice/apiserver/model"
  6. "kpt.notice/apiserver/service"
  7. "kpt.notice/middleware/notice"
  8. )
  9. var s *service.Service
  10. func Init(svc *service.Service) {
  11. s = svc
  12. }
  13. func TestMsg() {
  14. Job()
  15. }
  16. func SendDBMsg() {
  17. m := new(model.Message)
  18. if e := s.DB.Table("message").Where("id = ?", 4120).Find(&m).Error; e != nil {
  19. fmt.Println(e)
  20. }
  21. m.Target = `["oLd1b56PwpexCa0QK4NCkza9TKyY"]`
  22. e := service.SendMsg(m)
  23. fmt.Println(e)
  24. e = s.UpdateMessage(m)
  25. fmt.Println(e)
  26. }
  27. func SendAllMsg() {
  28. service.ReadMsgs()
  29. }
  30. func Job() {
  31. time.Sleep(time.Minute * 10)
  32. }
  33. func SendMsg() {
  34. p := `{
  35. "miniprogram": {
  36. "appid": "wx9ab2b5b25701da0a",
  37. "pagepath": "pages/login/login"
  38. },
  39. "template_id": "RLPlaCnqQZt_6s4HZuaFJYbQ9gmTfIYipTYDoKJInY8",
  40. "touser": "oLd1b56PwpexCa0QK4NCkza9TKyY",
  41. "data": {
  42. "first": {
  43. "value": "恭喜你购买成功!",
  44. "color": "#173177"
  45. },
  46. "keyword1": {
  47. "value": "巧克力",
  48. "color": "#173177"
  49. },
  50. "keyword2": {
  51. "value": "39.8元",
  52. "color": "#173177"
  53. },
  54. "keyword3": {
  55. "value": "2014年9月22日",
  56. "color": "#173177"
  57. },
  58. "remark": {
  59. "value": "欢迎再次购买!",
  60. "color": "#173177"
  61. }
  62. }
  63. }`
  64. resp, e := notice.MsgTemplate([]byte(p))
  65. fmt.Printf("%s\n", resp)
  66. fmt.Println(e)
  67. }