{
  "nodes": [
    {
      "parameters": {
        "bucketName": "n8n",
        "fileKey": "token_tuisong"
      },
      "id": "92b1914d-5c5a-4488-8080-eed7b3020914",
      "name": "\u8bfb\u53d6token\u7f13\u5b58",
      "type": "n8n-nodes-base.s3",
      "typeVersion": 1,
      "position": [
        -140,
        200
      ],
      "credentials": {
        "s3": {
          "name": "<your credential>"
        }
      },
      "continueOnFail": true
    },
    {
      "parameters": {
        "authentication": "headerAuth",
        "path": "wechatwork",
        "responseMode": "responseNode",
        "options": {
          "ignoreBots": true
        }
      },
      "id": "8bc2cd00-bf8c-4026-8a7a-c67a33b43a55",
      "name": "Webhook-GET",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        -440,
        -180
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "authentication": "headerAuth",
        "httpMethod": "POST",
        "path": "wechatwork",
        "responseMode": "responseNode",
        "options": {
          "ignoreBots": false
        }
      },
      "id": "4eb74db7-7e27-4c5d-9862-52f090cdad11",
      "name": "Webhook-POST",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        -440,
        -40
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "01b3a906-a4ad-464c-af7e-6a0677e87e35",
      "name": "S3\u6570\u636e\u8f6c\u6362",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        220,
        220
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={{ $json.token }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($node[\"\u751f\u6210\u63a8\u9001payload\"].json.content) }}",
        "options": {}
      },
      "id": "38566d6d-c6da-477f-9a9b-15c50140bb6a",
      "name": "\u63a8\u9001\u6d88\u606f",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        380,
        220
      ]
    },
    {
      "parameters": {
        "options": {
          "responseCode": 200
        }
      },
      "id": "42198b23-022f-47ad-a6c2-773676145937",
      "name": "\u6b63\u5e38\u63a8\u9001\u8fd4\u56de",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1040,
        160
      ]
    },
    {
      "parameters": {
        "operation": "upload",
        "bucketName": "n8n",
        "fileName": "token_tuisong",
        "binaryData": false,
        "fileContent": "={\"token\":\"{{ $json[\"access_token\"] }}\"}",
        "additionalFields": {
          "acl": "private"
        }
      },
      "id": "bca132d2-09eb-486c-9607-cb31099fb50c",
      "name": "\u5199\u5165token\u7f13\u5b58",
      "type": "n8n-nodes-base.s3",
      "typeVersion": 1,
      "position": [
        80,
        440
      ],
      "credentials": {
        "s3": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "https://qyapi.weixin.qq.com/cgi-bin/gettoken",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "corpid",
              "value": "wwbd724dbf452811c3"
            },
            {
              "name": "corpsecret",
              "value": "FtNTc4AV3kYYor6zfB8BieCeS8Wr1VZ9A4FLaixHUTw"
            }
          ]
        },
        "options": {}
      },
      "id": "72991f97-5ddd-4c32-899f-172e7fba7566",
      "name": "\u8bf7\u6c42\u65b0token",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        -100,
        440
      ]
    },
    {
      "parameters": {},
      "id": "392eecba-867a-404b-b35d-ed3855c46228",
      "name": "Trigger",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1,
      "position": [
        -440,
        100
      ]
    },
    {
      "parameters": {
        "content": "token\u5b58\u6d3b\u671f\uff1a7200s=2h\n42001 token\u8fc7\u671f\n40014 \u65e0\u6548token\n\n",
        "height": 111.67074663402693,
        "width": 214.38800489596082
      },
      "id": "30f95710-1d20-44d2-9e5a-d8b043754947",
      "name": "Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        260,
        -120
      ]
    },
    {
      "parameters": {
        "value1": "={{$node[\"\u63a8\u9001\u6d88\u606f\"].json[\"errcode\"]}}",
        "rules": {
          "rules": [
            {
              "operation": "equal"
            },
            {
              "operation": "equal",
              "value2": 42001,
              "output": 1
            },
            {
              "operation": "equal",
              "value2": 40014,
              "output": 1
            }
          ]
        },
        "fallbackOutput": 3
      },
      "id": "85bc824a-41ce-4a99-9137-157ad72d35a5",
      "name": "\u63a8\u9001\u7ed3\u679c\u5224\u65ad",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        760,
        220
      ]
    },
    {
      "parameters": {
        "options": {
          "responseCode": 400
        }
      },
      "id": "13f4a562-d6f0-480f-b250-4af903734905",
      "name": "\u817e\u8baf\u7aef\u62a5\u9519\u8fd4\u56de",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1040,
        340
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.error }}",
              "operation": "isNotEmpty"
            }
          ]
        }
      },
      "id": "03787073-8203-499c-b9a5-ad173f0ea7f2",
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        40,
        200
      ]
    },
    {
      "parameters": {
        "content": "https://developer.work.weixin.qq.com/document/path/90236#%E6%96%87%E6%9C%AC%E5%8D%A1%E7%89%87%E6%B6%88%E6%81%AF",
        "height": 80,
        "width": 280.4834761321911
      },
      "id": "da64e771-c3d2-426b-8fea-0138ac21113c",
      "name": "Note1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -220,
        -380
      ]
    },
    {
      "parameters": {
        "content": "https://developer.work.weixin.qq.com/document/path/90236#markdown%E6%B6%88%E6%81%AF",
        "height": 80,
        "width": 280.4834761321911
      },
      "id": "d3d9879e-5ed2-4b99-a699-5ea2d28280d4",
      "name": "Note2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -220,
        -220
      ]
    },
    {
      "parameters": {
        "content": "https://developer.work.weixin.qq.com/document/path/90236#%E6%96%87%E6%9C%AC%E6%B6%88%E6%81%AF",
        "height": 80,
        "width": 280.4834761321911
      },
      "id": "e1a79ec5-0fe6-47f3-99ec-ed5bada3608d",
      "name": "Note3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -220,
        -300
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "type",
              "value": "={{$json.type ? $json.type : ($json.body.type ? $json.body.type : \"text\") }}"
            },
            {
              "name": "content",
              "value": "={{$json.content? $json.content : ($json.body.content ? $json.body.content : $json.query.content) }}"
            }
          ]
        },
        "options": {}
      },
      "id": "1a77d243-5c1a-4d23-b136-00f272e78da5",
      "name": "\u521d\u59cb\u5316\u4f20\u5165\u53c2\u6570",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        -200,
        -40
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "type",
              "value": "={{ $json[\"type\"] }}"
            },
            {
              "name": "content.touser",
              "value": "@all"
            },
            {
              "name": "content.toparty",
              "value": "@all"
            },
            {
              "name": "content.totag",
              "value": "@all"
            },
            {
              "name": "content.msgtype",
              "value": "={{ $json[\"type\"] }}"
            },
            {
              "name": "=content.{{ $json[\"type\"] }}{{ $jmespath($json.type,\"contains([`text`,`markdown`],@)\") ? \".content\" : \"\" }}",
              "value": "={{ $json.content }}"
            }
          ],
          "number": [
            {
              "name": "content.agentid",
              "value": 1000002
            },
            {
              "name": "content.enable_duplicate_check"
            },
            {
              "name": "content.duplicate_check_interval",
              "value": 1800
            }
          ]
        },
        "options": {}
      },
      "id": "a4a44ad2-6c32-4c9f-8869-0c847d2a6a33",
      "name": "\u751f\u6210\u63a8\u9001payload",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        -60,
        -40
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.content.msgtype }}",
              "operation": "isNotEmpty"
            }
          ]
        }
      },
      "id": "a77db1ba-c7b1-4014-901e-8c1dd35fbc67",
      "name": "\u5224\u65adtype",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        80,
        -40
      ]
    },
    {
      "parameters": {
        "content": "```json\n{\n    \"touser\" : \"@all\",\n    \"toparty\" : \"@all\",\n    \"totag\" : \"@all\",\n    \"msgtype\" : \"{{ $json[\"type\"] }}\",\n    \"agentid\" : 1000002,\n    \"{{ $json[\"type\"] }}\" : \n    {{ $jmespath($json.type,\"contains([`text`,`markdown`],@)\") ? \"{content: \" : \"\" }}\n    {{JSON.stringify($json.content)}}\n    {{ $jmespath($json.type,\"contains([`text`,`markdown`],@)\") ? \"}\" : \"\" }},\n    \"enable_duplicate_check\": 0,\n    \"duplicate_check_interval\": 1800\n}\n```",
        "height": 242.21664626682985,
        "width": 965.3500611995106
      },
      "id": "704149e9-4125-4945-9405-929dfeb776b8",
      "name": "Note4",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        80,
        -380
      ]
    },
    {
      "parameters": {
        "content": "{{ $jmespath($json.type,\"contains([`text`,`markdown`],@)\") ? \"content: \" : \"cc\" }}",
        "height": 80,
        "width": 541.1603427172583
      },
      "id": "47774aec-9c80-45a1-a24e-6867bf8f152c",
      "name": "Note5",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        500,
        -120
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\n\"errcode\":400,\n\"errmsg\":\"tpye missing\"\n}",
        "options": {
          "responseCode": 400
        }
      },
      "id": "ff5b741a-6a0a-4198-9808-2a8e444f33f1",
      "name": "\u7c7b\u578b\u7f3a\u5931",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1040,
        -20
      ]
    }
  ],
  "connections": {
    "\u8bfb\u53d6token\u7f13\u5b58": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook-GET": {
      "main": [
        [
          {
            "node": "\u521d\u59cb\u5316\u4f20\u5165\u53c2\u6570",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook-POST": {
      "main": [
        [
          {
            "node": "\u521d\u59cb\u5316\u4f20\u5165\u53c2\u6570",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "S3\u6570\u636e\u8f6c\u6362": {
      "main": [
        [
          {
            "node": "\u63a8\u9001\u6d88\u606f",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u63a8\u9001\u6d88\u606f": {
      "main": [
        [
          {
            "node": "\u63a8\u9001\u7ed3\u679c\u5224\u65ad",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u5199\u5165token\u7f13\u5b58": {
      "main": [
        [
          {
            "node": "\u8bfb\u53d6token\u7f13\u5b58",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u8bf7\u6c42\u65b0token": {
      "main": [
        [
          {
            "node": "\u5199\u5165token\u7f13\u5b58",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger": {
      "main": [
        [
          {
            "node": "\u521d\u59cb\u5316\u4f20\u5165\u53c2\u6570",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u63a8\u9001\u7ed3\u679c\u5224\u65ad": {
      "main": [
        [
          {
            "node": "\u6b63\u5e38\u63a8\u9001\u8fd4\u56de",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "\u8bf7\u6c42\u65b0token",
            "type": "main",
            "index": 0
          }
        ],
        null,
        [
          {
            "node": "\u817e\u8baf\u7aef\u62a5\u9519\u8fd4\u56de",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "\u8bf7\u6c42\u65b0token",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "S3\u6570\u636e\u8f6c\u6362",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u521d\u59cb\u5316\u4f20\u5165\u53c2\u6570": {
      "main": [
        [
          {
            "node": "\u751f\u6210\u63a8\u9001payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u751f\u6210\u63a8\u9001payload": {
      "main": [
        [
          {
            "node": "\u5224\u65adtype",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u5224\u65adtype": {
      "main": [
        [
          {
            "node": "\u8bfb\u53d6token\u7f13\u5b58",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "\u7c7b\u578b\u7f3a\u5931",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}