Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
InterfaceAutoTest
Overview
Overview
Details
Activity
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TestAuto
InterfaceAutoTest
Commits
a418e740
Commit
a418e740
authored
May 16, 2021
by
taoke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加发送钉钉消息
parent
ad6e1ae0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
5 deletions
+69
-5
common/utils/dingTalk.py
+65
-3
run.py
+4
-2
No files found.
common/utils/dingTalk.py
View file @
a418e740
import
requests
import
requests
,
time
,
hmac
,
hashlib
,
base64
,
urllib
.
parse
,
json
import
json
from
config
import
BaseConfig
from
config
import
BaseConfig
def
dingTalk
(
webhook
,
message
):
def
get_sign
(
secret
):
timestamp
=
str
(
round
(
time
.
time
()
*
1000
))
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
def
dingTalk
(
secret
,
webhook
,
message
):
"""发送消息到钉钉群"""
"""发送消息到钉钉群"""
timestamp
=
str
(
round
(
time
.
time
()
*
1000
))
sign
=
get_sign
(
secret
)
webhook
=
webhook
+
f
"×tamp={timestamp}&sign={sign}"
data
=
{
'msgtype'
:
'text'
,
'text'
:
{
"content"
:
message
},
data
=
{
'msgtype'
:
'text'
,
'text'
:
{
"content"
:
message
},
'at'
:
{
'isAtAll'
:
True
}}
'at'
:
{
'isAtAll'
:
True
}}
post_data
=
json
.
dumps
(
data
)
post_data
=
json
.
dumps
(
data
)
response
=
requests
.
post
(
webhook
,
headers
=
BaseConfig
.
headers
,
data
=
post_data
)
response
=
requests
.
post
(
webhook
,
headers
=
BaseConfig
.
headers
,
data
=
post_data
)
return
response
.
text
return
response
.
text
def
dingTalk_link
(
secret
,
webhook
,
message
):
"""发送消息到钉钉群"""
timestamp
=
str
(
round
(
time
.
time
()
*
1000
))
sign
=
get_sign
(
secret
)
webhook
=
webhook
+
f
"×tamp={timestamp}&sign={sign}"
data
=
{
'msgtype'
:
'link'
,
"link"
:
{
"text"
:
"这个即将发布的新版本,创始人xx称它为红树林。而在此之前,每当面临重大升级,产品经理们都会取一个应景的代号,这一次,为什么是红树林"
,
"title"
:
"Dinding发送消息接口文档"
,
"picUrl"
:
"https://aqjg.gyszhjt.com:60028/img/group1/M00/00/03/Cgs5XWCf8QiAeR3KAAA1uImt-QE934.jpg"
,
"messageUrl"
:
"https://developers.dingtalk.com/document/app/custom-robot-access"
},
'at'
:
{
'isAtAll'
:
True
}}
post_data
=
json
.
dumps
(
data
)
response
=
requests
.
post
(
webhook
,
headers
=
BaseConfig
.
headers
,
data
=
post_data
)
return
response
.
text
def
dingTalk_markdown
(
secret
,
webhook
,
message
):
"""发送消息到钉钉群"""
timestamp
=
str
(
round
(
time
.
time
()
*
1000
))
sign
=
get_sign
(
secret
)
webhook
=
webhook
+
f
"×tamp={timestamp}&sign={sign}"
data
=
{
'msgtype'
:
'markdown'
,
"markdown"
:
{
"title"
:
"接口执行报告"
,
"text"
:
"#### 接口自动化测试报告
\n
> 本消息由Jenkins构建后自动发送
\n
>
\

\n
> ###### 10点20分发布 [斑马信用](http://10.197.236.10:8080/job/bmc/)
\n
"
},
'at'
:
{
'isAtAll'
:
False
}}
post_data
=
json
.
dumps
(
data
)
response
=
requests
.
post
(
webhook
,
headers
=
BaseConfig
.
headers
,
data
=
post_data
)
return
response
.
text
if
__name__
==
'__main__'
:
res
=
dingTalk_markdown
(
secret
=
"SEC1d08f46da74337cc0e1cd5bb9ad19622d825483343fdfa43ce396881e4745bdb"
,
webhook
=
"https://oapi.dingtalk.com/robot/send?access_token=f9e005c1a984b9607960345d38669337b1115d1141a0294e98666443b312115b"
,
message
=
"我就是我, @XXX 是不一样的烟火"
)
print
(
res
)
# 自动化测试组 - 技术和思路分享 - ----小帅
# SEC40a1be4bbd9214e16ba288208fd608b2b590e82e853fa9b24c1850a506c6185b
# https: // oapi.dingtalk.com / robot / send?access_token = e830b05eeee88da31972099e403a74d05ec55719360707dc44e532c0d0b49cb6
\ No newline at end of file
run.py
View file @
a418e740
...
@@ -4,6 +4,7 @@ import pytest
...
@@ -4,6 +4,7 @@ import pytest
import
argparse
import
argparse
from
config
import
BaseConfig
from
config
import
BaseConfig
from
common.tools
import
get_case_dir
from
common.tools
import
get_case_dir
from
common.utils
import
dingTalk
def
get_parser
():
def
get_parser
():
...
@@ -27,6 +28,7 @@ if __name__ == "__main__":
...
@@ -27,6 +28,7 @@ if __name__ == "__main__":
# 生成报告数据
# 生成报告数据
pytest
.
main
([
'-v'
,
'-s'
,
test_case_dir
,
'--alluredir'
,
'./report/tmp'
])
pytest
.
main
([
'-v'
,
'-s'
,
test_case_dir
,
'--alluredir'
,
'./report/tmp'
])
# 打开报告
# 打开报告
os
.
system
(
'allure serve ./report/tmp'
)
# os.system('allure serve ./report/tmp')
dingTalk
.
dingTalk_markdown
(
secret
=
"SEC1d08f46da74337cc0e1cd5bb9ad19622d825483343fdfa43ce396881e4745bdb"
,
webhook
=
"https://oapi.dingtalk.com/robot/send?access_token=f9e005c1a984b9607960345d38669337b1115d1141a0294e98666443b312115b"
,)
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