首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Twilio -发送未正确呈现的vCard

Twilio -发送未正确呈现的vCard
EN

Stack Overflow用户
提问于 2021-02-23 13:37:26
回答 1查看 65关注 0票数 0

我试图通过Twilio (php)发送一张联系人卡片(.vcf),但似乎无法正确渲染vcf。

.vcf可以很好地保存到我的服务器上,如果我随后从服务器上下载该文件并在我的iPhone或Mac上的iMessage中打开,它会显示得很好。但是当通过Twilio发送时,我看到的都是纯文本的.vcf内容。

下面是我使用的代码:

代码语言:javascript
复制
$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格式。

代码语言:javascript
复制
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
EN

Stack Overflow用户

回答已采纳

发布于 2021-02-25 20:02:42

确保为您的vCard提供服务的端点设置了以下标头:

  • Content-Type: text/vcard
  • Cache-Control: no-cache
  • Content-Disposition: inline; filename="filename.vcf"

另请参阅此SO问题:生成VCard并通过Twilio发送

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66327635

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档