refactor wechat sender

This commit is contained in:
Ulric Qin 2020-10-09 22:47:10 +08:00
parent 8455994118
commit c4ad9f1e88
2 changed files with 12 additions and 8 deletions

View File

@ -12,8 +12,8 @@ import (
"github.com/didi/nightingale/src/common/dataobj"
"github.com/didi/nightingale/src/modules/rdb/config"
"github.com/didi/nightingale/src/modules/rdb/corp"
"github.com/didi/nightingale/src/modules/rdb/redisc"
"github.com/didi/nightingale/src/modules/rdb/wechat"
)
func ConsumeIm() {
@ -83,13 +83,17 @@ func sendImByWeChat(message *dataobj.Message) {
return
}
client := corp.New(corpID, agentID, secret)
client := wechat.New(corpID, agentID, secret)
var err error
for i := 0; i < cnt; i++ {
err = client.Send(corp.Message{
ToUser: message.Tos[i],
toUser := strings.TrimSpace(message.Tos[i])
if toUser == "" {
continue
}
err = client.Send(wechat.Message{
ToUser: toUser,
MsgType: "text",
Text: corp.Content{Content: message.Content},
Text: wechat.Content{Content: message.Content},
})
if err != nil {

View File

@ -1,4 +1,4 @@
package corp
package wechat
import (
"bytes"
@ -56,11 +56,11 @@ type Message struct {
}
// New 实例化微信企业号应用
func New(corpID string, agentID int, AgentSecret string) *Client {
func New(corpID string, agentID int, agentSecret string) *Client {
c := new(Client)
c.CorpID = corpID
c.AgentID = agentID
c.AgentSecret = AgentSecret
c.AgentSecret = agentSecret
return c
}