当前位置: 首页>>代码示例>>Java>>正文


Java TwilioRestResponse类代码示例

本文整理汇总了Java中com.twilio.sdk.TwilioRestResponse的典型用法代码示例。如果您正苦于以下问题:Java TwilioRestResponse类的具体用法?Java TwilioRestResponse怎么用?Java TwilioRestResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TwilioRestResponse类属于com.twilio.sdk包,在下文中一共展示了TwilioRestResponse类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendNotification

import com.twilio.sdk.TwilioRestResponse; //导入依赖的package包/类
public Hashtable sendNotification(Notification notification, Device device) throws NotificationException {
	try {
		if (!(device instanceof TwilioDevice)) {
			throw new NotificationException(NotificationException.NOT_ACCEPTABLE, "Supplied device is not a Twilio device");
		}

		String message = "You have a new notification from " + notification.getSender() + ".  The subject is " + notification.getSubject()
				+ ".  The message is " + notification.getMessages()[0].getMessage() + ".";
		String url = "http://twimlets.com/message?Message%5B0%5D=" + URLEncoder.encode(message);

		TwilioDevice twilio = (TwilioDevice) device;

		String accountSid = BrokerFactory.getConfigurationBroker().getStringValue("twilio.sid");
		String authToken = BrokerFactory.getConfigurationBroker().getStringValue("twilio.token");
		
		BrokerFactory.getLoggingBroker().logDebug("Sid="+accountSid);
		BrokerFactory.getLoggingBroker().logDebug("token="+authToken);
		TwilioRestClient client = new TwilioRestClient(accountSid, authToken);
		
		Map<String, String> params = new HashMap<String, String>();
		params.put("To", twilio.getPhoneNumber());
		params.put("From", BrokerFactory.getConfigurationBroker().getStringValue("twilio.phone.from", "(720)530-8877"));
		params.put("Url", url);

		TwilioRestResponse response;
		response = client.request("/" + APIVERSION + "/Accounts/" + client.getAccountSid() + "/Calls", "POST", params);
		if (response.isError())
			System.out.println("Error making outgoing call: " + response.getHttpStatus() + "\n" + response.getResponseText());
		else {
			BrokerFactory.getLoggingBroker().logDebug(response.getResponseText());
		}

		Hashtable<String, String> tracking = new Hashtable<String, String>();
		tracking.put("ID", "");
		return tracking;

	} catch (TwilioRestException e) {
		// TODO Auto-generated catch block
		throw new NotificationException(400, e.getErrorMessage());
	}
}
 
开发者ID:davidrudder23,项目名称:OpenNotification,代码行数:42,代码来源:TwilioNotificationProvider.java


注:本文中的com.twilio.sdk.TwilioRestResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。