145 lines
4.5 KiB
Plaintext
145 lines
4.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"id": "initial_id",
|
|
"metadata": {
|
|
"collapsed": true,
|
|
"ExecuteTime": {
|
|
"end_time": "2025-08-26T08:49:23.484900Z",
|
|
"start_time": "2025-08-26T08:49:23.324823Z"
|
|
}
|
|
},
|
|
"source": [
|
|
"# 使用Python验证(替换实际参数)\n",
|
|
"import requests\n",
|
|
"def verify_webhook():\n",
|
|
" url = \"https://oapi.dingtalk.com/robot/send?access_token=06d3d68dbe677ad18aca3a5aaf54bb6253812b5d8bfc725b63addf2962732a3b\"\n",
|
|
" data = {\"msgtype\": \"text\", \"text\": {\"content\": \"测试\"}}\n",
|
|
" response = requests.post(url, json=data)\n",
|
|
" print(response.json()) # 应返回 {\"errcode\":0, \"errmsg\":\"ok\"}\n",
|
|
"\n",
|
|
"verify_webhook()"
|
|
],
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"{'errcode': 0, 'errmsg': 'ok'}\n"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 6
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-08-26T08:24:54.246957Z",
|
|
"start_time": "2025-08-26T08:24:54.051940Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"import requests\n",
|
|
"import json\n",
|
|
"import time\n",
|
|
"\n",
|
|
"def send_js_to_dingtalk(webhook_url, secret, js_code, title=\"JavaScript代码\", description=None):\n",
|
|
" \"\"\"\n",
|
|
" 快速发送JavaScript代码到钉钉\n",
|
|
"\n",
|
|
" Args:\n",
|
|
" webhook_url: 钉钉webhook地址\n",
|
|
" secret: 加签密钥\n",
|
|
" js_code: JavaScript代码内容\n",
|
|
" title: 消息标题\n",
|
|
" description: 代码描述\n",
|
|
" \"\"\"\n",
|
|
" # 生成签名(简化版)\n",
|
|
" timestamp = str(round(time.time() * 1000))\n",
|
|
" if secret:\n",
|
|
" import hmac, hashlib, base64, urllib.parse\n",
|
|
" secret_enc = secret.encode('utf-8')\n",
|
|
" string_to_sign = f\"{timestamp}\\n{secret}\"\n",
|
|
" hmac_code = hmac.new(secret_enc, string_to_sign.encode('utf-8'), hashlib.sha256).digest()\n",
|
|
" sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))\n",
|
|
" webhook_url = f\"{webhook_url}×tamp={timestamp}&sign={sign}\"\n",
|
|
"\n",
|
|
" # 构建消息内容\n",
|
|
" markdown_text = f\"# {title}\\n\\n\"\n",
|
|
" if description:\n",
|
|
" markdown_text += f\"**描述**: {description}\\n\\n\"\n",
|
|
"\n",
|
|
" markdown_text += f\"**发送时间**: {time.strftime('%Y-%m-%d %H:%M:%S')}\\n\\n\"\n",
|
|
" markdown_text += f\"```javascript\\n{js_code}\\n```\"\n",
|
|
"\n",
|
|
" data = {\n",
|
|
" \"msgtype\": \"markdown\",\n",
|
|
" \"markdown\": {\n",
|
|
" \"title\": title,\n",
|
|
" \"text\": markdown_text\n",
|
|
" }\n",
|
|
" }\n",
|
|
"\n",
|
|
" try:\n",
|
|
" response = requests.post(webhook_url, json=data, timeout=10)\n",
|
|
" return response.json()\n",
|
|
" except Exception as e:\n",
|
|
" return {\"error\": str(e)}\n",
|
|
"\n",
|
|
"# 快速测试\n",
|
|
"if __name__ == \"__main__\":\n",
|
|
" WEBHOOK_URL = \"https://oapi.dingtalk.com/robot/send?access_token=06d3d68dbe677ad18aca3a5aaf54bb6253812b5d8bfc725b63addf2962732a3b\"\n",
|
|
" SECRET = \"None\" # 如果没有加签,设为None\n",
|
|
"\n",
|
|
" # 要发送的JavaScript代码\n",
|
|
" js_code = \"\"\"\n",
|
|
"// 简单的DOM操作示例测试\n",
|
|
"document.addEventListener('DOMContentLoaded', function() {\n",
|
|
" const button = document.getElementById('myButton');\n",
|
|
" button.addEventListener('click', function() {\n",
|
|
" alert('按钮被点击了!');\n",
|
|
" });\n",
|
|
"});\n",
|
|
"\"\"\"\n",
|
|
"\n",
|
|
" result = send_js_to_dingtalk(WEBHOOK_URL, SECRET, js_code, \"前端代码示例\", \"这是一个简单的DOM事件处理示例\")\n",
|
|
" print(\"发送结果:\", result)"
|
|
],
|
|
"id": "479549992d9a2d22",
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"发送结果: {'errcode': 0, 'errmsg': 'ok'}\n"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 4
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 2
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython2",
|
|
"version": "2.7.6"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|