twillio phone 数字查找 sdk5x

twillio phone number lookup sdk5x

Twillio returns 一个在查找 phone 数字时分配私有属性的对象。下面是我使用的代码

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 键?此外,try catch 似乎也无济于事,一旦输入无效条目,异常就会到处都是。我正在使用 SDK 5x

如果有人因为缺少示例和没有太多有用的文档而陷入困境,我想出了一些非常简单的方法。这一点都不优雅,但现在完成工作

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