You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel调用WhatsApp Business API发送自定义文本消息失败

WhatsApp Business API自定义文本返回200但收不到消息排查方案

已成功通过WhatsApp Business API发送「Hello World」模板消息,但发送自定义纯文本消息时,请求返回状态码200及成功响应体,但手机端未收到消息。使用的PHP代码如下:

配置与消息构造代码

//API token given by Meta
$token = '*private*';

//Reciever number of msg
$telefono = '*private*';

//URL of msg given by Meta
$url = '*I think is private too*';

$mensaje = '{"messaging_product": "whatsapp", "to": "'.$telefono.'", "type": "text", "text": {"preview_url": false, "body": "MESSAGE_CONTENT" }}';
//header of msg
$header = array("Authorization: Bearer " . $token, "Content-Type: application/json");

Curl请求代码

//curl init
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POSTFIELDS, $mensaje);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

//get response from information sent
$response = json_decode(curl_exec($curl),true);

//print response
print_r($response);

//get curl response code
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);

print_r($status_code);
//close curl
curl_close($curl);

请求返回结果:

Array ( [messaging_product] => whatsapp [contacts] => Array ( [0] => Array ( [input] => *phone* [wa_id] => 56994134989 ) ) [messages] => Array ( [0] => Array ( [id] => *i think is private too* ) ) ) 200

核心排查方向

  • 会话窗口限制:
    WhatsApp Business API强制规定,自定义非模板消息仅能在用户主动向你的号码发送消息后的24小时会话窗口内发送。如果是你主动发起的 outbound 消息(用户未先触发对话),只能使用预审批的模板消息,即使请求返回200,消息也会被Meta拦截,无法送达。这是平台核心规则,优先确认是否符合这个场景。

  • 号码格式准确性:
    确认接收号码$telefono严格遵循E.164标准格式:无空格、括号或特殊字符,仅包含国家代码+号码(例如+56994134989)。即使响应返回了wa_id,也可能存在格式隐性错误导致路由失败。

  • API端点正确性:
    验证请求URL是否为对应版本的正确发送端点,格式应为:

    https://graph.facebook.com/v[版本号]/[你的WhatsApp号码ID]/messages
    

    确保URL中的[你的WhatsApp号码ID]是Meta Business Manager中绑定的WhatsApp号码的唯一ID,而非业务账户ID或其他ID。

  • 消息内容合规性:
    如果自定义文本包含Meta违规内容(如未授权广告、敏感词汇、垃圾信息等),会被静默拦截。先测试发送极简内容(如"Test 123"),排除内容合规问题。

  • Webhook状态监听:
    配置Webhook监听message_status事件,查看消息的实际流转状态(sent/delivered/failed等)。请求返回200仅代表Meta接收了请求,后续送达失败的具体原因会通过Webhook反馈。

代码小检查

确认$mensaje中的"MESSAGE_CONTENT"已替换为实际要发送的自定义文本内容,避免发送占位符空消息。

内容的提问来源于stack exchange,提问作者Javier Auspont Cerda

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 23:01:19