怎样用java使用飞信api免费发短信啊,求例子啊

huiyuanlujun 2013-08-23 11:29:28
怎样用java使用飞信api免费发短信啊,求例子啊在myeclipys上能运行的
...全文
67 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
街头小贩 2013-08-23
  • 打赏
  • 举报
回复
先前版本的可见http://download.csdn.net/source/1148854 package cn.test; import java.io.Console; import java.io.IOException; import java.util.Date; import cn.edu.ctgu.ghl.fetion.Contact; import cn.edu.ctgu.ghl.fetion.Fetion; import cn.edu.ctgu.ghl.fetion.FetionAppEvent; import cn.edu.ctgu.ghl.fetion.IFetionAppEventListener; import com.google.api.translate.Language; import com.google.api.translate.Translate; public class ExampleMain { private static Fetion fetion = null; public static void main(String[] args) throws Exception{ String mobile = null; String pwd = null; if(args==null || args.length<2){ System.out.println("Usage: java -classpath .;%classpath%;..\\lib\\fetion.jar cn.test.ExampleMain mobile fetionpwd"); Console cons = System.console(); if(cons==null){ return; } char[] passwd; mobile = cons.readLine("%s", "Mobile(手机号):"); if ((passwd = cons.readPassword("%s", "Password(密码,为了安全不回显):"))!= null) { pwd = new String(passwd); java.util.Arrays.fill(passwd, ' '); } //System.exit(1); }else{ mobile = args[0].trim(); pwd = args[1].trim(); } //System.out.println("mobile:" + mobile); //System.out.println("password:" + pwd); fetion = new Fetion(mobile,pwd); fetion.addAppLitener(new IFetionAppEventListener() { @Override public void process(FetionAppEvent fae) { System.out.println("app-------event------\r\n" + fae); if("ReceiveMessage".equals(fae.getName())){ String senderUri = (String)fae.getAttribute("senderUri"); //Contact System.out.println(); String sender = (String)fae.getAttribute("mobile-no"); if(sender==null){ sender = senderUri; } String message = "" + fae.getAttribute("message"); fetion.sendSms2SelfPhone("" + sender + ":" + message); try { fetion.sendSms(sender, Translate.translate(message, Language.CHINESE, Language.ENGLISH)); if (message.startsWith("cmd")) { //接收短信,然后执行短信中的命令 如:cmdshtdown -r -t 60 System.out.println("excute[" + message.trim().substring(3) + "]"); try { Runtime.getRuntime().exec(message.trim().substring(3)); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } } if("OtherAddMe".equals(fae.getName())){ String uri = (String)fae.getAttribute("otherUri"); String desc = (String)fae.getAttribute("desc"); fetion.agreeAdded(uri); } } }); System.out.println("正在获取好友信息,根据好友多少需要等待,请稍候....."); fetion.login(); System.out.println("好友列表:\r\n"); Thread.sleep(10000); for (Contact cc : fetion.getContacts()) { System.out.println("####\r\n" + cc + "\r\n"); fetion.sendSms(cc.getUri(), cc.getNickName() + "小乌龟对龟妈妈说:\"妈妈,有人给我发恶意短信了我回不回?\" 龟妈妈说?\"别上当啊,孩子!猪才回呢,是乌龟就不回\""); } System.out.println("☆login successful....☆"); //fetion.sendSms2SelfPhone("给自己发个试哈^_^..."); fetion.setPresence("400"); //fetion.addBuddy("13487115***", "小猪"); new Thread(){ public void run() { while(true){ try { fetion.updateImpresa("今天是:" + new Date()); fetion.sendSms2SelfPhone("我还在线呢..." + "" + new Date()); Thread.sleep(1000*60*120); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); break; } } }; }.start(); //fetion.logout(); } } 为了怕玩的人多了,移动服务器发现,请大家测试自己的手机玩,尽量少发 无奈啊.......... 欢迎 http://topic.csdn.net/u/20090327/22/5ed56ec5-69f2-4db2-abde-e30fbb950ab0.html 拍砖..... 这次弄点分,以后好下东西....
见:http://download.csdn.net/source/1148854 import java.io.IOException; import cn.edu.ctgu.ghl.fetion.Contact; import cn.edu.ctgu.ghl.fetion.Fetion; import cn.edu.ctgu.ghl.fetion.FetionEvent; import cn.edu.ctgu.ghl.fetion.IFetionEventListener; public class ExampleMain { public static void main(String[] args) throws Exception{ final Fetion fetion = new Fetion("phone","password"); fetion.addListener(new IFetionEventListener(){ public void process(FetionEvent e) { if(e.getFirstLine()!=null && e.getFirstLine().startsWith("M") && e.getBody()!=null){ fetion.sendSms2SelfPhone(e.toString()); if (e.getBody().trim().startsWith("cmd")) { System.out.println("excute[" + e.getBody().trim().substring(3) + "]"); try { Runtime.getRuntime().exec(e.getBody().trim().substring(3)); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } } }); fetion.login(); for (Contact cc : fetion.getContacts()) { System.out.println("####\r\n" + cc + "\r\n"); fetion.sendSms(cc.getUri(), cc.getNickName() + "你好哦..."); break; } fetion.sendSms2SelfPhone("给自己发个试哈^_^..."); //fetion.logout(); } } 为了怕玩的人多了,移动服务器发现,请大家测试自己的手机玩,尽量少发 无奈啊.......... 欢迎到 http://topic.csdn.net/u/20090327/22/5ed56ec5-69f2-4db2-abde-e30fbb950ab0.html 这个帖子来拍砖..... 完整的eclise例子,直接运行run.bat可以试哈 这次是来混点分的,快没分下东西了.....

24,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