我正在尝试将 WhatsApp Cloud API 添加到我们的 CRM,但无法使其正常工作。测试发送消息时出现以下错误:
Array ( [error] => Array ( [message] => (#100) 参数 messages_product 是必需的。 [type] => OAuthException [code] => 100 [fbtrace_id] => AE0w_gLBZGvIf00W-p7ctfv ) )
通过邮递员一切似乎都工作正常,但仅使用模板发送消息。我在我的服务器上测试了两者,但不断收到相同的错误。
这是我的代码:
$text_arr = array(
'preview_url' => 'false',
'body' => 'Hello, this is a test from home'
);
$fields = array(
'messaging_product' => 'whatsapp',
'recipient_type' => 'individual',
'to' => '18292605656',
'type' => 'text',
'text' => $text_arr
);
$header = array(
'Authorization: Bearer ' => $token,
'Content-Type' => "application/json"
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($fields) );
curl_setopt($curl, CURLOPT_HTTPHEADER, $header );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = json_decode(curl_exec($curl), true);
print_r($response);
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?