Ejemplo n.º 1
0
  /** 订阅异步通知 */
  public SipcRequest createSubscribeRequest() {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SUBSCRIBE);
    req.addHeader(SipcHeader.EVENT, "PresenceV4");
    req.setBody(new SipcBody(MessageTemplate.TMPL_SUBSCRIBE));

    return req;
  }
Ejemplo n.º 2
0
  /** 建立新的分组 */
  public SipcRequest createCreateCordRequest(String title) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SERVICE);
    req.addHeader(SipcHeader.EVENT, "CreateBuddyList");

    req.setBody(new SipcBody(MessageTemplate.TMPL_CREATE_CORD.replace("{title}", title)));
    return req;
  }
Ejemplo n.º 3
0
  /**
   * 获取个人详细信息
   *
   * @return
   */
  public SipcRequest createGetPersonalInfoRequest() {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SERVICE);
    req.addHeader(SipcHeader.EVENT, "GetPersonalInfo");
    req.setBody(new SipcBody(MessageTemplate.TMPL_GET_PERSONAL_INFO));

    return req;
  }
Ejemplo n.º 4
0
  /** 确认会话收到请求 */
  public SipcRequest createAckRequest(String uri) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.ACK);
    req.addHeader(SipcHeader.TO, uri);

    req.setNeedReplyTimes(0);
    return req;
  }
Ejemplo n.º 5
0
 /**
  * 发送聊天消息
  *
  * @param buddy 消息发往的好友对象
  * @param message 消息正文
  * @param listener 操作监听器
  * @throws TransferException
  */
 public void sendChatMessage(Buddy buddy, Message message, ActionEventListener listener) {
   this.ensureOpened();
   SipcRequest request =
       this.getMessageFactory().createSendChatMessageRequest(buddy.getUri(), message);
   request.setResponseHandler(new SendChatMessageResponseHandler(context, this, listener));
   this.process(request);
 }
Ejemplo n.º 6
0
  /**
   * 用户登录验证
   *
   * @return
   */
  public SipcRequest createUserAuthRequest(
      SipcHeader wwwHeader, int presence, boolean isSupportedMutiConnection, StoreVersion version) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.REGISTER);

    Pattern pt =
        Pattern.compile(
            "Digest algorithm=\"SHA1-sess-v4\",nonce=\"(.*?)\",key=\"(.*?)\",signature=\"(.*?)\"");
    Matcher mc = pt.matcher(wwwHeader.getValue());
    if (mc.matches()) {
      String passHex =
          PasswordEncrypterV4.encryptV4(this.user.getUserId(), this.user.getPassword());
      AuthGeneratorV4 auth = new AuthGeneratorV4();
      String aeskey = ConvertHelper.byte2HexStringWithoutSpace(user.getAesKey());
      String response = auth.generate(mc.group(2), passHex, mc.group(1), aeskey);
      String authString = "Digest response=\"" + response + "\",algorithm=\"SHA1-sess-v4\"";
      req.addHeader(SipcHeader.AUTHORIZATION, authString);
      req.addHeader("AK", "ak-value");

      String body = MessageTemplate.TMPL_USER_AUTH;
      body = body.replace("{machineCode}", FetionConfig.getString("fetion.sip.machine-code"));
      body = body.replace("{sid}", Integer.toString(this.user.getFetionId()));
      body = body.replace("{userId}", Integer.toString(this.user.getUserId()));
      body = body.replace("{presence}", Integer.toString(presence));
      body = body.replace("{personalVersion}", Integer.toString(version.getPersonalVersion()));
      body = body.replace("{contactVersion}", Integer.toString(version.getContactVersion()));
      req.setBody(new SipcBody(body));

    } else {
      throw new IllegalStateException("parse wwwHeader failed. wwwHeader=" + wwwHeader.getValue());
    }

    return req;
  }
Ejemplo n.º 7
0
 /**
  * 注册服务器
  *
  * @param presence 登录状态
  * @param listener
  */
 public void register(int presence, ActionEventListener listener) {
   SipcRequest request =
       this.getMessageFactory()
           .createServerRegisterRequest(
               presence, this.context.getTransferFactory().isMutiConnectionSupported());
   request.setResponseHandler(new ServerRegisterResponseHandler(context, this, listener));
   this.process(request);
 }
