Commit 8ace3765 authored by yz's avatar yz

测试群的钉钉机器人提醒

parents
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+"&timestamp="+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)
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