finish
This commit is contained in:
@@ -19,7 +19,9 @@ import (
|
||||
"github.com/jageros/hawox/httpc"
|
||||
"github.com/jageros/hawox/logx"
|
||||
"net/http"
|
||||
"stock/fund"
|
||||
"stock/module"
|
||||
"stock/stock"
|
||||
"stock/user"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -52,6 +54,11 @@ type IArg interface {
|
||||
Arg(openid string) map[string]interface{}
|
||||
}
|
||||
|
||||
type IMsg interface {
|
||||
Msg() string
|
||||
Name() string
|
||||
}
|
||||
|
||||
func getAccessToken(update bool) (string, error) {
|
||||
if !update && time.Now().Unix() < expiresIn {
|
||||
return accessToken, nil
|
||||
@@ -77,6 +84,9 @@ func send(openID string, arg IArg, recall bool) error {
|
||||
url := fmt.Sprintf(sendUrl, token)
|
||||
|
||||
msg := arg.Arg(openID)
|
||||
if msg == nil {
|
||||
return errcode.New(1, "arg == nil")
|
||||
}
|
||||
resp := &Resp{}
|
||||
err = httpc.RequestWithInterface(httpc.POST, url, httpc.JSON, msg, nil, resp)
|
||||
if err != nil {
|
||||
@@ -146,7 +156,8 @@ func Handle(c *gin.Context) {
|
||||
FromUserName: rMsg.ToUserName,
|
||||
MsgType: "text",
|
||||
CreateTime: time.Now().Unix(),
|
||||
Content: "订阅股票:+st股票代码(例如:+st600905)\n订阅基金:+fd基金代码(例如:+fd161725)\n" +
|
||||
Content: "查询股票:=st股票代码(例如:=st600905)\n查询基金:=fd基金代码(例如:=fd161725)\n\n" +
|
||||
"订阅股票:+st股票代码(例如:+st600905)\n订阅基金:+fd基金代码(例如:+fd161725)\n\n" +
|
||||
"取消订阅股票:-st股票代码(例如:-st600905)\n取消订阅基金:-fd基金代码(例如:-fd161725)",
|
||||
}
|
||||
|
||||
@@ -159,12 +170,55 @@ func Handle(c *gin.Context) {
|
||||
}
|
||||
|
||||
switch {
|
||||
case len(rMsg.Content) < 9:
|
||||
break
|
||||
|
||||
case strings.HasPrefix(rMsg.Content, "="):
|
||||
code := rMsg.Content[3:]
|
||||
isFund := rMsg.Content[1:3] == "fd"
|
||||
var im IMsg
|
||||
if isFund {
|
||||
im, err = fund.NewFund(code)
|
||||
} else {
|
||||
im, err = stock.GetStock(code)
|
||||
}
|
||||
if err != nil {
|
||||
wMsg.Content = "查询出错:\n" + err.Error()
|
||||
} else {
|
||||
wMsg.Content = "查询成功:\n" + im.Msg()
|
||||
}
|
||||
|
||||
case strings.HasPrefix(rMsg.Content, "+"):
|
||||
u.Subscribe(rMsg.Content[1:3] == "fd", rMsg.Content[3:])
|
||||
wMsg.Content = "订阅成功!"
|
||||
code := rMsg.Content[3:]
|
||||
isFund := rMsg.Content[1:3] == "fd"
|
||||
var im IMsg
|
||||
if isFund {
|
||||
im, err = fund.NewFund(code)
|
||||
} else {
|
||||
im, err = stock.GetStock(code)
|
||||
}
|
||||
if err != nil {
|
||||
wMsg.Content = "订阅出错:\n" + err.Error()
|
||||
} else {
|
||||
u.Subscribe(isFund, code)
|
||||
wMsg.Content = "订阅成功:\n" + im.Msg()
|
||||
}
|
||||
|
||||
case strings.HasPrefix(rMsg.Content, "-"):
|
||||
u.UnSubscribe(rMsg.Content[1:3] == "fd", rMsg.Content[3:])
|
||||
wMsg.Content = "成功取消订阅!"
|
||||
code := rMsg.Content[3:]
|
||||
isFund := rMsg.Content[1:3] == "fd"
|
||||
var im IMsg
|
||||
if isFund {
|
||||
im, err = fund.NewFund(code)
|
||||
} else {
|
||||
im, err = stock.GetStock(code)
|
||||
}
|
||||
if err != nil {
|
||||
wMsg.Content = "取消订阅:\n" + err.Error()
|
||||
} else {
|
||||
wMsg.Content = "成功取消订阅:" + im.Name()
|
||||
}
|
||||
u.UnSubscribe(isFund, code)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user