Ejemplo n.º 8
0
  /** 订阅群通知 */
  public SipcRequest createSubscribeGroupNotifyRequest(String uri) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SUBSCRIBE);
    req.addHeader(SipcHeader.EVENT, "PGPresence");

    req.setBody(new SipcBody(MessageTemplate.TMPL_SUBSCRIBE_GROUP_NOPTIFY.replace("{uri}", uri)));

    return req;
  }
Ejemplo n.º 9
0
 /**
  * 获取定时短信列表
  *
  * @param listener
  */
 public void getScheduleSMSList(ActionEventListener listener) {
   this.ensureOpened();
   SipcRequest request =
       this.messageFactory.createGetScheduleSMSListRequest(
           this.context.getFetionStore().getStoreVersion().getScheduleSMSVersion());
   request.setResponseHandler(new GetScheduleSMSListResponseHandler(context, this, listener));
   this.process(request);
 }
Ejemplo n.º 10
0
  /** 群在线请求 */
  public SipcRequest createGroupKeepLiveRequest(String uri) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.INFO);
    req.addHeader(SipcHeader.TO, uri);

    req.setBody(new SipcBody(MessageTemplate.TMPL_GROUP_KEEP_LIVE));

    return req;
  }
Ejemplo n.º 11
0
  /** 删除分组 */
  public SipcRequest createDeleteCordRequest(int cordId) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SERVICE);
    req.addHeader(SipcHeader.EVENT, "DeleteBuddyList");

    req.setBody(
        new SipcBody(
            MessageTemplate.TMPL_DELETE_CORD.replace("{cordId}", Integer.toString(cordId))));
    return req;
  }
Ejemplo n.º 12
0
 /**
  * 创建新的定时短信
  *
  * @param scheduleSMS 定时短信对象
  * @param listener
  */
 public void createScheduleSMS(ScheduleSMS scheduleSMS, ActionEventListener listener) {
   this.ensureOpened();
   SipcRequest request =
       this.messageFactory.createCreateScheduleSMSRequest(
           scheduleSMS.getSendDate(), scheduleSMS.getMessage(), scheduleSMS.getReciverList());
   request.setResponseHandler(
       new CreateScheduleSMSResponseHandler(context, this, listener, scheduleSMS));
   this.process(request);
 }
Ejemplo n.º 13
0
 /** 将好友从黑名单移除 */
 public SipcRequest createRemoveBuddyFromBlackList(int userId) {
   SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SERVICE);
   req.addHeader(SipcHeader.EVENT, "RemoveFromBlacklistV4");
   req.setBody(
       new SipcBody(
           MessageTemplate.TMPL_REMOVE_FROM_BLACKLIST.replace(
               "{userId}", Integer.toString(userId))));
   return req;
 }
Ejemplo n.º 14
0
  /** 邀请好友加入会话 */
  public SipcRequest createInvateBuddyRequest(String uri) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SERVICE);

    String body = MessageTemplate.TMPL_INVATE_BUDDY;
    body = body.replace("{uri}", uri);

    req.addHeader(SipcHeader.EVENT, "InviteBuddy");
    req.setBody(new SipcBody(body));
    return req;
  }
Ejemplo n.º 15
0
  /**
   * 发送手机短消息
   *
   * @param uri
   * @param m
   * @return
   */
  public SipcRequest createSendSMSRequest(String uri, Message m) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.MESSAGE);

    req.addHeader(SipcHeader.TO, uri);
    req.addHeader(SipcHeader.EVENT, "SendCatSMS");

    req.setBody(new SipcBody(m.getText()));

    return req;
  }
Ejemplo n.º 16
0
  /**
   * 拒绝陌生人添加好友请求
   *
   * @param userId
   * @return
   */
  public SipcRequest createDeclineApplicationRequest(int userId) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SERVICE);
    String body = MessageTemplate.TMPL_APPLICATION_DECLINED;
    body = body.replace("{userId}", Integer.toString(userId));

    req.addHeader(SipcHeader.EVENT, "HandleContactRequestV4");

    req.setBody(new SipcBody(body));
    return req;
  }
