cmb
This commit is contained in:
parent
5928e407fe
commit
190d9fc065
|
|
@ -0,0 +1,7 @@
|
||||||
|
package mixrepos
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
type DingMixRepo interface {
|
||||||
|
SendMarkdownMessage(_ context.Context, text string) error
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,8 @@ package mixrepoimpl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"voucher/internal/biz/mixrepos"
|
||||||
"voucher/internal/conf"
|
"voucher/internal/conf"
|
||||||
"voucher/internal/pkg/ding"
|
"voucher/internal/pkg/ding"
|
||||||
)
|
)
|
||||||
|
|
@ -9,11 +11,25 @@ import (
|
||||||
type DingMixRepoImpl struct {
|
type DingMixRepoImpl struct {
|
||||||
bc *conf.Bootstrap
|
bc *conf.Bootstrap
|
||||||
|
|
||||||
d *ding.TalkClient
|
client *ding.TalkClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DingMixRepoImpl) Send(ctx context.Context, title, text string) error {
|
func NewDingMixRepoImpl(bc *conf.Bootstrap) mixrepos.DingMixRepo {
|
||||||
|
client := ding.NewDingTalkClient(bc.Alarm.WebhookURL, bc.Alarm.Secret)
|
||||||
|
|
||||||
|
return &DingMixRepoImpl{bc: bc, client: client}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DingMixRepoImpl) SendMarkdownMessage(_ context.Context, text string) error {
|
||||||
|
|
||||||
|
isAtAll := false
|
||||||
|
if len(s.bc.Alarm.AtMobiles) == 0 {
|
||||||
|
isAtAll = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := s.client.SendMarkdownMessage("xx", text, s.bc.Alarm.AtMobiles, isAtAll); err != nil {
|
||||||
|
return fmt.Errorf("Markdown 消息发送失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ func (c *TalkClient) SendLinkMessage(title, text, messageURL, picURL string, atM
|
||||||
func (c *TalkClient) SendMarkdownMessage(title, text string, atMobiles []string, isAtAll bool) error {
|
func (c *TalkClient) SendMarkdownMessage(title, text string, atMobiles []string, isAtAll bool) error {
|
||||||
var atStr string
|
var atStr string
|
||||||
for _, mobile := range atMobiles {
|
for _, mobile := range atMobiles {
|
||||||
atStr += fmt.Sprintf(" @%s", mobile)
|
atStr += fmt.Sprintf("<font color='#FFA500'>@%s</font>", mobile)
|
||||||
}
|
}
|
||||||
text += atStr
|
text += atStr
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue