如何免费使用 WhatsApp Business API(2026版)
无需预付费用,即可通过编程方式发送消息
开始使用 Hypereal 构建
通过单个 API 访问 Kling、Flux、Sora、Veo 等。免费积分开始,扩展到数百万。
无需信用卡 • 10万+ 开发者 • 企业级服务
如何免费使用 WhatsApp Business API (2026年版)
WhatsApp Business API 允许你通过编程方式发送和接收消息、自动化客户服务并构建聊天机器人。以前,访问此 API 需要通过昂贵的商业解决方案提供商 (BSP)。但在 2026 年,Meta 的 Cloud API 让免费入门成为可能。本指南将通过实际的代码示例带你完成完整的设置过程。
WhatsApp Business API:免费层级概述
Meta 为 WhatsApp Business Cloud API 提供的免费层级包含以下限制:
| 功能 | 免费层级 | 付费层级 |
|---|---|---|
| 服务对话(用户发起) | 每月 1,000 条免费 | 每条对话 $0.005 - 0.08 |
| 营销对话 | 不包含 | 每条对话 $0.01 - 0.15 |
| 测试电话号码 | 包含 1 个测试号码 | 无限制的已验证号码 |
| 消息模板 | 250 个模板 | 250 个模板 |
| 媒体消息 | 支持 | 支持 |
| Webhook 通知 | 支持 | 支持 |
| 速率限制 | 80 消息/秒 | 500+ 消息/秒 |
每月 1,000 条免费服务对话会在每月 1 号重置。服务对话是指由用户发起的对话(他们先给你发消息),每个对话窗口持续 24 小时。
前提条件
在开始之前,你需要:
- 一个 Meta (Facebook) 账号
- 一个 Meta 商务管理中心账号 (免费创建)
- 一个可以接收短信或语音电话以进行验证的 电话号码
- REST API 的基础知识
分步设置
第 1 步:创建 Meta 开发者账号
1. 访问 https://developers.facebook.com
2. 点击 "入门" 或 "我的应用"
3. 使用你的 Facebook 账号登录
4. 接受开发者条款
5. 使用电话号码验证你的账号
第 2 步:创建一个新应用
1. 在开发者面板中点击 "创建应用"
2. 选择 "商务" 作为应用类型
3. 输入应用名称(例如 "My WhatsApp Bot")
4. 选择你的 Meta 商务管理中心账号(或创建一个)
5. 点击 "创建应用"
第 3 步:将 WhatsApp 添加到你的应用
1. 在应用面板中,找到 "添加产品"
2. 在 WhatsApp 卡片上点击 "设置"
3. 这会自动创建一个测试 WhatsApp Business 账号
4. 你将看到一个测试电话号码和临时访问令牌 (Access Token)
第 4 步:获取访问令牌
面板中的临时令牌会在 24 小时后过期。对于生产环境,请生成永久的系统用户令牌:
1. 前往 Meta 商务管理中心 > 设置 > 商务管理中心设置
2. 导航到 "系统用户"
3. 点击 "添加" 创建一个新的系统用户
4. 将角色设置为 "管理员"
5. 点击 "生成令牌"
6. 选择你的 WhatsApp 应用
7. 授予以下权限:
- whatsapp_business_management
- whatsapp_business_messaging
8. 复制并安全保存该令牌
第 5 步:添加测试收件人
在发送消息之前,你必须将收件人电话号码添加到测试列表中:
1. 在应用面板的 WhatsApp 栏目中
2. 前往 "API 设置"
3. 在 "发送消息" 下,点击 "管理电话号码列表"
4. 添加你想要发送测试消息的电话号码
5. 每个收件人必须通过回复验证消息来进行确认
发送你的第一条消息
使用 cURL
curl -X POST \
"https://graph.facebook.com/v21.0/YOUR_PHONE_NUMBER_ID/messages" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"messaging_product": "whatsapp",
"to": "1234567890",
"type": "text",
"text": {
"body": "来自 WhatsApp Business API 的问候!"
}
}'
使用 Node.js
const axios = require("axios");
const PHONE_NUMBER_ID = "your_phone_number_id";
const ACCESS_TOKEN = "your_access_token";
async function sendWhatsAppMessage(to, message) {
try {
const response = await axios.post(
`https://graph.facebook.com/v21.0/${PHONE_NUMBER_ID}/messages`,
{
messaging_product: "whatsapp",
to: to,
type: "text",
text: { body: message }
},
{
headers: {
Authorization: `Bearer ${ACCESS_TOKEN}`,
"Content-Type": "application/json"
}
}
);
console.log("消息已发送:", response.data);
return response.data;
} catch (error) {
console.error("错误:", error.response?.data || error.message);
throw error;
}
}
// 发送消息
sendWhatsAppMessage("1234567890", "来自 Node.js 的问候!");
使用 Python
import requests
PHONE_NUMBER_ID = "your_phone_number_id"
ACCESS_TOKEN = "your_access_token"
def send_whatsapp_message(to: str, message: str):
url = f"https://graph.facebook.com/v21.0/{PHONE_NUMBER_ID}/messages"
headers = {
"Authorization": f"Bearer {ACCESS_TOKEN}",
"Content-Type": "application/json"
}
payload = {
"messaging_product": "whatsapp",
"to": to,
"type": "text",
"text": {"body": message}
}
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
print("消息已发送:", response.json())
return response.json()
# 发送消息
send_whatsapp_message("1234567890", "来自 Python 的问候!")
发送富媒体消息
图片消息
def send_image(to: str, image_url: str, caption: str = ""):
payload = {
"messaging_product": "whatsapp",
"to": to,
"type": "image",
"image": {
"link": image_url,
"caption": caption
}
}
response = requests.post(
f"https://graph.facebook.com/v21.0/{PHONE_NUMBER_ID}/messages",
json=payload,
headers={"Authorization": f"Bearer {ACCESS_TOKEN}"}
)
return response.json()
交互式按钮消息
def send_buttons(to: str, body_text: str, buttons: list):
payload = {
"messaging_product": "whatsapp",
"to": to,
"type": "interactive",
"interactive": {
"type": "button",
"body": {"text": body_text},
"action": {
"buttons": [
{
"type": "reply",
"reply": {"id": btn["id"], "title": btn["title"]}
}
for btn in buttons
]
}
}
}
response = requests.post(
f"https://graph.facebook.com/v21.0/{PHONE_NUMBER_ID}/messages",
json=payload,
headers={"Authorization": f"Bearer {ACCESS_TOKEN}"}
)
return response.json()
# 发送带有按钮的消息
send_buttons(
"1234567890",
"今天我们可以为您提供什么帮助?",
[
{"id": "support", "title": "获取支持"},
{"id": "pricing", "title": "查看价格"},
{"id": "demo", "title": "预约演示"}
]
)
模板消息(用于主动通知)
要首先给用户发消息(在 24 小时窗口期外),你必须使用审核通过的模板:
def send_template(to: str, template_name: str, language: str = "en_US"):
payload = {
"messaging_product": "whatsapp",
"to": to,
"type": "template",
"template": {
"name": template_name,
"language": {"code": language},
"components": [
{
"type": "body",
"parameters": [
{"type": "text", "text": "John"},
{"type": "text", "text": "您的订单 #12345"}
]
}
]
}
}
response = requests.post(
f"https://graph.facebook.com/v21.0/{PHONE_NUMBER_ID}/messages",
json=payload,
headers={"Authorization": f"Bearer {ACCESS_TOKEN}"}
)
return response.json()
设置 Webhook
要接收传入的消息,你需要配置一个 Webhook 端点。
Express.js Webhook 服务器
const express = require("express");
const app = express();
app.use(express.json());
const VERIFY_TOKEN = "your_custom_verify_token";
// Webhook 验证 (GET)
app.get("/webhook", (req, res) => {
const mode = req.query["hub.mode"];
const token = req.query["hub.verify_token"];
const challenge = req.query["hub.challenge"];
if (mode === "subscribe" && token === VERIFY_TOKEN) {
console.log("Webhook 已验证");
res.status(200).send(challenge);
} else {
res.sendStatus(403);
}
});
// 接收消息 (POST)
app.post("/webhook", (req, res) => {
const body = req.body;
if (body.object === "whatsapp_business_account") {
body.entry?.forEach((entry) => {
entry.changes?.forEach((change) => {
const messages = change.value?.messages;
if (messages) {
messages.forEach((message) => {
console.log("来自:", message.from);
console.log("类型:", message.type);
if (message.type === "text") {
console.log("内容:", message.text.body);
}
});
}
});
});
res.sendStatus(200);
} else {
res.sendStatus(404);
}
});
app.listen(3000, () => {
console.log("Webhook 服务器运行在端口 3000");
});
公开你的本地服务器
在开发阶段,使用隧道服务公开你的本地 Webhook:
# 使用 ngrok
ngrok http 3000
# 使用 Cloudflare Tunnel
cloudflared tunnel --url http://localhost:3000
然后在 Meta 应用面板的 WhatsApp > 配置 > Webhook URL 中注册该公开 URL。
免费替代方案和补充
如果免费层级的限制过于严格,可以考虑以下选项:
| 选项 | 免费消息 | 备注 |
|---|---|---|
| Meta Cloud API (官方) | 每月 1,000 条服务对话 | 最适合小型项目 |
| Twilio WhatsApp Sandbox | 开发期间免费 | 需要 Twilio 账号;生产环境付费 |
| WhatsApp Business App (手动) | 无限制 | 无 API 访问权限;仅限手动发送 |
| WATI 免费试用 | 14 天试用 | 提供面板和机器人构建器的 BSP |
常见错误及解决方案
| 错误代码 | 消息内容 | 解决方案 |
|---|---|---|
| 131030 | "收件人手机号不在允许列表中" | 将该号码添加到测试收件人列表中 |
| 131047 | "重新互动消息" | 使用审核通过的模板进行首次联系 |
| 100 | "参数无效" | 检查电话号码格式(需包含国家代码,不含 + 或空格) |
| 190 | "访问令牌已过期" | 生成新的系统用户令牌 |
| 368 | "因政策原因暂时锁定" | 查看 Meta 的商业和消息政策 |
结论
通过 Meta 的 Cloud API,你可以免费访问 WhatsApp Business API,每月享受 1,000 条免费服务对话。这对于小型企业、原型设计和个人项目来说已经足够了。通过 Meta 开发者门户设置大约需要 30 分钟,之后你就可以通过编程方式发送文本、媒体和交互式消息。
对于希望通过 AI 生成的视频内容来增强 WhatsApp 沟通的企业——例如个性化的产品演示视频或 AI 数字人问候——Hypereal AI 提供了价格合理的视频生成和数字人创建 API,能很好地与 WhatsApp 富媒体消息结合使用。
