wechat.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // wechat
  2. //
  3. // Description: wechat service
  4. //
  5. // Schemes: http, https
  6. // Host: localhost:0
  7. // BasePath: /
  8. // Version: 0.0.1
  9. // SecurityDefinitions:
  10. // Token:
  11. // type: apiKey
  12. // name: Authorization
  13. // in: header
  14. // Security:
  15. // - Token: []
  16. // Consumes:
  17. // - application/json
  18. //
  19. // Produces:
  20. // - application/json
  21. //
  22. // swagger:meta
  23. package main
  24. import (
  25. "flag"
  26. "fmt"
  27. "github.com/zeromicro/go-zero/core/logx"
  28. "wechat-api/crontask"
  29. "wechat-api/internal/config"
  30. "wechat-api/internal/handler"
  31. "wechat-api/internal/svc"
  32. "github.com/robfig/cron/v3"
  33. "github.com/zeromicro/go-zero/core/conf"
  34. "github.com/zeromicro/go-zero/rest"
  35. )
  36. var configFile = flag.String("f", "etc/wechat.yaml", "the config file")
  37. func main() {
  38. flag.Parse()
  39. var c config.Config
  40. conf.MustLoad(*configFile, &c, conf.UseEnv())
  41. server := rest.MustNewServer(c.RestConf, rest.WithCors(c.CROSConf.Address))
  42. defer server.Stop()
  43. ctx := svc.NewServiceContext(c)
  44. handler.RegisterHandlers(server, ctx)
  45. //个微处理程序 没有彻底完成之前不能开,和cow重复了
  46. if len(ctx.WechatWs) == 0 {
  47. fmt.Println("wechat ws is nil")
  48. } else if ctx.WechatWs["default"] != nil {
  49. //var ic channel.IChannel
  50. //for _, ws := range ctx.WechatWs {
  51. //switch ws.CTypes {
  52. //case "wechat":
  53. // ic = channel.NewWechatChannel(ws, ctx)
  54. //}
  55. //ws.RegisterMessageHandler(ic.OnMessage)
  56. //ws.RegisterMessageHandler(MessageHandlers.NewFriendPushNoticeHandler(ctx).Handler)
  57. //}
  58. logx.Info("注册个微处理通道~")
  59. }
  60. //for {
  61. // time.Sleep(time.Second * 10)
  62. //}
  63. cronCtx := cron.New(cron.WithChain(
  64. cron.SkipIfStillRunning(cron.DefaultLogger),
  65. cron.Recover(cron.DefaultLogger),
  66. ))
  67. crontask.ScheduleRun(cronCtx, ctx)
  68. go cronCtx.Start()
  69. defer cronCtx.Stop()
  70. fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
  71. server.Start()
  72. }