100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 通过Webhook接入钉钉群自定义机器人

通过Webhook接入钉钉群自定义机器人

时间:2020-11-09 04:54:30

相关推荐

通过Webhook接入钉钉群自定义机器人

在钉钉群中添加Webhook自定义机器人,

复制Webhook地址保存:

/robot/send?access_token=xxxxxx

安全设置:选择加签方式,复制加签保存

#!/usr/bin/python# -*- coding: utf-8 -*-import requestsimport jsonimport timeimport hmacimport hashlibimport base64import urllib.parsetimestamp = str(round(time.time() * 1000))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))print(timestamp)print(sign)headers = {'Content-Type': 'application/json;charset=utf-8'}api_url = '/robot/send?access_token=xxxxx&timestamp=' + timestamp + "&sign=" + signdef msg(text):json_text= {"msgtype": "text","at": {"atMobiles": ["135xxxxxxx"],"isAtAll": False},"text": {"content": text}}print (requests.post(api_url,json.dumps(json_text),headers=headers).content)if __name__ == '__main__':text = "我就是我, 是不一样的烟火"msg(text)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。