使用Twilio发送短信,以及发送短信时 在我的表单中使用阿拉伯语号码电话,它无法发送短信并显示以下异常。
我理解我是否像这样使用英语
+962772211755 有效
但是在阿拉伯语中
+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)
答案 0 :(得分:3)
这是我的工作示例,并将数字转换为英语 用很长的时间解析它,我不知道它为什么会起作用并转换成英文,
/**
* 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