php - Twilio - 发送未正确呈现的 vCard
问题描述
我正在尝试通过 Twilio (php) 发送联系人卡片 (.vcf),但似乎无法让 vcf 正确呈现。
.vcf 可以很好地保存到我的服务器,如果我随后从服务器下载文件并在我的 iPhone 或 Mac 上的 iMessage 中打开,它显示得很好。但是当通过 Twilio 发送时,我看到的只是纯文本的 .vcf 内容。
这是我正在使用的代码:
$account_sid = 'xxxxxxxx';
$auth_token = 'xxxxxxxx';
$client = new Services_Twilio($account_sid, $auth_token);
header('content-type: text/vcard');
header('content-disposition: inline; filename= "testing2.vcf"');
try {
$vCard = "BEGIN:VCARD\r";
$vCard .= "VERSION:4.0\r";
$vCard .= "N:Gump;Forrest;;Mr.;\r";
$vCard .= "FN:Forrest Gump\r";
$vCard .= "ORG:Bubba Gump Shrimp Co.\r";
$vCard .= "TITLE:Shrimp Man\r";
$vCard .= "PHOTO;MEDIATYPE=image/gif:http://www.example.com/dir_photos/my_photo.gif\r";
$vCard .= "TEL;TYPE=work,voice;VALUE=uri:tel:+1-111-555-1212\r";
$vCard .= "TEL;TYPE=home,voice;VALUE=uri:tel:+1-404-555-1212\r";
$vCard .= "EMAIL:forrestgump@example.com\r";
$vCard .= "END:VCARD";
$path = '/var/www/xxxx/xxxx/testing2.vcf';
file_put_contents($path, $vCard);
$client->account->messages->create(array(
'To' => $user_mobile,
'MediaUrl' => ['https://www.example.com/vcfs/testing2.vcf'],
'From' => "xxxxxxxxxxxx"
));
}
catch (\Services_Twilio_RestException $e) {
}
编辑
这是我从 MediaURL 中使用的 URL 得到的 curl 响应,表明它确实是 vcard 格式。
HTTP/1.1 200 OK
Date: Wed, 24 Feb 2021 04:13:29 GMT
Server: Apache/2.4.29 (Ubuntu)
Last-Modified: Tue, 23 Feb 2021 05:28:59 GMT
ETag: "15f-5bbfa320d710f"
Accept-Ranges: bytes
Content-Length: 351
Content-Type: text/vcard
解决方案
确保为您的 vCard 提供服务的端点设置以下标头:
Content-Type: text/vcard
,Cache-Control: no-cache
和Content-Disposition: inline; filename="filename.vcf"
另请参阅此 SO 问题:生成 VCard 并通过 Twilio 发送
推荐阅读
- javascript - cocos2dJs跨平台游戏换语言时设备崩溃(Android平台)
- java - 我在哪里可以找到 jdatepicker jar 文件?
- pdf - PDF 中使用的线条艺术或二进制图像的纯文本格式是什么?
- visual-studio - 英特尔 Fortran 外部库链接问题
- wildcard - 来自变量名的通配符匹配集
- azure - Chrome 中的 AzDO 被强制保存而不进行编辑
- search - 能否禁用 Visual Studio 2019 中的动态搜索?
- r - Plotly(R)中关于“标记”的错误消息
- r - 如何合并R中具有不同列名的两个数据集?
- ios - 为什么 UIAccessibilityNotification 不转向正确的论点?