Ejemplo n.º 17
0
  /**
   * 删除好友
   *
   * @param uri
   * @return
   */
  public SipcRequest createDeleteBuddyRequest(int userId) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SERVICE);
    String body = MessageTemplate.TMPL_DELETE_BUDDY;
    body = body.replace("{userId}", Integer.toString(userId));

    req.addHeader(SipcHeader.EVENT, "DeleteBuddyV4");

    req.setBody(new SipcBody(body));
    return req;
  }
Ejemplo n.º 18
0
  /** 获取定时短信列表 */
  public SipcRequest createGetScheduleSMSListRequest(int localVersion) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SERVICE);
    req.addHeader(SipcHeader.EVENT, "SSGetScheduleSmsList");

    String body = MessageTemplate.TMPL_GET_SCHEDULE_SMS_LIST;
    body = body.replace("{version}", Integer.toString(localVersion));
    req.setBody(new SipcBody(body));

    return req;
  }
Ejemplo n.º 19
0
  /** 更新分组标题 */
  public SipcRequest createSetCordTitleRequest(int cordId, String title) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SERVICE);
    req.addHeader(SipcHeader.EVENT, "SetBuddyListInfo");

    String body = MessageTemplate.TMPL_UPDATE_CORD;
    body = body.replace("{cordId}", Integer.toString(cordId));
    body = body.replace("{title}", title);
    req.setBody(new SipcBody(body));
    return req;
  }
Ejemplo n.º 20
0
  /** 开始群会话 */
  public SipcRequest createInviteRequest(String uri, Port localPort) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.INVATE);
    req.addHeader(SipcHeader.TO, uri);
    req.addHeader(SipcHeader.SUPPORTED, "text/html-fragment");
    // req.addHeader(SipcHeader.SUPPORTED, "text/plain");
    req.addHeader(SipcHeader.SUPPORTED, "multiparty");
    req.addHeader(SipcHeader.SUPPORTED, "nudge");
    req.addHeader(SipcHeader.SUPPORTED, "share-background");
    req.addHeader(SipcHeader.SUPPORTED, "fetion-show");

    req.setNeedReplyTimes(2); // 需回复两次

    // 正文是一些固定的参数
    StringBuffer buffer = new StringBuffer();
    buffer.append("v=0\r\n");
    buffer.append("o=-0 0 IN " + localPort.toString() + "\r\n");
    buffer.append("s=session\r\n");
    buffer.append("c=IN IP4 " + localPort.toString() + "\r\n");
    buffer.append("t=0 0\r\n");
    buffer.append("m=message " + Integer.toString(localPort.getPort()) + " sip " + uri);

    req.setBody(new SipcBody(buffer.toString()));

    return req;
  }
Ejemplo n.º 21
0
  /** 设置群状态 */
  public SipcRequest createSetGroupPresenceRequest(String uri, int presense) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SERVICE);
    req.addHeader(SipcHeader.EVENT, "PGSetPresence");
    String body = MessageTemplate.TMPL_GROUP_SET_PRESENCE;
    body = body.replace("{uri}", uri);
    body = body.replace("{presence}", Integer.toString(presense));

    req.setBody(new SipcBody(body));

    return req;
  }
Ejemplo n.º 22
0
  /**
   * 获取联系人详细信息
   *
   * @param buddyList
   * @return
   */
  public SipcRequest createGetContactInfoRequest(String uri) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SERVICE);

    String body = MessageTemplate.TMPL_GET_CONTACT_INFO;
    body = body.replace("{args}", " uri=\"" + uri + "\" version=\"0\" ");
    req.setBody(new SipcBody(body));

    req.addHeader(SipcHeader.EVENT, "GetContactInfoV4");

    return req;
  }
Ejemplo n.º 23
0
  /** 获取群列表 */
  public SipcRequest createGetGroupListRequest(int localVersion) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SERVICE);
    req.addHeader(SipcHeader.EVENT, "PGGetGroupList");

    req.setBody(
        new SipcBody(
            MessageTemplate.TMPL_GET_GROUP_LIST.replace(
                "{version}", Integer.toString(localVersion))));

    return req;
  }
