#!/usr/bin/python3 #-*-coding: utf-8-*- # by QianFeng.newrain # ''' Welcome QianFeng cloud computing ''' import requests import json import sys import time,hmac,base64,hashlib,urllib.parse headers = {'Content-Type': 'application/json;charset=utf-8'} # 需要修改,钉钉群助手中获取 timestamp = str(round(time.time() * 1000)) secret = 'SECf3aa0ec68151d6a0599d8d9db4fa40afa5341c358d5' 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)) api_url = f"https://oapi.dingtalk.com/robot/send?access_token=abdec0db67d1ca355b547711f822e0bb60929295cd3c42c1e4c89c7f24b4872e×tamp={timestamp}&sign={sign}" def msg(text): json_text= { "msgtype": "text", "at": { "atMobiles": [ "all" ], "isAtAll": False }, "text": { "content": text } } print(requests.post(api_url,json.dumps(json_text),headers=headers).content.decode()) msg('\n'+sys.argv[1])