Commit 688d6309 authored by yaozheng's avatar yaozheng

增加流量线测试群提醒

parent 08f57a00
import os
import sys
# 把项目的根目录通过sys.path.append添加为执行时的环境变量
current_directory = os.path.dirname(os.path.abspath(__file__))
root_path = os.path.abspath(os.path.dirname(current_directory) + os.path.sep + ".")
sys.path.append(root_path)
from robot.task import Task
# Task.liuliang_everyday1()
Task.ceshi()
import base64
import hashlib
import hmac
import urllib
def get_sign(timestamp, secret):
"""
获取签名
:param secret: 密钥
:return:
"""
# 密钥进行编码
secret_enc = secret.encode('utf-8')
# 把timestamp+"\n"+密钥当做签名字符串
string_to_sign = '{}\n{}'.format(timestamp, secret)
# 对签名进行编码
string_to_sign_enc = string_to_sign.encode('utf-8')
# 使用HmacSHA256算法计算签名,然后进行Base64 encode
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
import json
import time
import requests
from robot import encode
class Remind:
webhook = 'https://oapi.dingtalk.com/robot/send?access_token='
headers = {"Content-Type": "application/json; charset=utf-8"}
@classmethod
def send_messages(cls, token, secret, content, at):
"""
发送钉钉消息,text类型
:param token: 对应机器人的token
:param secret: 密钥
:param content:需要发送的内容,文本
:param at:需要at的用户,字典类型。atMobiles里面存放被@人的手机号,列表存放。isAtAll表示是否at所有人
:return:返回调用钉钉的结果
"""
data_info = {
"msgtype": "text",
"text": {
"content": content
},
"at": at
}
# 发送消息
return cls.send(token, secret, data_info)
@classmethod
def send_markdown(cls, token, secret, title, text, at):
"""
发送钉钉消息,markdown类型
:param token: 对应机器人的token
:param secret: 密钥
:param title:首屏会话透出的展示内容
:param text:markdown格式的消息内容,目前只支持markdown语法的子集
:param at:需要at的用户,字典类型。atMobiles里面存放被@人的手机号。isAtAll表示是否at所有人
:return: 返回调用钉钉的结果
"""
data_info = {
"msgtype": "markdown",
"markdown": {
"title": title,
"text": text
},
"at": at
}
# 发送消息
return cls.send(token, secret, data_info)
@classmethod
def send_actionCard(cls, token, secret, title, text, singleTitle, singleURL):
"""
发送钉钉消息,整体跳转actionCard类型
:param token: 对应机器人的token
:param secret: 密钥
:param title:首屏会话透出的展示内容
:param text:markdown格式的消息内容
:param singleTitle:单个按钮的标题
:param singleURL:单个按钮的跳转链接
:return:返回调用钉钉的结果
"""
data_info = {
"msgtype": "actionCard",
"actionCard": {
"title": title,
"text": text,
"singleTitle": singleTitle,
"singleURL": singleURL
}
}
# 发送消息
return cls.send(token, secret, data_info)
@classmethod
def send_alone_actionCard(cls, token, secret, title, text, btnOrientation, btns):
"""
发送钉钉消息,独立跳转actionCard类型
:param token: 对应机器人的token
:param secret: 密钥
:param title:首屏会话透出的展示内容
:param text:markdown格式的消息内容
:param btnOrientation:按钮排序方式,0:按钮竖直排列,1:按钮横向排列
:param btns:按钮,列表格式,列表中每个元素是一个按钮字典,包含title和actionURL
如:[
{
"title": "内容不错",
"actionURL": "https://www.dingtalk.com/"
},
{
"title": "不感兴趣",
"actionURL": "https://www.dingtalk.com/"
}
]
:return:返回调用钉钉的结果
"""
data_info = {
"msgtype": "actionCard",
"actionCard": {
"title": title,
"text": text,
"hideAvatar": "0",
"btnOrientation": btnOrientation,
"btns": btns
}
}
# 发送消息
return cls.send(token, secret, data_info)
@classmethod
def send_feedCard(cls, token, secret, links):
"""
发送钉钉消息,feedCard类型
:param token: 对应机器人的token
:param secret: 密钥
:param links: 链接,列表类型,里面组装了所有的链接,而每个链接是一个字典,包含title:单条信息文本、messageURL:单条信息跳转链接、picURL:单条信息后面图片的URL
如:[
{
"title": "时代的火车向前开1",
"messageURL": "https://www.dingtalk.com/",
"picURL": "https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png"
},
{
"title": "时代的火车向前开2",
"messageURL": "https://www.dingtalk.com/",
"picURL": "https://img.alicdn.com/tfs/TB1NwmBEL9TBuNjy1zbXXXpepXa-2400-1218.png"
}
]
:return:
"""
data_info = {
"msgtype": "feedCard",
"feedCard": {
"links": links
}
}
# 发送消息
return cls.send(token, secret, data_info)
@classmethod
def send(cls, token,secret, data_info):
# 获取时间戳
timestamp = str(round(time.time() * 1000))
sign = encode.get_sign(timestamp, secret)
# 拼接完整的url,用于鉴权
fullUrl = cls.webhook+token + "&timestamp=" + timestamp + "&sign=" + sign
print(fullUrl)
# 发送钉钉消息
return requests.post(url=fullUrl, data=json.dumps(data_info), headers=cls.headers).json()
from robot.remind import Remind
import datetime
import calendar
class Task:
@classmethod
def liuliang_everyday(cls):
token = '903ab8b3ba3d46e7c8b934ef83038bd6037e56c04a985e43fab8f2e0bd359cad'
secret = 'SEC7e57fbdd5b20103208482f520420139072d84c754a3cd624641623bd2f225af3'
text = '***今天排查的线上问题记录了吗?\n\n\r 测试用例上传了吗?\n\n\r 提测bug都提交了吗?\n\n\r 今天上线的需求都线上回归了吗?\n\n\r 业务文档都更新了吗?***'
btns = [{
"title": "线上问题记录",
"actionURL": "http://cf.dui88.com/pages/viewpage.action?pageId=97986428"
},
{
"title": "测试用例上传",
"actionURL": "http://cf.dui88.com/pages/viewpage.action?pageId=67163062"
},
{
"title": "提测bug提交并更新状态",
"actionURL": "http://jira.dui88.com"
},
{
"title": "业务文档更新",
"actionURL": "http://cf.dui88.com/pages/viewpage.action?pageId=78912619"
}
]
Remind.send_alone_actionCard(token=token, secret=secret, title='下班前想一想', text=text, btnOrientation='1', btns=btns)
@classmethod
def liuliang_everyday1(cls):
token = '903ab8b3ba3d46e7c8b934ef83038bd6037e56c04a985e43fab8f2e0bd359cad'
secret = 'SEC7e57fbdd5b20103208482f520420139072d84c754a3cd624641623bd2f225af3'
text = '# 下班前先想一想 ' \
'\n> ***今天排查的线上问题记录了吗?*** [去记录](http://cf.dui88.com/pages/viewpage.action?pageId=97986428) ' \
'\n> ***测试用例上传了吗?*** [去上传](http://cf.dui88.com/pages/viewpage.action?pageId=67163062) ' \
'\n> ***提测bug都提交了吗?*** [去提交](http://jira.dui88.com) ' \
'\n> ***业务文档都更新了吗?*** [去更新](http://cf.dui88.com/pages/viewpage.action?pageId=78912619)'
text = text + ' \n> ***今天上线的需求都线上回归了吗?***'
text = text + ' \n> ***测试周报都写了吗?*** [去写周报](http://cf.dui88.com/pages/viewpage.action?pageId=92507929)'
at = {'atMobiles': ['15726940779'], 'isAtAll': False}
Remind.send_markdown(token=token, secret=secret, title='下班前想一想', text=text, at=at)
@classmethod
def ceshi(cls):
token = 'fb8da62f0af606820fe8bdfdf8ea261d468f09b57c22faaa454d45855ea82eef'
secret = 'SECf2cc843306d667575a491650c777d8aa21788c4c60f3f0949d5d0b61c86e5aef'
text = '# 下班前先想一想 ' \
'\n> ***今天排查的线上问题记录了吗?*** [去记录](http://cf.dui88.com/pages/viewpage.action?pageId=97986428) ' \
'\n> ***测试用例上传了吗?*** [去上传](http://cf.dui88.com/pages/viewpage.action?pageId=67163062) ' \
'\n> ***提测bug都提交了吗?*** [去提交](http://jira.dui88.com) ' \
'\n> ***业务文档都更新了吗?*** [去更新](http://cf.dui88.com/pages/viewpage.action?pageId=78912619)'
at = {'isAtAll': True}
# 获取当天日期
currentdate = datetime.date.today()
currentday = calendar.weekday(currentdate.year, currentdate.month, currentdate.day)
if currentday == 1 or currentday == 3:
text = text + '\n> ***今天上线的需求都线上回归了吗?***'
if currentday == 4:
text = text + '\n> ***测试周报都写了吗?*** [去写周报](http://cf.dui88.com/pages/viewpage.action?pageId=92507929)'
Remind.send_markdown(token=token, secret=secret, title='下班前想一想', text=text, at=at)
\ No newline at end of file
import os
import sys
# 把项目的根目录通过sys.path.append添加为执行时的环境变量
current_directory = os.path.dirname(os.path.abspath(__file__))
root_path = os.path.abspath(os.path.dirname(current_directory) + os.path.sep + ".")
sys.path.append(root_path)
from servers.ddMessageServer import DDMessage
import time
# 机器人提醒地址,测试群
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+"&timestamp="+timestamp+"&sign="+sign
# 构造要发送的信息
title = ''
text = ''
content1 = "今天排查的线上问题记录了吗?测试用例上传了吗?:http://cf.dui88.com/pages/viewpage.action?pageId=67163149"
# 发送信息
# DDMessage.send_message(fullUrl,content1)
# DDMessage.send_message(fullUrl,content2)
# DDMessage.send_message(fullUrl,content3)
DDMessage.send_message(fullUrl,content1+'\n'+content3)
\ No newline at end of file
...@@ -31,4 +31,21 @@ class DDMessage: ...@@ -31,4 +31,21 @@ class DDMessage:
} }
r = requests.post(url=url,data=json.dumps(message),headers=headers).json() r = requests.post(url=url,data=json.dumps(message),headers=headers).json()
print(r) print(r)
\ No newline at end of file
# 发送消息
@classmethod
def send_actionCard(cls, url, title,text,btns):
headers = {'Content-Type': 'application/json', 'charset': 'utf-8'}
message = {
"msgtype": "actionCard",
"actionCard": {
"title": title,
"text": text,
"hideAvatar": "0",
"btnOrientation": "1",
"btns": btns
}
}
r = requests.post(url=url, data=json.dumps(message), headers=headers).json()
print(r)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment