提交 b88fb984 编写于 作者: Espoir__'s avatar Espoir__

docs(): update readme

上级 83db3eeb
......@@ -2,15 +2,12 @@
本插件用于向钉钉群推送消息
### 使用步骤
#### 1. 使用说明
### 1. 使用场景
- 当服务运行异常时,可以向钉钉推送异常信息,便于及时发现解决问题
- 推送一些关键业务的运行日志等
#### 2. 配置说明
### 2. 配置说明
钉钉 token 等相关信息的获取,请参考 [钉钉官网](https://developers.dingtalk.com/document/robots/custom-robot-access?spm=ding_open_doc.document.0.0.7f8710afbfzduV#topic-2026027)
......@@ -23,6 +20,19 @@ var GlobalConfig_ = &config.DingDing{
Secret: "xxx",
}
```
### 3. 使用说明
在代码中调用 `SendTextMessage` 方法即可
```go
func NotifyController(c *gin.Context) {
if err := service.ServiceGroupApp.SendTextMessage("test"); err != nil {
global.GVA_LOG.Error("发送失败!", zap.Any("err", err))
response.FailWithMessage("发送失败", c)
} else {
response.OkWithData("发送成功", c)
}
}
```
### 方法API
......@@ -12,7 +12,7 @@ type Api struct {
}
func (s *Api) NotifyController(c *gin.Context) {
if err := service.ServiceGroupApp.Send(); err != nil {
if err := service.ServiceGroupApp.SendTextMessage("test"); err != nil {
global.GVA_LOG.Error("发送失败!", zap.Any("err", err))
response.FailWithMessage("发送失败", c)
} else {
......
......@@ -17,7 +17,12 @@ import (
type NotifyService struct {
}
func SendTextMessage(content string) error {
//@author: [Espoir](https://github.com/nightsimon)
//@function: NotifyController
//@description: 钉钉通知测试
//@return: err error
func (e *NotifyService) SendTextMessage(content string) error {
msg := map[string]interface{}{
"msgtype": "text",
"text": map[string]string{
......@@ -99,16 +104,3 @@ func sign(t int64, secret string) string {
data := hmac256.Sum(nil)
return base64.StdEncoding.EncodeToString(data)
}
//@author: [Espoir](https://github.com/nightsimon)
//@function: NotifyController
//@description: 钉钉通知测试
//@return: err error
func (e *NotifyService) Send() (err error) {
err = SendTextMessage("test")
if err != nil {
return err
}
return err
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册