凌霄电话家园
回拨 美国虚拟号 SIP 签到 回拨平台 美国VPN 网络电话

当前位置: 主页 > VOIP基础知识 >

Flex使用ribbit.com给手机发送免费短信

时间:2010-06-04 17:50 来源:javaeye.com 作者:wangcheng 点击:
Ribbit可以将语音通信和丰富的功能集成到您的网站,应用或社区。这里说一下使用ribbit.com 的服务免费给手机发短信。

Ribbit Corporation硅谷一家电话公司,成立于2006年2月。Ribbit是一个基于云计算的网络电话服务,具有网络通话、智能呼叫路由和语音邮件转 录功能。Ribbit和Google Voice一样,也向用户提供一个免费的电话号码(美国虚拟号码),可以免费拨打美国和加拿大,也可以免费接听来电。[详细]

下面说一下使用 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了,通常是用户名和项目名的组合。
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. < mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"   
  3.     xmlns:ribbit="com.ribbit.api.*"    
  4.     width="346" height="244"    
  5.     backgroundGradientAlphas="[1.0, 1.0]"    
  6.     backgroundGradientColors="[BFE4EF, B3BCCF]"   
  7.     creationComplete="init()">   
  8.        
  9.     <mx:Script>   
  10.         [CDATA[   
  11.             import mx.controls.Alert;   
  12.             import mx.messaging.channels.StreamingAMFChannel;   
  13.             import com.ribbit.api.interfaces.IMessageManager;   
  14.             import com.ribbit.api.interfaces.IAuthenticationManager;   
  15.             import com.ribbit.api.events.MessageEvent;   
  16.             import com.ribbit.api.events.AuthenticationEvent;   
  17.             import com.ribbit.api.objects.LoginParam;   
  18.                
  19.             private static const userid : String = "Your User ID e.g. lxvoip";   
  20.                
  21.             private static const password : String = "Your Password";   
  22.                
  23.             private static const devHandle : String = "Your Developer ID e.g. lxvoip";   
  24.                
  25.             private static const applicationId : String = "Your App ID";   
  26.                
  27.             private var loginObject:LoginParam;    
  28.                
  29.             public function init():void{   
  30.                 request.authenticationManager.addEventListener(AuthenticationEvent.LOGGING_IN, handleAuthEvent);   
  31.                 request.authenticationManager.addEventListener(AuthenticationEvent.LOGGED_IN, handleAuthEvent);   
  32.                 request.authenticationManager.addEventListener(AuthenticationEvent.LOGGED_OUT, handleAuthEvent);   
  33.                 request.authenticationManager.addEventListener(AuthenticationEvent.ERROR, authError);   
  34.                    
  35.                 request.addEventListener(MessageEvent.MESSAGE_SENT, handleMessageSent);   
  36.    
  37.                 // login   
  38.                 request.login(userid, password, devHandle, applicationId, loginObject);   
  39.    
  40.                 initEventListeners();   
  41.                     }   
  42.    
  43.             private function initEventListeners():void{   
  44.                 smsSubmit.addEventListener(MouseEvent.CLICK, retrieveTextInfo);    
  45.             }   
  46.                
  47.             private function retrieveTextInfo(event:MouseEvent):void{   
  48.                 //原文作者在这里有个小错误,他将message和subject的参数位置写颠倒了   
  49.                 sendSMS(cellNumber.text, message.text, subject.text);   
  50.             }   
  51.                
  52.             private function sendSMS(mobileNumber:String, message:String, subject:String=""):void{   
  53.                 request.messageManager.sendSmsMessage(mobileNumber, message, subject);   
  54.             }   
  55.                
  56.             private function handleAuthEvent(event:AuthenticationEvent):void{   
  57.                 switch(event.type){   
  58.                     case AuthenticationEvent.LOGGED_IN:   
  59.                         loginStatus.text = "Logged In OK!";   
  60.                         smsSubmit.enabled = true;   
  61.                         break;   
  62.                     case AuthenticationEvent.LOGGING_IN:   
  63.                         loginStatus.text = "Logging In...";   
  64.                         break;   
  65.                 }   
  66.             }   
  67.                
  68.             private function handleMessageSent(event:MessageEvent):void{   
  69.                 Alert.show("Message has been sent");   
  70.             }   
  71.                
  72.             private function authError(event:AuthenticationEvent):void{   
  73.                 loginStatus.text = "Login Error";   
  74.                 Alert.show("Auth Error:" + event.data);   
  75.             }   
  76.    
  77.         ]]   
  78.     </mx:Script>   
  79.        
  80.     <ribbit:RibbitServices id="request"/>   
  81.        
  82.     <mx:Label x="21" y="16" text="Cell Number" fontSize="12"/>   
  83.     <mx:TextInput id="cellNumber" x="110" y="16" width="221"/>   
  84.        
  85.     <mx:Label x="20" y="44" text="SMS Subject" fontSize="12"/>   
  86.     <mx:TextInput id="subject" x="110" y="44" width="221"/>   
  87.        
  88.     <mx:Label x="16" y="72" text="SMS Content" fontSize="12"/>   
  89.     <mx:TextArea id="message" x="110" y="73" width="221" height="124"/>   
  90.        
  91.     <mx:Button id="smsSubmit" x="110" y="205" label="Send SMS" enabled="false"/>   
  92.        
  93.     <mx:Label id="loginStatus" x="198" y="207" width="133" textAlign="right"/>   
  94.        
  95. </mx:Application>  

 

相关标签:ribbit(3) 凌霄电话家园

    
    赞助商
    
    关于本站 | 广告服务 | 网站地图 | RSS地图 | Tag标签 | 联系我们 |