【问题标题】:Is there any way to retrieve type or price of available phone number?有没有办法检索可用电话号码的类型或价格?
【发布时间】:2016-11-12 13:11:25
【问题描述】:

假设我只有 number 和 isoCountry 例如:

    String number = +43720116398;
    String isoCountry = "AT";

我正在尝试在购买前确定价格或类型。 我想知道那个号码是 LOCAL、MOBILE 还是 TOLL_FREE。

可悲的是,查找客户端在这种情况下不起作用:

  public static void main(String[] args) throws TwilioRestException {
    LookupsClient client = new LookupsClient(ACCOUNT_SID, AUTH_TOKEN);
    PhoneNumber number = client.getPhoneNumber(number , true);
    System.out.println(number.getType());
  }

它返回不同类型的类型或空值。 如果我能得到也会让我满意的传入电话号码的类型/价格。 有什么办法吗?

【问题讨论】:

    标签: twilio twilio-api


    【解决方案1】:

    在我的情况下,我知道该号码是 LOCAL 或 MOBILE,所以我只需检查这个具有 LOCAL 类型的号码是否存在,如果它不存在 MOBILE,您可以轻松添加检查它的 TOLL_FREE 或 MOBILE 如果您愿意。 如果有人在几天内提供更清洁的方法,我会很乐意接受他的回答,否则我会接受我的。

    可运行示例:

    public class Main {
        private final static String MOBILE = "MOBILE";
        private final static String LOCAL = "LOCAL";
        private static TwilioRestClient twilioRestClient = new TwilioRestClient("Key", "key");
    
        public static void main(String[] args) {
            String number = "+43720116398";
            String isoCountry = "AT";
            getMsisdnType(number, isoCountry);
        }
    
    
        public static String getMsisdnType(String msisdn, String isoCountry) {
            Map<String, String> params = new HashMap<>();
            params.put("Contains", msisdn);
            Optional<AvailablePhoneNumber> number = twilioRestClient.getAccount().getAvailablePhoneNumbers(params, isoCountry, LOCAL).getPageData().stream().findAny();
            if (number.isPresent()) return LOCAL;
            return MOBILE;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-02
      • 1970-01-01
      • 2018-12-12
      • 1970-01-01
      • 1970-01-01
      • 2012-05-03
      • 1970-01-01
      相关资源
      最近更新 更多