Ejemplo n.º 24
0
  /** 注册聊天服务器 */
  public SipcRequest createRegisterChatRequest(String ticket) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.REGISTER);
    req.addHeader(SipcHeader.AUTHORIZATION, "TICKS auth=\"" + ticket + "\"");
    req.addHeader(SipcHeader.SUPPORTED, "text/html-fragment");
    // req.addHeader(SipcHeader.SUPPORTED,"multiparty");
    // req.addHeader(SipcHeader.SUPPORTED,"nudge");
    // req.addHeader(SipcHeader.SUPPORTED,"share-background");
    // req.addHeader(SipcHeader.FIELD_SUPPORTED,"fetion-show");

    return req;
  }
Ejemplo n.º 25
0
 /**
  * 验证用户
  *
  * @param presence 登录状态
  * @param listener
  */
 public void userAuth(int presence, ActionEventListener listener) {
   SipcHeader wwwHeader = (SipcHeader) this.session.getAttribute(SipcHeader.WWWAUTHENTICATE);
   SipcRequest request =
       this.getMessageFactory()
           .createUserAuthRequest(
               wwwHeader,
               presence,
               this.context.getTransferFactory().isMutiConnectionSupported(),
               this.context.getFetionStore().getStoreVersion());
   request.setResponseHandler(new UserAuthResponseHandler(context, this, listener));
   this.process(request);
 }
Ejemplo n.º 26
0
  /** 发送在线消息 */
  public SipcRequest createSendChatMessageRequest(String toUri, Message m) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.MESSAGE);

    req.addHeader(SipcHeader.TO, toUri);
    // req.addHeader(SipcHeader.CONTENT_TYPE, "text/plain");text/html-fragment
    req.addHeader(SipcHeader.CONTENT_TYPE, m.getType());
    req.addHeader(SipcHeader.EVENT, "CatMsg");

    req.setBody(new SipcBody(m.getContent()));

    return req;
  }
Ejemplo n.º 27
0
  /**
   * 设置好友分组信息
   *
   * @param uri
   * @param cordId
   * @return
   */
  public SipcRequest createSetBuddyCord(int userId, String cordId) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SERVICE);

    String body = MessageTemplate.TMPL_SET_BUDDY_CORD;
    body = body.replace("{userId}", Integer.toString(userId));
    body = body.replace("{cordId}", cordId != null ? cordId : "");

    req.addHeader(SipcHeader.EVENT, "SetContactInfoV4");

    req.setBody(new SipcBody(body));
    return req;
  }
Ejemplo n.º 28
0
  /**
   * 设置好友本地姓名
   *
   * @param userId 好友用户ID
   * @param localName 本地显示名字
   * @return
   */
  public SipcRequest createSetBuddyLocalName(int userId, String localName) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SERVICE);

    String body = MessageTemplate.TMPL_SET_BUDDY_LOCAL_NAME;
    body = body.replace("{userId}", Integer.toString(userId));
    body = body.replace("{localName}", localName);

    req.addHeader(SipcHeader.EVENT, "SetContactInfoV4");

    req.setBody(new SipcBody(body));
    return req;
  }
Ejemplo n.º 29
0
 /** 发送数据包 */
 @Override
 public void process(SipcOutMessage out) {
   try {
     this.processorChain.getFirst().processOutcoming(out);
   } catch (FetionException e) {
     this.handleException(e);
     // 如果是传输异常,就将其抛出,让调用者处理传输错误
     if (out instanceof SipcRequest) {
       SipcRequest request = (SipcRequest) out;
       if (request.getResponseHandler() != null) request.getResponseHandler().ioerror(request);
     }
   }
 }
Ejemplo n.º 30
0
  /**
   * 添加飞信好友请求
   *
   * @param uri
   * @param promptId
   * @param cordId
   * @param desc
   * @return
   */
  public SipcRequest createAddBuddyRequest(
      String uri, int promptId, int cordId, String desc, String localName) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.SERVICE);
    String body = MessageTemplate.TMPL_ADD_BUDDY;
    body = body.replace("{uri}", uri);
    body = body.replace("{promptId}", Integer.toString(promptId));
    body = body.replace("{cordId}", cordId == -1 ? "" : Integer.toString(cordId));
    body = body.replace("{desc}", StringHelper.qouteHtmlSpecialChars(desc));
    body = body.replace("{localName}", localName != null ? "local-name=\"" + localName + "\"" : "");

    req.addHeader(SipcHeader.EVENT, "AddBuddyV4");
    req.setBody(new SipcBody(body));
    return req;
  }