Package iqq.im.action

Source Code of iqq.im.action.GetFriendAccoutAction

package iqq.im.action;

import iqq.im.QQActionListener;
import iqq.im.QQException;
import iqq.im.bean.QQUser;
import iqq.im.core.QQConstants;
import iqq.im.core.QQContext;
import iqq.im.core.QQSession;
import iqq.im.event.QQActionEvent;
import iqq.im.http.QQHttpRequest;
import iqq.im.http.QQHttpResponse;

import org.json.JSONException;
import org.json.JSONObject;

/**
* 获取QQ账号
*
* @author ChenZhiHui
* @since 2013-2-23
*/
public class GetFriendAccoutAction extends AbstractHttpAction {

  private QQUser buddy;

  /**
   * <p>Constructor for GetFriendAccoutAction.</p>
   *
   * @param context a {@link iqq.im.core.QQContext} object.
   * @param listener a {@link iqq.im.QQActionListener} object.
   * @param buddy a {@link iqq.im.bean.QQUser} object.
   */
  public GetFriendAccoutAction(QQContext context, QQActionListener listener, QQUser buddy) {
    super(context, listener);
    this.buddy = buddy;
  }

  /** {@inheritDoc} */
  @Override
  protected QQHttpRequest onBuildRequest() throws QQException, JSONException {
    QQSession session = getContext().getSession();
    // tuin=4245757755&verifysession=&type=1&code=&vfwebqq=**&t=1361631644492
    QQHttpRequest req = createHttpRequest("GET",
        QQConstants.URL_GET_USER_ACCOUNT);
    req.addGetValue("tuin", buddy.getUin() + "");
    req.addGetValue("vfwebqq", session.getVfwebqq());
    req.addGetValue("t", System.currentTimeMillis() / 1000 + "");
    req.addGetValue("verifysession", ""); // 验证码??
    req.addGetValue("type", 1 + "");
    req.addGetValue("code", "");

    req.addHeader("Referer", QQConstants.REFFER);
    return req;
  }

  /** {@inheritDoc} */
  @Override
  protected void onHttpStatusOK(QQHttpResponse response) throws QQException,
      JSONException {
    JSONObject json = new JSONObject(response.getResponseString());
    if (json.getInt("retcode") == 0) {
      JSONObject obj = json.getJSONObject("result");
      buddy.setQQ(obj.getLong("account"));
    }
   
    notifyActionEvent(QQActionEvent.Type.EVT_OK, buddy);
  }

}
TOP

Related Classes of iqq.im.action.GetFriendAccoutAction

TOP
Copyright © 2018 www.massapi.com. 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.