From c4ad9f1e886853370fbb3c35e4fdd7543440991f Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Fri, 9 Oct 2020 22:47:10 +0800 Subject: [PATCH] refactor wechat sender --- src/modules/rdb/cron/sender_im.go | 14 +++++++++----- src/modules/rdb/{corp/corp.go => wechat/wechat.go} | 6 +++--- 2 files changed, 12 insertions(+), 8 deletions(-) rename src/modules/rdb/{corp/corp.go => wechat/wechat.go} (97%) diff --git a/src/modules/rdb/cron/sender_im.go b/src/modules/rdb/cron/sender_im.go index 1ad1bbbc..ad20b6d8 100644 --- a/src/modules/rdb/cron/sender_im.go +++ b/src/modules/rdb/cron/sender_im.go @@ -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 { diff --git a/src/modules/rdb/corp/corp.go b/src/modules/rdb/wechat/wechat.go similarity index 97% rename from src/modules/rdb/corp/corp.go rename to src/modules/rdb/wechat/wechat.go index 57252de4..52fa034f 100644 --- a/src/modules/rdb/corp/corp.go +++ b/src/modules/rdb/wechat/wechat.go @@ -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 }