2015-10-20 48 views
-2

我需要JSON格式響應這我得到的如何使用PHP SDK從twilio短信API

class Services_Twilio_Rest_Message 

我需要在以下JSON發送短信後返回的響應得到JSON格式響應:

{ 
    "sid": "sid", 
    "date_created": "Tue, 20 Oct 2015 06:01:14 +0000", 
    "date_updated": "Tue, 20 Oct 2015 06:01:14 +0000", 
    "date_sent": null, 
    "account_sid": "AccountSid", 
    "to": "+91999999999", 
    "from": "+18989898989", 
    "body": "I am trying to send a message having characters more than 160. But twilio allows concatenated messages upto 1600 characters length, i thought i should give it a try. So i wrote this weird message.", 
    "status": "queued", 
    "num_segments": "2", 
    "num_media": "0", 
    "direction": "outbound-api", 
    "api_version": "2010-04-01", 
    "price": null, 
    "price_unit": "USD", 
    "error_code": null, 
    "error_message": null, 
    "uri": "/2010-04-01/Accounts/AccountSid/Messages/SM745b97dcb56a4f9f82c52242ca3b5e92.json", 
    "subresource_uris": { 
    "media": "/2010-04-01/Accounts/AccountSid/Messages/SM745b97dcb56a4f9f82c52242ca3b5e92/Media.json" 
    } 
} 
+0

我不確定你在問什麼。該API返回JSON,但PHP SDK將其封裝在對象中,以便在應用程序中處理。 – philnash

回答

1

Ricky從Twilio在這裏。

Services_Twilio_Rest_Message對象有一個toString method,它將返回json表示形式對象。如果你只是要輸出的JSON用於調試你可以呼應迴應你:

$message = $client->account->messages->create(array(
    "From" => "XXX-XXX-XXXX", 
    "To" => "XXX-XXX-XXXX", 
    "Body" => "Test message!", 
)); 

echo $message; 

如果你需要存儲在一個變量,你可以在字符串顯式轉換$消息字符串:

$json = (string)$message; 

希望有幫助!

+0

這沒有幫助 –

+0

對不起,在這種情況下,我可能不完全理解你的問題。 toString方法給你的json與你想要返回的東西之間有一個delta嗎? – rickyrobinett