2016-12-17 55 views
2

Twillio在查找電話號碼時返回一個擁有私有屬性的對象。右下面的代碼我使用twillio電話號碼查詢sdk5x

function isValidNumber($number) { 
    try{ 
     $obj = $this->client->lookups->phoneNumbers($number)->fetch(); 
     return $obj; 
    }catch(Twilio\Exceptions\RestException $e){ 
     return false; 
    } 
} 

這是我得到

object(Twilio\Rest\Lookups\V1\PhoneNumberInstance)#23 (4) { 
    ["properties":protected]=> 
    array(6) { 
    ["callerName"]=> 
    NULL 
    ["countryCode"]=> 
    string(2) "LK" 
    ["phoneNumber"]=> 
    string(12) "+94xxxxxxxx" 
    ["nationalFormat"]=> 
    string(12) "xxxxxxxxxx" 
    ["carrier"]=> 
    NULL 
    ["addOns"]=> 
    NULL 
    } 
    ["solution":protected]=> 
    array(1) { 
    ["phoneNumber"]=> 
    string(11) "94xxxxxxxxx" 
    } 
} 

是有一個優雅的方式來獲得phoneNumber的關鍵出結果的片段?此外,嘗試捕捉似乎也沒有幫助,只要一個無效的條目進入,異常都在這個地方。我正在使用SDK 5x

回答

0

如果有人由於缺乏示例而沒有那麼多有用的文檔,我想出了一些非常簡單的東西。這不是在所有的優雅,但現在幹得

file_get_contents('https://'.$sid.':'.$auth_token.'@lookups.twilio.com/v1/PhoneNumbers/'.urlencode($number)); 
+0

PS的工作 - 捲曲是去,如果由於某種原因你離開了沒有捲曲的方式,這實際工作。 –