瀏覽代碼

docs(): update readme

Espoir 3 年之前
父節點
當前提交
b88fb9841f
共有 3 個文件被更改,包括 22 次插入20 次删除
  1. 15 5
      server/plugin/notify/README.MD
  2. 1 1
      server/plugin/notify/api/api.go
  3. 6 14
      server/plugin/notify/service/notify.go

+ 15 - 5
server/plugin/notify/README.MD

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

+ 1 - 1
server/plugin/notify/api/api.go

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

+ 6 - 14
server/plugin/notify/service/notify.go

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