# coding: utf-8
import json
import requests

def dingding_robot(data):
    # 机器人的webhooK 获取地址参考：https://open-doc.dingtalk.com/microapp/serverapi2/qf2nxq
    webhook = "https://oapi.dingtalk.com/robot/send?access_token=5131b887f6b022150f903e9d690e08c0d481fba844545034aaf48906ee026fa0"
    headers = {'content-type': 'application/json'} # 请求头
    r = requests.post(webhook, headers=headers, data=json.dumps(data))
    r.encoding = 'utf-8'
    return (r.text)


if __name__ == "__main__":
    # 请求参数 可以写入配置文件中
    data = {
        "msgtype": "link",
        "link": {
            "text": "群机器人是钉钉群的高级扩展功能。群机器人可以将第三方服务的信息聚合到群聊中，实现自动化的信息同步。",
            "title": "自定义机器人",
            "picUrl": "",
            # "messageUrl": "https://www.baidu.com/"
        }
    }
    res = dingding_robot(data)
    print(res) # 打印请求结果