com.twilio.sdk.TwilioRestException:'To'号+??????????????不是有效的 phone 号码

com.twilio.sdk.TwilioRestException: The 'To' number +???????????? is not a valid phone number

我正在使用 Twilio 发送短信,当有人 在我的表单中使用 arabic 数字 phone,它无法发送短信并显示以下异常。

如果我这样使用 english 我明白了

+962772211755 有效

但是阿拉伯语

+٩٦٢٧٧٢٢١١٧٥٥ 剂量 无效

并显示异常

com.twilio.sdk.TwilioRestException: The 'To' number +???????????? is not a valid phone number.
    at com.twilio.sdk.TwilioRestException.parseResponse(TwilioRestException.java:74)
    at com.twilio.sdk.TwilioClient.safeRequest(TwilioClient.java:497)
    at com.twilio.sdk.resource.list.MessageList.create(MessageList.java:70)

这是我的工作示例,并将数字转换为英语 用长解析它,我不知道它为什么有效并转换为英语,

/**
     * this method simplest way to send SMS with no threading
     *
     * @param userSms
     * @param toNumber e.g +12246193820
     * @param body
     */
    public static void sendSMS(UserSms userSms, String toNumber, String body) {
        TwilioRestClient client = new TwilioRestClient(userSms.getAccountSid(), userSms.getAuthToken());

        //to solve if arabic numbers was submitted and avoid exceptiono
        // com.twilio.sdk.TwilioRestException: The 'To' number +???????????? is not a valid phone number.
        long phoneNumber = Long.parseLong(toNumber.replace("+", ""));// remove plus just in case cause strange parse is working ! with +s
        // Build a filter for the MessageList
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("Body", body));
        params.add(new BasicNameValuePair("To", toNumber));// in TRIAL VERSION works only with verified number with trial account
        params.add(new BasicNameValuePair("From", userSms.getFromNumber()));// for test use the one created from twilio

        MessageFactory messageFactory = client.getAccount().getMessageFactory();
        Message message;
        try {
            message = messageFactory.create(params);
            // Get an object from its sid. If you do not have a sid,
            // check out the list resource examples on this page
            message = client.getAccount().getMessage(message.getSid());
            //store to log
            SmsService.saveSmsLog(message, userSms, body);

        } catch (TwilioRestException ex) {
            Logger.getLogger(SmslUtil.class.getName()).log(Level.SEVERE, "send sms exception", ex);
        }

    }

这里是 java 例子来证明这一点 ;D Example of parsing arabic and its on my production now