Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
钉
钉钉群通知
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
yaozheng
钉钉群通知
Commits
8ace3765
Commit
8ace3765
authored
Oct 30, 2020
by
yz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
测试群的钉钉机器人提醒
parents
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
+62
-0
sendMessage.py
sendMessage.py
+62
-0
No files found.
sendMessage.py
0 → 100644
View file @
8ace3765
import
requests
import
time
import
hmac
import
hashlib
import
base64
import
urllib.parse
import
json
# http://gitlab2.dui88.com/yaozheng/dingdingMessage.git
# https://oapi.dingtalk.com/robot/send?access_token=fb8da62f0af606820fe8bdfdf8ea261d468f09b57c22faaa454d45855ea82eef
# SECf2cc843306d667575a491650c777d8aa21788c4c60f3f0949d5d0b61c86e5aef
class
DDMessage
:
# 获得签名
@
classmethod
def
get_sign
(
cls
,
timestamp
,
secret
):
secret_enc
=
secret
.
encode
(
'utf-8'
)
string_to_sign
=
'{}
\n
{}'
.
format
(
timestamp
,
secret
)
string_to_sign_enc
=
string_to_sign
.
encode
(
'utf-8'
)
hmac_code
=
hmac
.
new
(
secret_enc
,
string_to_sign_enc
,
digestmod
=
hashlib
.
sha256
)
.
digest
()
sign
=
urllib
.
parse
.
quote_plus
(
base64
.
b64encode
(
hmac_code
))
return
sign
# 发送消息
@
classmethod
def
send_message
(
cls
,
url
,
message
):
headers
=
{
'Content-Type'
:
'application/json'
,
'charset'
:
'utf-8'
}
message
=
{
"msgtype"
:
"text"
,
"text"
:
{
"content"
:
message
},
"isAtAll"
:
True
}
r
=
requests
.
post
(
url
=
url
,
data
=
json
.
dumps
(
message
),
headers
=
headers
)
.
json
()
print
(
r
)
# 机器人提醒地址
dingTalkUrl
=
"https://oapi.dingtalk.com/robot/send?access_token=fb8da62f0af606820fe8bdfdf8ea261d468f09b57c22faaa454d45855ea82eef"
# 密钥,签名算法需要
secret
=
'SECf2cc843306d667575a491650c777d8aa21788c4c60f3f0949d5d0b61c86e5aef'
# 获取时间戳,签名算法需要,并且需要和签名一起拼到链接后面
timestamp
=
str
(
round
(
time
.
time
()
*
1000
))
# 获取签名
sign
=
DDMessage
.
get_sign
(
timestamp
,
secret
)
# 拼接完整的url,用于鉴权
fullUrl
=
dingTalkUrl
+
"×tamp="
+
timestamp
+
"&sign="
+
sign
# 获取要发送的信息
content1
=
"请及时上传测试用例:http://cf.dui88.com/pages/viewpage.action?pageId=67163149"
content2
=
"bug请及时上报jira并更新状态:http://jira.dui88.com"
content3
=
"业务文档请及时更新:http://cf.dui88.com/pages/viewpage.action?pageId=78912619"
# 发送信息
DDMessage
.
send_message
(
fullUrl
,
content1
)
DDMessage
.
send_message
(
fullUrl
,
content2
)
DDMessage
.
send_message
(
fullUrl
,
content3
)
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