master
jager 3 years ago
parent 627c6582e3
commit 179c6a3afa

@ -57,3 +57,6 @@ func Send(text string) error {
}
return nil
}

@ -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)
})
}

@ -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
}

Loading…
Cancel
Save