From 179c6a3afab81a41c8e2e55a98dea482fcc9337f Mon Sep 17 00:00:00 2001 From: jager Date: Fri, 17 Dec 2021 19:08:29 +0800 Subject: [PATCH] msg --- msg/msg.go | 3 ++ msg/msg_test.go | 33 ++++++++++++++++++++ stock/stock.go | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 msg/msg_test.go diff --git a/msg/msg.go b/msg/msg.go index e9c43c9..8759e89 100644 --- a/msg/msg.go +++ b/msg/msg.go @@ -57,3 +57,6 @@ func Send(text string) error { } return nil } + + + diff --git a/msg/msg_test.go b/msg/msg_test.go new file mode 100644 index 0000000..7a48fee --- /dev/null +++ b/msg/msg_test.go @@ -0,0 +1,33 @@ +/** + * @Author: jager + * @Email: lhj168os@gmail.com + * @File: msg_test + * @Date: 2021/12/17 5:56 下午 + * @package: msg + * @Version: v1.0.0 + * + * @Description: + * + */ + +package msg + +import ( + "github.com/jageros/hawox/httpc" + "stock/stock" + "testing" +) + +func Test_Post(t *testing.T) { + url := "" + stk, err := stock.NewStocks(600905) + if err != nil { + t.Error(err) + return + } + stk.ForEachStock(func(stk stock.IArg) { + arg := stk.Arg("o-KDV6NbRaanYz55fJuSgyR0qxxU") + httpc.RequestWithInterface(httpc.POST, url, httpc.JSON, arg, nil) + }) + +} diff --git a/stock/stock.go b/stock/stock.go index dcca2f1..b7a5df6 100644 --- a/stock/stock.go +++ b/stock/stock.go @@ -183,6 +183,16 @@ func (sk *stocks) Msg() string { return resp } +type IArg interface { + Arg(openId string) map[string]interface{} +} + +func (sk *stocks) ForEachStock(f func(stk IArg)) { + for _, k := range sk.ss { + f(k) + } +} + func NewStocks(codes ...string) (*stocks, error) { if len(codes) <= 0 { return nil, errcode.New(1, "股票代码为空") @@ -236,3 +246,73 @@ const msgTemplate = `%s 成交量:%s 成交额: %s 前五总买单:%s 前五总卖单:%s ` + +func (s *stock) Arg(openId string) map[string]interface{} { + + arg := map[string]interface{}{ + "touser": openId, + "template_id": "1EaaO8jlUJBrj5y7Iz5_lJVXoQq2ivTxH8JnAM_vqGU", + "url": "", + + "miniprogram": map[string]interface{}{ + "appid": "wxba88e64e7342b027", + "pagepath": "ab8130a7bf55b78992e3d17f59909e0a", + }, + + "data": map[string]interface{}{ + "first": map[string]interface{}{ + "value": s.values[0], + "color": "#173177", + }, + "keyword1": map[string]interface{}{ + "value": fmt.Sprintf("%s %s", s.values[30], s.values[31]), + "color": "#173177", + }, + "keyword2": map[string]interface{}{ + "value": s.values[2], + "color": "#173177", + }, + "keyword3": map[string]interface{}{ + "value": s.values[1], + "color": "#173177", + }, + "keyword4": map[string]interface{}{ + "value": s.values[3], + "color": "#173177", + }, + "keyword5": map[string]interface{}{ + "value": s.rise(), + "color": "#173177", + }, + "keyword6": map[string]interface{}{ + "value": s.values[4], + "color": "#173177", + }, + "keyword7": map[string]interface{}{ + "value": s.values[5], + "color": "#173177", + }, + "keyword8": map[string]interface{}{ + "value": s.tradingVolume(), + "color": "#173177", + }, + "keyword9": map[string]interface{}{ + "value": numFormat(s.values[9]), + "color": "#173177", + }, + "keyword10": map[string]interface{}{ + "value": s.buyCount(), + "color": "#173177", + }, + "keyword11": map[string]interface{}{ + "value": s.sellCount(), + "color": "#173177", + }, + "remark": map[string]interface{}{ + "value": "欢迎再次购买!", + "color": "#173177", + }, + }, + } + return arg +}