Clickatel WhatsApp集成无法发送图像
我无法使用ClickAtel One API发送媒体文件,尤其是图像(JPEG)。
但是,正在发送短信。
以下是我的代码段以发送文件:( php)
$header = [
'Authorization: ' . $clickatel_api_key,
'Content-Type: image/jpeg'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, 'https://platform.clickatell.com/v1/media?fileName=' . $name . '&to=254712345678');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $file);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
以下是请求的响应:
{"error":null,"fileId":"2eee5d0eee4fc4f42943e47c06f12345fdss2ddd.jpg","accepted":true}
未交付媒体文件。
I am unable to send media files especially images(jpeg) using the Clickatel One API.
However, text messages are being delivered.
Below is my code snippet for sending the file: (PHP)
$header = [
'Authorization: ' . $clickatel_api_key,
'Content-Type: image/jpeg'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, 'https://platform.clickatell.com/v1/media?fileName=' . $name . '&to=254712345678');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $file);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
Below is the response from the request:
{"error":null,"fileId":"2eee5d0eee4fc4f42943e47c06f12345fdss2ddd.jpg","accepted":true}
The media file is not delivered.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您在示例中使用的API调用您上传文件并返回文件ID。接下来,您必须使用该文件ID发送一条消息(另一个HTTP帖子),示例:
替代方案是执行一个http请求,其中包含文件数据内联的文件:
我所指的Clickatell文档中的示例称为:
如果您使用通过参考发送的方法(涉及两个HTTP请求),则在所有HTTP请求之间重复使用您的curl对象(甚至对于其他消息),以便您重复使用将是有益的您的HTTP连接可降低延迟,并减少您身边的CPU使用情况。
I think the API call you do in your example uploads a file and returns a file ID. Next you must send a message (another HTTP POST) using that file ID, example:
The alternative is to do one HTTP request that contains the file data inline:
The examples in the Clickatell documentation that I refer to are called:
If you use the method to send by reference (involving two HTTP requests), it would be beneficial to reuse your curl object ($ch) between all HTTP requests (even for other messages) so that you reuse your HTTP connection for lower latency and reduced CPU usage on your side.