我在我的服务器上设置了一个API端点,以便Twilio在收到短信/彩信时通知我的服务器。
直到大约2周前,我能够使用PHP Copy功能将MMS的媒体文件复制到我的服务器:
copy($sourceFile, $destinationFolder.$destinationFileName);
哪里
$sourceFile = 'https://api.twilio.com/2010-04-01/Accounts/AC000000001/Messages/MM000000001/Media/ME000000001'
但是,现在,我没有获取媒体文件,而是获取描述该文件的XML:
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
<Media>
<Sid/>
<AccountSid>AC000000001</AccountSid>
<ParentSid/>
<ContentType/>
<DateCreated>Thu, 04 Apr 2019 15:31:30 +0000</DateCreated>
<DateUpdated>Thu, 04 Apr 2019 15:31:30 +0000</DateUpdated>
<Uri>/2010-04-01/Accounts/AC000000001/Messages/MM000000001/Media/ME000000001</Uri>
</Media>
</TwilioResponse>
我的代码没有任何变化,我找不到任何文件表明Twilio正在改变工作方式。
我尝试更改为卷曲请求,我得到相同的结果。我也尝试使用Twilio PHP SDK并遵循以下文档:https://www.twilio.com/docs/sms/api/media-resource#default-content-type
有没有人对发生的事情/改变了什么以及如何解决这个问题有所了解?
如果你看看"ME000000001"
$sourceFile = 'https://api.twilio.com/2010-04-01/Accounts/AC000000001/Messages/MM000000001/Media/ME000000001'
然后在XML响应的"ME000000001"
<Uri>/2010-04-01/Accounts/AC000000001/Messages/MM000000001/Media/ME000000001</Uri>
它们是不同的。
事实上,对于一条消息,比方说3个媒体附件,XML响应将类似于:
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
<MediaList end="2" firstpageuri="/2010-04-01/Accounts/AC.../Messages/MM.../Media?Pag...>
<Media>
<Sid>ME...92c</Sid>
<AccountSid>AC...3e4</AccountSid>
<ParentSid>MM...e3d</ParentSid>
<ContentType>image/jpeg</ContentType>
<DateCreated>Tue, 09 Apr 2019 20:06:33 +0000</DateCreated>
<DateUpdated>Tue, 09 Apr 2019 20:06:33 +0000</DateUpdated>
<Uri>/2010-04-01/Accounts/AC...3e4/Messages/MM.../Media/ME...92c</Uri>
</Media>
<Media>
<Sid>ME...4ac</Sid>
<AccountSid>AC...3e4</AccountSid>
<ParentSid>MM...e3d</ParentSid>
<ContentType>image/jpeg</ContentType>
<DateCreated>Tue, 09 Apr 2019 20:06:33 +0000</DateCreated>
<DateUpdated>Tue, 09 Apr 2019 20:06:33 +0000</DateUpdated>
<Uri>/2010-04-01/Accounts/AC.../Messages/MM.../Media/ME...4ac</Uri>
</Media>
<Media>
<Sid>ME...048</Sid>
<AccountSid>AC...3e4</AccountSid>
<ParentSid>MM...e3d</ParentSid>
<ContentType>image/jpeg</ContentType>
<DateCreated>Tue, 09 Apr 2019 20:06:33 +0000</DateCreated>
<DateUpdated>Tue, 09 Apr 2019 20:06:33 +0000</DateUpdated>
<Uri>/2010-04-01/Accounts/AC.../Messages/MM.../Media/ME...048</Uri>
</Media>
</MediaList>
</TwilioResponse>
所以,你会在<Uri>...</Uri>
的地址找到媒体(当然前面是https://api.twilio.com
)。
观察三个Uris是如何不同的,因为它们指向连接到同一消息的不同媒体。
<Uri>/2010-04-01/Accounts/AC.../Messages/MM.../Media/ME...92c</Uri>
<Uri>/2010-04-01/Accounts/AC.../Messages/MM.../Media/ME...4ac</Uri>
<Uri>/2010-04-01/Accounts/AC.../Messages/MM.../Media/ME...048</Uri>