Search in sources :

Example 1 with LikeResultBean

use of org.aisen.weibo.sina.support.bean.LikeResultBean in project AisenWeiBo by wangdan.

the class SDK method doLike.

/**
     * 点赞
     *
     * @param statusId
     * @param like
     * @param cookie
     * @return
     * @throws TaskException
     */
public LikeResultBean doLike(String statusId, boolean like, String cookie) throws TaskException {
    try {
        String url = like ? "http://m.weibo.cn/attitudesDeal/add" : "http://m.weibo.cn/attitudesDeal/delete";
        Map<String, String> cookieMap = new HashMap<String, String>();
        String[] cookieValues = cookie.split(";");
        for (String cookieValue : cookieValues) {
            String key = cookieValue.split("=")[0];
            String value = cookieValue.split("=")[1];
            cookieMap.put(key, value);
        }
        //            Logger.d(WeiboClientActivity.TAG, cookieMap);
        Connection connection = Jsoup.connect(url);
        connection.userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:33.0) Gecko/20100101 Firefox/33.0").referrer("http://m.weibo.cn/").cookies(cookieMap).data("id", statusId).method(Connection.Method.POST);
        if (like)
            connection.data("attitude", "heart");
        String body = connection.execute().body();
        if (!TextUtils.isEmpty(body)) {
            Logger.d(TAG, body);
            if (body.indexOf("http://passport.weibo.cn/sso/crossdomain") != -1)
                throw new TaskException("-100", "未登录");
            else if (body.indexOf("<html") != -1)
                throw new TaskException("-100", "未登录");
            LikeResultBean likeBean = JSON.parseObject(body, LikeResultBean.class);
            if (likeBean.getOk() == 1) {
                return likeBean;
            } else if (likeBean.getOk() == -100) {
                throw new TaskException("-100", "未登录");
            } else {
                throw new TaskException("", likeBean.getMsg());
            }
        }
    } catch (Exception e) {
        if (e instanceof TaskException)
            throw (TaskException) e;
        e.printStackTrace();
    }
    throw new TaskException(TaskException.TaskError.timeout.toString());
}
Also used : LikeResultBean(org.aisen.weibo.sina.support.bean.LikeResultBean) TaskException(org.aisen.android.network.task.TaskException) HashMap(java.util.HashMap) Connection(org.jsoup.Connection) TaskException(org.aisen.android.network.task.TaskException)

Aggregations

HashMap (java.util.HashMap)1 TaskException (org.aisen.android.network.task.TaskException)1 LikeResultBean (org.aisen.weibo.sina.support.bean.LikeResultBean)1 Connection (org.jsoup.Connection)1