Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
nizhengjia888
gin-vue-admin
提交
90414970
G
gin-vue-admin
项目概览
nizhengjia888
/
gin-vue-admin
与 Fork 源项目一致
Fork自
FLIPPED-AURORA / gin-vue-admin
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
90414970
编写于
8月 28, 2021
作者:
Mr.奇淼(
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
插件优化
上级
1ae17fb3
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
88 addition
and
48 deletion
+88
-48
server/initialize/plugin.go
server/initialize/plugin.go
+7
-0
server/initialize/router.go
server/initialize/router.go
+0
-25
server/plugin/notify/README.MD
server/plugin/notify/README.MD
+34
-7
server/plugin/notify/api/api.go
server/plugin/notify/api/api.go
+3
-2
server/plugin/notify/config/dingding.go
server/plugin/notify/config/dingding.go
+1
-1
server/plugin/notify/global/global.go
server/plugin/notify/global/global.go
+1
-5
server/plugin/notify/main.go
server/plugin/notify/main.go
+5
-1
server/plugin/notify/router/router.go
server/plugin/notify/router/router.go
+2
-2
server/plugin/notify/service/notify.go
server/plugin/notify/service/notify.go
+35
-5
未找到文件。
server/initialize/plugin.go
浏览文件 @
90414970
...
...
@@ -2,6 +2,7 @@ package initialize
import
(
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/plugin/notify"
//email "github.com/flipped-aurora/gva-plug-email" // 在线仓库模式
"github.com/flipped-aurora/gin-vue-admin/server/plugin/email"
// 本地插件仓库地址模式
"github.com/flipped-aurora/gin-vue-admin/server/plugin/example_plugin"
...
...
@@ -30,4 +31,10 @@ func InstallPlugin(PublicGroup *gin.RouterGroup, PrivateGroup *gin.RouterGroup)
global
.
GVA_CONFIG
.
Email
.
Port
,
global
.
GVA_CONFIG
.
Email
.
IsSSL
,
))
// 钉钉通知,暂时开放权限
PluginInit
(
PublicGroup
,
notify
.
CreateDDPlug
(
"https://oapi.dingtalk.com/robot/send"
,
"8ded23f91917dc4f6275f44ba5ef243e6ed1d2cc74de83f01a6f5f5f39905671"
,
"SECaecf452bd6e671ab0d47469c3ad933e32fcc47b335333049a1b8961606192f38"
))
}
server/initialize/router.go
浏览文件 @
90414970
package
initialize
import
(
//email "github.com/flipped-aurora/gva-plug-email" // 在线仓库模式
"github.com/flipped-aurora/gin-vue-admin/server/plugin/email"
// 本地插件仓库地址模式
"github.com/flipped-aurora/gin-vue-admin/server/plugin/example_plugin"
"github.com/flipped-aurora/gin-vue-admin/server/plugin/notify"
"net/http"
_
"github.com/flipped-aurora/gin-vue-admin/server/docs"
...
...
@@ -64,27 +58,8 @@ func Routers() *gin.Engine {
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
}
// 添加开放权限的插件 示例
PluginInit
(
PublicGroup
,
example_plugin
.
ExamplePlugin
)
// 钉钉通知,暂时开放权限
PluginInit
(
PublicGroup
,
notify
.
CreateDDPlug
())
// 添加跟角色挂钩权限的插件 示例 本地示例模式于在线仓库模式注意上方的import 可以自行切换 效果相同
PluginInit
(
PrivateGroup
,
email
.
CreateEmailPlug
(
global
.
GVA_CONFIG
.
Email
.
To
,
global
.
GVA_CONFIG
.
Email
.
From
,
global
.
GVA_CONFIG
.
Email
.
Host
,
global
.
GVA_CONFIG
.
Email
.
Secret
,
global
.
GVA_CONFIG
.
Email
.
Nickname
,
global
.
GVA_CONFIG
.
Email
.
Port
,
global
.
GVA_CONFIG
.
Email
.
IsSSL
,
))
InstallPlugin
(
PublicGroup
,
PrivateGroup
)
// 安装插件
global
.
GVA_LOG
.
Info
(
"router register success"
)
return
Router
}
server/plugin/notify/README.MD
浏览文件 @
90414970
...
...
@@ -14,18 +14,45 @@
在
`plugin/notify/global/global.go`
文件中配置钉钉通知的URL ,Token 等
```
go
var
GlobalConfig_
=
&
config
.
DingDing
{
Url
:
"https://oapi.dingtalk.com/robot/send"
,
Token
:
"xxx"
,
Secret
:
"xxx"
,
// 在gin-vue-admin 主程序的initialize中的plugin的InstallPlugin 函数中写入如下代码
PluginInit
(
PublicGroup
,
notify
.
CreateDDPlug
(
URL
,
Token
,
密钥
))
}
```
### 3. 使用说明
### 3方法API
```
go
可调用方法
//content 发送的内容
//atMobiles 需要艾特的人的手机号
//isAtAll 是否艾特全体
SendTextMessage
(
content
string
,
atMobiles
[]
string
,
isAtAll
bool
)
//content 发送的内容
//title 内容标题
//picUrl 配图
//messageUrl 点击跳转路径
//atMobiles 需要艾特的人的手机号
//isAtAll 是否艾特全体
SendLinkMessage
(
content
,
title
,
picUrl
,
messageUrl
string
)
//content 发送的内容(markdown语法)
//title 内容标题
//atMobiles 需要艾特的人的手机号
//isAtAll 是否艾特全体
SendMarkdownMessage
(
content
,
title
string
,
atMobiles
[]
string
,
isAtAll
bool
)
```
### 4. 使用示例
在代码中调用
`SendTextMessage`
方法即可
```
go
// 示例
func
NotifyController
(
c
*
gin
.
Context
)
{
if
err
:=
service
.
ServiceGroupApp
.
SendTextMessage
(
"test"
);
err
!=
nil
{
if
err
:=
service
.
ServiceGroupApp
.
SendTextMessage
(
"test"
,[]
string
{
"手机号"
},
是否艾特全体
);
err
!=
nil
{
global
.
GVA_LOG
.
Error
(
"发送失败!"
,
zap
.
Any
(
"err"
,
err
))
response
.
FailWithMessage
(
"发送失败"
,
c
)
}
else
{
...
...
@@ -34,5 +61,5 @@ func NotifyController(c *gin.Context) {
}
```
### 方法API
server/plugin/notify/api/api.go
浏览文件 @
90414970
...
...
@@ -11,8 +11,9 @@ import (
type
Api
struct
{
}
func
(
s
*
Api
)
NotifyController
(
c
*
gin
.
Context
)
{
if
err
:=
service
.
ServiceGroupApp
.
SendTextMessage
(
"test"
);
err
!=
nil
{
//
func
(
s
*
Api
)
SendTextMessage
(
c
*
gin
.
Context
)
{
if
err
:=
service
.
ServiceGroupApp
.
SendTextMessage
(
"notify"
,
[]
string
{},
false
);
err
!=
nil
{
global
.
GVA_LOG
.
Error
(
"发送失败!"
,
zap
.
Any
(
"err"
,
err
))
response
.
FailWithMessage
(
"发送失败"
,
c
)
}
else
{
...
...
server/plugin/notify/config/dingding.go
浏览文件 @
90414970
...
...
@@ -2,6 +2,6 @@ package config
type
DingDing
struct
{
Url
string
`mapstructure:"url" json:"url" yaml:"url"`
// Url
Token
string
`mapstructure:"token" json:"token" yaml:"token"`
//
T
oken
Token
string
`mapstructure:"token" json:"token" yaml:"token"`
//
access_t
oken
Secret
string
`mapstructure:"secret" json:"secret" yaml:"secret"`
// 密钥
}
server/plugin/notify/global/global.go
浏览文件 @
90414970
...
...
@@ -2,8 +2,4 @@ package global
import
"github.com/flipped-aurora/gin-vue-admin/server/plugin/notify/config"
var
GlobalConfig_
=
&
config
.
DingDing
{
Url
:
"https://oapi.dingtalk.com/robot/send"
,
Token
:
"77d18293e221b3b7bdae7330d19a213c3cbb20fa07de5f4c273c0363ae475c34"
,
Secret
:
"SEC38425b7bd57c6bca9ce20611c41b437994ed65e0ddbd42e840ffa7a8c7da2106"
,
}
var
GlobalConfig_
=
&
config
.
DingDing
{}
server/plugin/notify/main.go
浏览文件 @
90414970
package
notify
import
(
"github.com/flipped-aurora/gin-vue-admin/server/plugin/notify/global"
"github.com/flipped-aurora/gin-vue-admin/server/plugin/notify/router"
"github.com/gin-gonic/gin"
)
...
...
@@ -11,7 +12,10 @@ type ddPlugin struct {
Url
string
}
func
CreateDDPlug
()
*
ddPlugin
{
func
CreateDDPlug
(
url
,
Token
,
Secret
string
)
*
ddPlugin
{
global
.
GlobalConfig_
.
Url
=
url
global
.
GlobalConfig_
.
Token
=
Token
global
.
GlobalConfig_
.
Secret
=
Secret
return
&
ddPlugin
{}
}
...
...
server/plugin/notify/router/router.go
浏览文件 @
90414970
...
...
@@ -11,8 +11,8 @@ type NotifyRouter struct {
func
(
s
*
NotifyRouter
)
InitRouter
(
Router
*
gin
.
RouterGroup
)
{
router
:=
Router
.
Use
(
middleware
.
OperationRecord
())
var
Controller
=
api
.
ApiGroupApp
.
Api
.
NotifyController
var
SendTextMessage
=
api
.
ApiGroupApp
.
Api
.
SendTextMessage
{
router
.
POST
(
"
dingding"
,
Controller
)
router
.
POST
(
"
sendTextMessage"
,
SendTextMessage
)
}
}
server/plugin/notify/service/notify.go
浏览文件 @
90414970
...
...
@@ -22,20 +22,50 @@ type NotifyService struct {
//@description: 钉钉通知测试
//@return: err error
func
(
e
*
NotifyService
)
SendTextMessage
(
content
string
)
(
err
error
)
{
func
(
e
*
NotifyService
)
SendTextMessage
(
content
string
,
atMobiles
[]
string
,
isAtAll
bool
)
(
err
error
)
{
msg
:=
map
[
string
]
interface
{}{
"msgtype"
:
"text"
,
"text"
:
map
[
string
]
string
{
"content"
:
content
,
},
//"at": map[string]interface{}{
// "atMobiles": atMobiles,
// "isAtAll": isAtAll,
//},
"at"
:
map
[
string
]
interface
{}{
"atMobiles"
:
atMobiles
,
"isAtAll"
:
isAtAll
,
},
}
return
SendMessage
(
msg
)
}
func
(
e
*
NotifyService
)
SendLinkMessage
(
content
,
title
,
picUrl
,
messageUrl
string
)
(
err
error
)
{
msg
:=
map
[
string
]
interface
{}{
"msgtype"
:
"link"
,
"link"
:
map
[
string
]
string
{
"text"
:
content
,
"title"
:
title
,
"picUrl"
:
picUrl
,
"messageUrl"
:
messageUrl
,
},
}
return
SendMessage
(
msg
)
}
func
(
e
*
NotifyService
)
SendMarkdownMessage
(
content
,
title
string
,
atMobiles
[]
string
,
isAtAll
bool
)
(
err
error
)
{
msg
:=
map
[
string
]
interface
{}{
"msgtype"
:
"markdown"
,
"markdown"
:
map
[
string
]
string
{
"text"
:
content
,
"title"
:
title
,
},
"at"
:
map
[
string
]
interface
{}{
"atMobiles"
:
atMobiles
,
"isAtAll"
:
isAtAll
,
},
}
return
SendMessage
(
msg
)
}
// 其余方法请参考 https://developers.dingtalk.com/document/robots/custom-robot-access?spm=ding_open_doc.document.0.0.7f8710afbfzduV#topic-2026027
func
SendMessage
(
msg
interface
{})
error
{
body
:=
bytes
.
NewBuffer
(
nil
)
err
:=
json
.
NewEncoder
(
body
)
.
Encode
(
msg
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录