wxgzh
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jageros/hawox/attribute"
|
||||
"github.com/jageros/hawox/contextx"
|
||||
"github.com/jageros/hawox/httpx"
|
||||
"github.com/jageros/hawox/logx"
|
||||
@@ -10,8 +11,11 @@ import (
|
||||
"net/http"
|
||||
"stock/cfg"
|
||||
"stock/fund"
|
||||
"stock/module"
|
||||
"stock/msg"
|
||||
"stock/stock"
|
||||
"stock/user"
|
||||
"stock/wxgzh"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -32,6 +36,19 @@ func main() {
|
||||
|
||||
timer.Initialize(ctx) // 定时器初始化
|
||||
|
||||
// 初始化MongoDB
|
||||
attribute.Initialize(ctx, func(opt *attribute.Option) {
|
||||
opt.DBName = "stock-fund"
|
||||
})
|
||||
|
||||
err = user.LoadAllUserIntoCache()
|
||||
if err != nil {
|
||||
logx.Fatal(err)
|
||||
}
|
||||
|
||||
stockCodes := user.Codes(false)
|
||||
fundCodes := user.Codes(true)
|
||||
|
||||
timer.RunEveryDay(9, 25, 0, func() {
|
||||
if !stock.IsSellDay(time.Now()) {
|
||||
logx.Info("今天不是交易日!")
|
||||
@@ -63,7 +80,7 @@ func main() {
|
||||
logx.Info("今天不是交易日!")
|
||||
return
|
||||
}
|
||||
text := fund.FundsMsg(cfg.FundCodes...)
|
||||
text := fund.FundsMsg(fundCodes...)
|
||||
if text == "" {
|
||||
logx.Errorf("收集基金数据为空!")
|
||||
return
|
||||
@@ -76,11 +93,12 @@ func main() {
|
||||
}
|
||||
})
|
||||
|
||||
err = stock.Init(stockCodes...)
|
||||
if err != nil {
|
||||
logx.Fatal(err)
|
||||
}
|
||||
|
||||
ctx.Go(func(ctx contextx.Context) error {
|
||||
ss, err := stock.NewStocks(cfg.StockCodes...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var count int
|
||||
var opened, closed bool
|
||||
@@ -95,7 +113,7 @@ func main() {
|
||||
if !closed {
|
||||
if stock.HasClose(time.Now()) {
|
||||
logx.Info("--- 已闭市 ---")
|
||||
ss.Clear()
|
||||
stock.Clear()
|
||||
} else {
|
||||
logx.Info("--- 未开市 ---")
|
||||
}
|
||||
@@ -111,7 +129,7 @@ func main() {
|
||||
logx.Infof("--- 交易中 ---")
|
||||
}
|
||||
|
||||
err = ss.Update()
|
||||
err = stock.Update()
|
||||
if err != nil {
|
||||
count++
|
||||
logx.Errorf("Update ErrCount=%d err=%v", count, err)
|
||||
@@ -121,19 +139,33 @@ func main() {
|
||||
continue
|
||||
}
|
||||
|
||||
text := ss.Msg()
|
||||
if text == "" {
|
||||
logx.Info("已更新数据,未超过阈值,无警告!")
|
||||
continue
|
||||
}
|
||||
err = msg.Send(text)
|
||||
if err != nil {
|
||||
count++
|
||||
logx.Errorf("SendMsg ErrCount=%d err=%v", count, err)
|
||||
if count > 10 {
|
||||
return err
|
||||
user.ForEachUser(func(u module.IUser) bool {
|
||||
codes := u.Codes(false)
|
||||
stk, err := stock.GetStocks(codes...)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
} else {
|
||||
err = wxgzh.Send(u.OpenID(), stk)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
//text := ss.Msg()
|
||||
//if text == "" {
|
||||
// logx.Info("已更新数据,未超过阈值,无警告!")
|
||||
// continue
|
||||
//}
|
||||
//err = msg.Send(text)
|
||||
//if err != nil {
|
||||
// count++
|
||||
// logx.Errorf("SendMsg ErrCount=%d err=%v", count, err)
|
||||
// if count > 10 {
|
||||
// return err
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -143,21 +175,12 @@ func main() {
|
||||
r.GET("/sayhello", func(c *gin.Context) {
|
||||
httpx.PkgMsgWrite(c, map[string]interface{}{"say": "hello world!"})
|
||||
})
|
||||
r.POST("/receive", func(c *gin.Context) {
|
||||
msgs := &msg.RData{}
|
||||
err := c.BindXML(msgs)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
} else {
|
||||
logx.Info(msgs)
|
||||
}
|
||||
|
||||
c.String(http.StatusOK, "success")
|
||||
})
|
||||
r.POST("/receive", wxgzh.Handle)
|
||||
|
||||
r.GET("/receive", func(c *gin.Context) {
|
||||
echostr := c.Query("echostr")
|
||||
logx.Infof("=== %s ===", echostr)
|
||||
logx.Infof("配置接口 %s", echostr)
|
||||
c.String(http.StatusOK, echostr)
|
||||
})
|
||||
}, func(s *httpx.Server) {
|
||||
|
||||
Reference in New Issue
Block a user