Flex使用ribbit.com的服务给手机发送短信SMS

阅读更多

http://www.ribbit.com/ 可以将语音通信和丰富的功能集成到您的网站,应用或社区。

这里说一下使用 ribbit.com 的服务免费给手机发短信。(目前只支持美国手机号)

1. 访问 www.ribbit.com 注册并下载 Flex 的类库 RibbitAPI_2.5.0.1070_FX3_CS4.swc

2. 创建Flex项目,并引入下载的RibbitAPI_2.5.0.1070_FX3_CS4.swc

3. 要免费使用www.ribbit.com的服务,需要以下信息, 大部分在My Profile中能看到

  • user id: 就是登录名,通常是一个邮箱
  • password: 登录的密码
  • developer id: My Profile面板中Developer ID的值
  • application id: 点击My Apps -> Start an App, 注册你的app项目,App URL可以填写你自己GAE site的地址。注册成功后就能看到App ID了,通常是用户名和项目名的组合。

 

4. 下面是代码

 



	
	
		[CDATA[
			import mx.controls.Alert;
			import mx.messaging.channels.StreamingAMFChannel;
			import com.ribbit.api.interfaces.IMessageManager;
			import com.ribbit.api.interfaces.IAuthenticationManager;
			import com.ribbit.api.events.MessageEvent;
			import com.ribbit.api.events.AuthenticationEvent;
			import com.ribbit.api.objects.LoginParam;
			
			private static const userid : String = "Your User ID";
			
			private static const password : String = "Your Password";
			
			private static const devHandle : String = "Your Developer ID";
			
			private static const applicationId : String = "Your App ID";
			
			private var loginObject:LoginParam; 
			
			public function init():void{
				request.authenticationManager.addEventListener(AuthenticationEvent.LOGGING_IN, handleAuthEvent);
				request.authenticationManager.addEventListener(AuthenticationEvent.LOGGED_IN, handleAuthEvent);
				request.authenticationManager.addEventListener(AuthenticationEvent.LOGGED_OUT, handleAuthEvent);
				request.authenticationManager.addEventListener(AuthenticationEvent.ERROR, authError);
				
				request.addEventListener(MessageEvent.MESSAGE_SENT, handleMessageSent);

				// login
				request.login(userid, password, devHandle, applicationId, loginObject);

				initEventListeners();
	                }

			private function initEventListeners():void{
				smsSubmit.addEventListener(MouseEvent.CLICK, retrieveTextInfo); 
			}
			
			private function retrieveTextInfo(event:MouseEvent):void{
				//原文作者在这里有个小错误,他将message和subject的参数位置写颠倒了
				sendSMS(cellNumber.text, message.text, subject.text);
			}
			
	        private function sendSMS(mobileNumber:String, message:String, subject:String=""):void{
	            request.messageManager.sendSmsMessage(mobileNumber, message, subject);
	        }
	        
	        private function handleAuthEvent(event:AuthenticationEvent):void{
	            switch(event.type){
		            case AuthenticationEvent.LOGGED_IN:
		                loginStatus.text = "Logged In OK!";
		                smsSubmit.enabled = true;
		                break;
		            case AuthenticationEvent.LOGGING_IN:
		                loginStatus.text = "Logging In...";
		                break;
				}
	        }
	        
	        private function handleMessageSent(event:MessageEvent):void{
	            Alert.show("Message has been sent");
	        }
	        
	        private function authError(event:AuthenticationEvent):void{
	            loginStatus.text = "Login Error";
	            Alert.show("Auth Error:" + event.data);
	        }

		]]
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
 

经过测试确实可以给美国手机发短信(T-Mobile的号码)

短信内容一般为 [email protected] / subject / content

 

原作 http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&postid=12007&loc=en_US&productid=2

你可能感兴趣的:(Flex,GAE,Mobile,Adobe,XML)