• 钉钉机器人webhook的使用


    1、群启动webhook机器人:右上角设置--智能助手---添加机器人---其他机器人
    2、获取webhook地址
    0
    3、调用方式不一样,则访问方式就不一样
    --------------------------------------------方式一:加签-----------------------------------------------
    1、python加签名的调用方式
    pip install requests
    import requests
    import json
    import time
    import hmac
    import hashlib
    import base64
    import urllib.parse
    
    def send_text(countent_text):
        timestamp = str(round(time.time() * 1000))
        secret = 'SECc1495b626ab6ceb2415ee163ca3002cf2c77cbba82f6f3d55d9014c2ee58ed41'  #签名id
        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))
        url = f"https://oapi.dingtalk.com/robot/send?access_token=8684ad760333e6fbb8ec8c0c12e2c00fcf7e58e58eb5d0152d9cebb06dee&timestamp={timestamp}&sign={sign}"
        headers = {'Content-Type': 'application/json;charset=utf-8'}
        data = {
        "msgtype":"text",
        "at": {"atMobiles": ["18381001111"], #群中@的人员
             "isAtAll": False},
        "text": {"content": countent_text}, "msgtype": "text"}
        print(json.dumps(data))
        print(countent_text)
        requests.post(url, headers=headers, data=json.dumps(data))
    
    dx=f"-----------------------------sdfsdfsdf--------------------------------"
    send_text(dx)
    

     

    --------------------------------------------方式二:自定义关键词---------------------------------------------
    1、自定义关键词test
    import requests
    import json
    
    def send_text(countent_text):
        url = f"https://oapi.dingtalk.com/robot/send?access_token=8684ad760333e6fbb8ec8c0c12e2c00fcf7e58e58eb5d0152d906de"
        headers = {'Content-Type': 'application/json;charset=utf-8'}
        data = {"msgtype": "text", "text": {"content": countent_text}}
        print(json.dumps(data))
        print(countent_text)
        requests.post(url, headers=headers, data=json.dumps(data))
    dx=f"test----------------------------sdfsdfsdf--------------------------------"
    send_text(dx)
    
    2、linux下直接curl调用
    curl -H "Content-Type: application/json" -X POST -d '{"msgtype": "text", "text": {"content": "test1"}}' "https://oapi.dingtalk.com/robot/send?access_token=8684ad760333e6fbb8ec8c0c12e2c00fcf7e58e58eb5d0152d9cebb06dee"
    

      

      

     

  • 相关阅读:
    MySQL关于check约束无效的解决办法
    关于constraint的用法
    MySQL关于Duplicate entry '1' for key 'PRIMARY'错误
    iOS实现高斯模糊效果(Swift版本)
    iOS获取视频中的指定帧的两种方法
    Java关于e.printStackTrace()介绍
    iOS关于JSONKit解析Unicode字符内容出错,问题出在u0000
    Java转型(向上转型和向下转型)
    添加删除Windows组件里没有IIS(Internet信息服务)项的解决方法
    Windows2003:“无法加载安装程序库wbemupgd.dll
  • 原文地址:https://www.cnblogs.com/wukc/p/16525473.html
Copyright © 2020-2023  润新知