Package net.solosky.maplefetion

Examples of net.solosky.maplefetion.FetionClient


  private FetionClient client;
  private SMSListener listener;
 
  public FetionGateway(long mobile, String pass)
  {
    this.client = new FetionClient(Long.toString(mobile), pass, this);
  }
View Full Code Here


    while(true) {
        String line = reader.readLine();
        if(!this.dispatch(line)) {
          Iterator<FetionClient> it = this.clientList.iterator();
          while(it.hasNext()) {
            FetionClient client = it.next();
            if(client.getState()==ClientState.ONLINE) {
              client.logout();
            }
          }
          this.sharedTimer.reallyStopTimer();
          this.shareExecutor.reallyStopExecutor();
          break;
View Full Code Here

  {
    println("当前飞信池的客户端:");
    Iterator<FetionClient> it = this.clientList.iterator();
    int i = 0;
    while(it.hasNext()) {
      FetionClient client = it.next();
      println("["+(i++)+"]  "+client.getFetionUser().getDisplayName()+"("+client.getFetionUser().getMobile()+")    " + client.getState().name());
    }
  }
View Full Code Here

     * @param string
     */
    private void del(String s)
    {
      Integer i = Integer.parseInt(s);
      FetionClient client = this.clientList.get(i);
      if(client!=null) {
        if(client.getState()==ClientState.ONLINE) {
          println("正在退出 "+client.getFetionUser().getDisplayName()+"..");
          client.logout();
        }
        this.clientList.remove(i);
      }
     
    }
View Full Code Here

     * @param string
     * @param string2
     */
    private void add(String mobile, String password)
    {
      FetionClient client = new FetionClient(mobile, password);
      FetionPoolListener listener = new FetionPoolListener(client);
      client.setNotifyEventListener(listener);
      client.setFetionExecutor(this.shareExecutor);
      client.setFetionTimer(this.sharedTimer);
      client.setTransferFactory(this.transferFactory);
      this.clientList.add(client);
      println("已经添加 "+mobile +"..");
    }
View Full Code Here

     * @param string
     */
    private void logout(String s)
    {
      Integer i = Integer.parseInt(s);
      FetionClient client = this.clientList.get(i);
      if(client!=null && client.getState()==ClientState.ONLINE) {
        println("正在退出 "+client.getFetionUser().getDisplayName()+"..");
        client.logout();
      }
    }
View Full Code Here

     * @param string
     */
    private void login(String s)
    {
      Integer i = Integer.parseInt(s);
      FetionClient client = this.clientList.get(i);
      if(client!=null && client.getState()!=ClientState.ONLINE) {
        println("正在登陆 "+client.getFetionUser().getDisplayName()+"..");
        client.login();
      }
    }
View Full Code Here

    * @param pass
    */
 
  public MapleFetion(String serviceId, String pass)
  {
    this.client = new FetionClient(serviceId, pass,
        this,
        new AutoTransferFactory(),
        new SimpleFetionStore(),
        new ThreadTimer(),
        new SingleExecutor());
View Full Code Here

  public static void main(String[] args) {
    if(args.length<4){
      System.out.println("参数不正确。参数格式为:手机号 密码 发送消息的手机号 消息内容");
      System.out.println("说明:可以给指定的手机号码发送消息然后退出,前提是这个手机号码的飞信用户是你的好友,否则会发送失败。");
    }else{
      final FetionClient client = new FetionClient(args[0], args[1]);
      System.out.println("正在登录中,可能需要1分钟左右,请稍候...");
     
      //这里设置一个登录状态监听器,可以显示当前登录步骤,避免用户感到焦虑
      client.setNotifyEventListener(new NotifyEventListener() {
        public void fireEvent(NotifyEvent event)
        {
          System.err.println(event.toString());
          //如果出现验证码,取消登录
          if(event.getEventType()==NotifyEventType.IMAGE_VERIFY) {
            System.out.println("当前登录过程或者操作需要验证,操作失败。");
            client.cancelVerify((ImageVerifyEvent) event);
          }
        }
      });
      //禁用掉群,登录可以变得快一点
      client.enableGroup(false);   
     
      //这里为了编程方便使用了同步登录,当然推荐异步登录,使用登录状态回调函数来完成登录成功后的操作
      LoginState state = client.syncLogin();
      if(state==LoginState.LOGIN_SUCCESS){  //登录成功
        System.out.println("登录成功,正在发送消息至 "+args[2]+",请稍候...");                     
         
        ActionEventFuture future = new ActionEventFuture()//建立一个Future来等待操作事件     
        client.sendChatMessage(Long.parseLong(args[2]), new Message(args[3]), future);
        ActionEvent event = future.waitActionEventWithoutException()//等待操作完成事件
        switch(event.getEventType()){
         
          case SUCCESS:
            SendChatMessageSuccessEvent evt = (SendChatMessageSuccessEvent) event;
            if(evt.isSendToMobile()){
              System.out.println("发送成功,消息已通过短信发送到对方手机!");
            }else if(evt.isSendToClient()){
              System.out.println("发送成功,消息已通过服务直接发送到对方客户端!");
            }
            break;
           
          case FAILURE:
            FailureEvent evt2 = (FailureEvent) event;
            switch(evt2.getFailureType()){
              case BUDDY_NOT_FOUND:
                System.out.println("发送失败, 该用户可能不是你好友,请尝试添加该用户为好友后再发送消息。");
                break;
              case USER_NOT_FOUND:
                System.out.println("发送失败, 该用户不是移动用户。");
                break;
              case SIPC_FAIL:
                System.out.println("发送失败, 服务器返回了错误的信息。");
                break;
              case UNKNOWN_FAIL:
                System.out.println("发送失败, 不知道错在哪里。");
               
              case REQEUST_FAIL:
                RequestFailureEvent evt3 = (RequestFailureEvent) event;
                System.out.println("提示:"+evt3.getReason()+", 更多信息请访问:"+evt3.getReason());
               
              default:
                System.out.println("发送消息失败!"+event.toString());
            }
            break;
         
          /* 以下三个错误状态是在异步发送消息的情况才会发生,
           * 为了方便处理,使用waitActionEventWithException()同步的情况下,这三个错误是通过异常来处理的
           * 也就是在waitActionEvent的时候就会判断是否出现了这三个错误,如果出现了就会抛出相应的异常
           * 而waitActionEventWithoutException()不会抛出异常,会把这些错误作为操作事件返回
           */
          case SYSTEM_ERROR:
            System.out.println("发送失败, 客户端内部错误。");
            break;
          case TIMEOUT:
            System.out.println("发送失败, 超时");
            break;
          case TRANSFER_ERROR:
            System.out.println("发送失败, 超时");
       
             
              //无论发送成功还是失败,因为登录了,就必须退出,释放线程资源,否则客户端不会主动退出
              //如果登录失败了,客户端会主动释放线程资源,不需要退出
              System.out.print("正在退出客户端...");
              client.logout();
              System.out.println("已经退出。");
             
      }else if(state==LoginState.SSI_AUTH_FAIL){
        System.out.println("你输入的手机号或者密码不对,请检查后重试!");
      }else if(state==LoginState.SSI_CONNECT_FAIL){
View Full Code Here

TOP

Related Classes of net.solosky.maplefetion.FetionClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.