Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-common
Commits
9c815741
Commit
9c815741
authored
Feb 09, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create dingding.go
parent
316b492c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
0 deletions
+63
-0
dingding.go
sdk/dingding/dingding.go
+63
-0
No files found.
sdk/dingding/dingding.go
0 → 100644
View file @
9c815741
package
dingding
import
(
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
var
(
ROBOTWEBHOOK
=
"https://oapi.dingtalk.com/robot/send?access_token=5207fd753d28661ea0716ea0ef5b9e9e0aea392c9a148307c0b186e3d09b4aec"
HILO
=
"hilo:"
)
type
dingResponse
struct
{
Errcode
int
Errmsg
string
}
type
dingtextMessage
struct
{
MsgType
string
`json:"msgtype"`
Text
dingtextParams
`json:"text"`
At
dingdingAt
`json:"at"`
}
type
dingtextParams
struct
{
Content
string
`json:"content"`
}
// At at struct
type
dingdingAt
struct
{
AtMobiles
[]
string
`json:"atMobiles"`
IsAtAll
bool
`json:"isAtAll"`
}
func
SendDingRobot
(
url
string
,
content
string
,
isAtAll
bool
)
error
{
msg
:=
dingtextMessage
{
MsgType
:
"text"
,
Text
:
dingtextParams
{
Content
:
HILO
+
content
},
At
:
dingdingAt
{
IsAtAll
:
isAtAll
}}
m
,
err
:=
json
.
Marshal
(
msg
)
if
err
!=
nil
{
return
err
}
resp
,
err
:=
http
.
Post
(
url
,
"application/json"
,
bytes
.
NewReader
(
m
))
if
err
!=
nil
{
return
err
}
defer
resp
.
Body
.
Close
()
data
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
return
err
}
var
dr
dingResponse
err
=
json
.
Unmarshal
(
data
,
&
dr
)
if
err
!=
nil
{
return
err
}
if
dr
.
Errcode
!=
0
{
return
fmt
.
Errorf
(
"dingrobot send failed: %v"
,
dr
.
Errmsg
)
}
return
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment