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. 下面是代码
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
xmlns:ribbit="com.ribbit.api.*"
width="346" height="244"
backgroundGradientAlphas="[1.0, 1.0]"
backgroundGradientColors="[#BFE4EF, #B3BCCF]"
creationComplete="init()">
<mx:Script>
[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);
}
]]
</mx:Script>
<ribbit:RibbitServices id="request"/>
<mx:Label x="21" y="16" text="Cell Number" fontSize="12"/>
<mx:TextInput id="cellNumber" x="110" y="16" width="221"/>
<mx:Label x="20" y="44" text="SMS Subject" fontSize="12"/>
<mx:TextInput id="subject" x="110" y="44" width="221"/>
<mx:Label x="16" y="72" text="SMS Content" fontSize="12"/>
<mx:TextArea id="message" x="110" y="73" width="221" height="124"/>
<mx:Button id="smsSubmit" x="110" y="205" label="Send SMS" enabled="false"/>
<mx:Label id="loginStatus" x="198" y="207" width="133" textAlign="right"/>
</mx:Application>
经过测试确实可以给美国手机发短信(T-Mobile的号码)
短信内容一般为 rabbit@rabbit.com / subject / content
本文介绍如何利用Ribbit.com提供的服务,在Flex项目中实现免费向美国手机号发送短信的功能。通过注册账号并获取必要的认证信息,开发者可以轻松集成短信发送功能。
1080

被折叠的 条评论
为什么被折叠?



