我试图在我的 GWT 应用程序中使用 Twilio 的官方 Java 库来发送文本消息。
这是我在应用程序中使用的 Twilio 代码:
public class TwilioSMS{
/** The Constant ACCOUNT_SID. */
public static final String ACCOUNT_SID = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
public static final String AUTH_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxxx";
// Create a rest client
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
/**
* The main method.
*
* @param args
* the arguments
* @throws TwilioRestException
* the twilio rest exception
*/
public String sendMessage(String _to, String _message) throws TwilioRestException
{
// Get the main account (The one we used to authenticate the client
Account mainAccount = client.getAccount();
// Send an sms
SmsFactory smsFactory = mainAccount.getSmsFactory();
Map<String, String> smsParams = new HashMap<String, String>();
smsParams.put("To", _to); // Replace with a valid phone number
smsParams.put("From", "(646) 755-7665"); // Replace with a valid phone // number in your account
smsParams.put("Body", _message);
smsFactory.create(smsParams);
// Make a raw request to the api.
TwilioRestResponse resp = client.request("/2010-04-01/Accounts", "GET",
null);
if (!resp.isError()) {
return resp.getResponseText();
}
else
{
return "Failed to send the message.";
}
}
}
当我在 GAE 中运行代码时,出现以下异常:
java.lang.NoClassDefFoundError: javax.net.ssl.KeyManagerFactory is a restricted class. Please see the Google App Engine developer's guide for more details.
我确实意识到有一个 gwt-twilio http://code.google.com/p/gwt-twilio/ 但这是 twilio 客户端的包装器(它不处理发送短信)
任何在 GAE+GWT 中使用 twilio 发送文本消息的示例都有帮助!
谢谢
坤