|
|
@ -20,7 +20,6 @@ import (
|
|
|
|
"github.com/jageros/hawox/logx"
|
|
|
|
"github.com/jageros/hawox/logx"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"stock/fund"
|
|
|
|
"stock/fund"
|
|
|
|
"stock/module"
|
|
|
|
|
|
|
|
"stock/stock"
|
|
|
|
"stock/stock"
|
|
|
|
"stock/user"
|
|
|
|
"stock/user"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
@ -116,19 +115,19 @@ func Send(openId string, stk IArg) error {
|
|
|
|
return send(openId, stk, true)
|
|
|
|
return send(openId, stk, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func SendAll(stk IArg) error {
|
|
|
|
//func SendAll(stk IArg) error {
|
|
|
|
user.ForEachUser(func(u module.IUser) bool {
|
|
|
|
// user.ForEachUser(func(u *user.User) bool {
|
|
|
|
if u.HasSubscribed(false, "") {
|
|
|
|
// if u.HasSubscribed(false, "") {
|
|
|
|
err := Send(u.OpenID(), stk)
|
|
|
|
// err := Send(u.OpenID(), stk)
|
|
|
|
if err != nil {
|
|
|
|
// if err != nil {
|
|
|
|
logx.Error(err)
|
|
|
|
// logx.Error(err)
|
|
|
|
return false
|
|
|
|
// return false
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
return true
|
|
|
|
// return true
|
|
|
|
})
|
|
|
|
// })
|
|
|
|
return nil
|
|
|
|
// return nil
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
type rData struct {
|
|
|
|
type rData struct {
|
|
|
|
ToUserName string `xml:"ToUserName"`
|
|
|
|
ToUserName string `xml:"ToUserName"`
|
|
|
@ -137,6 +136,7 @@ type rData struct {
|
|
|
|
MsgType string `xml:"MsgType"`
|
|
|
|
MsgType string `xml:"MsgType"`
|
|
|
|
Content string `xml:"Content"`
|
|
|
|
Content string `xml:"Content"`
|
|
|
|
MsgID int64 `xml:"MsgId"`
|
|
|
|
MsgID int64 `xml:"MsgId"`
|
|
|
|
|
|
|
|
Event string `xml:"Event"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type xml struct {
|
|
|
|
type xml struct {
|
|
|
@ -163,18 +163,52 @@ func Handle(c *gin.Context) {
|
|
|
|
CreateTime: time.Now().Unix(),
|
|
|
|
CreateTime: time.Now().Unix(),
|
|
|
|
Content: "查询股票:=st股票代码(例如:=st600905)\n查询基金:=fd基金代码(例如:=fd161725)\n\n" +
|
|
|
|
Content: "查询股票:=st股票代码(例如:=st600905)\n查询基金:=fd基金代码(例如:=fd161725)\n\n" +
|
|
|
|
"订阅股票:+st股票代码(例如:+st600905)\n订阅基金:+fd基金代码(例如:+fd161725)\n\n" +
|
|
|
|
"订阅股票:+st股票代码(例如:+st600905)\n订阅基金:+fd基金代码(例如:+fd161725)\n\n" +
|
|
|
|
"取消订阅股票:-st股票代码(例如:-st600905)\n取消订阅基金:-fd基金代码(例如:-fd161725)",
|
|
|
|
"取消订阅股票:-st股票代码(例如:-st600905)\n取消订阅基金:-fd基金代码(例如:-fd161725)\n\n" +
|
|
|
|
|
|
|
|
"查询已订阅股票:lst\n" +
|
|
|
|
|
|
|
|
"查询已订阅基金:lfd\n" +
|
|
|
|
|
|
|
|
"停止通知:stop\n" +
|
|
|
|
|
|
|
|
"启动通知:start\n",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if rMsg.MsgType == "text" {
|
|
|
|
|
|
|
|
u, err := user.GetUser(rMsg.FromUserName)
|
|
|
|
u, err := user.GetUser(rMsg.FromUserName)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
c.String(http.StatusOK, err.Error())
|
|
|
|
wMsg.Content = err.Error()
|
|
|
|
c.Abort()
|
|
|
|
rMsg.MsgType = ""
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if rMsg.MsgType == "text" {
|
|
|
|
|
|
|
|
|
|
|
|
switch {
|
|
|
|
switch {
|
|
|
|
|
|
|
|
case strings.ToLower(rMsg.Content) == "stop":
|
|
|
|
|
|
|
|
u.Stop()
|
|
|
|
|
|
|
|
wMsg.Content = "已停止通知!"
|
|
|
|
|
|
|
|
case strings.ToLower(rMsg.Content) == "start":
|
|
|
|
|
|
|
|
u.Start()
|
|
|
|
|
|
|
|
wMsg.Content = "已启动通知!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case strings.ToLower(rMsg.Content) == "lst":
|
|
|
|
|
|
|
|
codes := u.Codes(false)
|
|
|
|
|
|
|
|
stks, err := stock.GetStocks(codes...)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
wMsg.Content = "查询错误:\n" + err.Error()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
msg := stks.Msg()
|
|
|
|
|
|
|
|
if msg == "" {
|
|
|
|
|
|
|
|
wMsg.Content = "您未订阅任何股票!"
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
wMsg.Content = "所有订阅股票信息:\n" + msg
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case strings.ToLower(rMsg.Content) == "lfd":
|
|
|
|
|
|
|
|
codes := u.Codes(true)
|
|
|
|
|
|
|
|
msg := fund.FundsMsg(codes...)
|
|
|
|
|
|
|
|
if msg == "" {
|
|
|
|
|
|
|
|
wMsg.Content = "您未订阅任何基金!"
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
wMsg.Content = "所有订阅基金信息:\n" + msg
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case len(rMsg.Content) < 9:
|
|
|
|
case len(rMsg.Content) < 9:
|
|
|
|
break
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
@ -227,5 +261,19 @@ func Handle(c *gin.Context) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if rMsg.MsgType == "event" {
|
|
|
|
|
|
|
|
switch rMsg.Event {
|
|
|
|
|
|
|
|
case "subscribe":
|
|
|
|
|
|
|
|
logx.Infof("user=%s subscribe!", u.OpenID())
|
|
|
|
|
|
|
|
u.Start()
|
|
|
|
|
|
|
|
case "unsubscribe":
|
|
|
|
|
|
|
|
logx.Infof("user=%s unsubscribe!", u.OpenID())
|
|
|
|
|
|
|
|
u.Stop()
|
|
|
|
|
|
|
|
c.String(http.StatusOK, "success")
|
|
|
|
|
|
|
|
c.Abort()
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
c.XML(http.StatusOK, wMsg)
|
|
|
|
c.XML(http.StatusOK, wMsg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|