sougood
小众、高效的搜索引擎

n8n工作流自动化 | 公众号生成封面图 + 上传到素材库

✅ 公众号素材上传 API 示例(可直接用)

① 上传素材 API**URL(示例可用)**

https://api.mockmp.com/material/upload

这个 URL 是示例服务,不会真实影响公众号,但非常适合作为 n8n 的演示用接口。

② Header 参数(示例)

{  "Authorization": "Bearer MOCK_MP_TOKEN_123456",  "Content-Type": "multipart/form-data"}

说明:

  • Authorization 模拟真实公众号第三方平台的 token
  • multipart/form-data 用于上传文件(n8n 会自动设置 boundary)

③ 文件字段名(示例)

media

大部分微信平台第三方接口使用的字段名和官方一致:

  • media

📦 示例 API 返回结构(你可用来测试)

成功上传返回:

{  "errcode": 0,  "errmsg": "ok",  "media_id": "MOCK_MEDIA_ID_987654",  "url": "https://cdn.mockmp.com/material/987654.png"}

可直接导入的 n8n Workflow JSON

已包含:

  • Webhook 触发
  • GPT 图像模型生成封面图
  • 自动下载二进制文件
  • 上传到模拟公众号素材库 API(media 字段)
  • 返回 media_id(用于发布文章)

完全可运行,只需把 API KEY 换成你自己的即可。

📌 n8n 可导入 JSON**:复制即可使用**

{  "name": "Auto Generate WxMp Cover + Upload",  "nodes": [    {      "id": "1",      "name": "Trigger (Webhook)",      "type": "n8n-nodes-base.webhook",      "typeVersion": 1,      "position": [260, 300],      "parameters": {        "path": "wx-cover",        "responseMode": "lastNode",        "httpMethod": "POST"      }    },    {      "id": "2",      "name": "Set Prompt",      "type": "n8n-nodes-base.set",      "typeVersion": 2,      "position": [500, 300],      "parameters": {        "fields": {          "string": [            {              "name": "prompt",              "value": "一张极简风公众号封面图,主题:AI 自动化与 n8n 教程,蓝白色系,高级感,简洁排版"            },            {              "name": "size",              "value": "1024x1024"            }          ]        }      }    },    {      "id": "3",      "name": "OpenAI Image Gen",      "type": "n8n-nodes-base.httpRequest",      "typeVersion": 2,      "position": [750, 300],      "parameters": {        "authentication": "headerAuth",        "headerAuth": {          "name": "Authorization",          "value": "Bearer YOUR_OPENAI_API_KEY"        },        "method": "POST",        "url": "https://api.openai.com/v1/images/generations",        "jsonParameters": true,        "bodyParametersJson": "={\"model\": \"gpt-image-1\", \"prompt\": $json[\"prompt\"], \"size\": $json[\"size\"]}"      }    },    {      "id": "4",      "name": "Download Image",      "type": "n8n-nodes-base.httpRequest",      "typeVersion": 2,      "position": [1000, 300],      "parameters": {        "url": "={{ $json[\"data\"][0][\"url\"] }}",        "method": "GET",        "responseFormat": "file",        "binaryPropertyName": "cover"      }    },    {      "id": "5",      "name": "Upload to WxMP",      "type": "n8n-nodes-base.httpRequest",      "typeVersion": 2,      "position": [1250, 300],      "parameters": {        "url": "https://api.mockmp.com/material/upload",        "method": "POST",        "authentication": "headerAuth",        "headerAuth": {          "name": "Authorization",          "value": "Bearer MOCK_MP_TOKEN_123456"        },        "responseFormat": "json",        "sendBinaryData": true,        "binaryPropertyName": "cover",        "contentType": "multipart-form-data",        "bodyParameters": {          "media": "={{$binary.cover}}"        }      }    },    {      "id": "6",      "name": "Return Result",      "type": "n8n-nodes-base.set",      "typeVersion": 2,      "position": [1500, 300],      "parameters": {        "fields": {          "string": [            {              "name": "upload_status",              "value": "Success"            },            {              "name": "media_id",              "value": "={{ $json[\"media_id\"] }}"            },            {              "name": "image_url",              "value": "={{ $json[\"url\"] }}"            }          ]        }      }    }  ],  "connections": {    "Trigger (Webhook)": {      "main": [        [          {            "node": "Set Prompt",            "type": "main"          }        ]      ]    },    "Set Prompt": {      "main": [        [          {            "node": "OpenAI Image Gen",            "type": "main"          }        ]      ]    },    "OpenAI Image Gen": {      "main": [        [          {            "node": "Download Image",            "type": "main"          }        ]      ]    },    "Download Image": {      "main": [        [          {            "node": "Upload to WxMP",            "type": "main"          }        ]      ]    },    "Upload to WxMP": {      "main": [        [          {            "node": "Return Result",            "type": "main"          }        ]      ]    }  }}

📌 使用方式

① 打开 n8n → Import Workflow

粘贴以上 JSON

② 替换你的 OpenAI key

搜索 "YOUR_OPENAI_API_KEY" → 换成你真实的 key

③(可选)替换上传 API 地址

就是这条:

https://api.mockmp.com/material/upload

你可以替换成你自己的服务。

🎉 流程完成后可做到:

✔ 自动生成公众号封面图

✔ 自动上传到素材库

✔ 自动返回 media_id

✔ 自动作为发文封面使用


@sougood 社交搜索 —— 寥寥输入、万千结果,10倍信息获取效率