Search in sources :

Example 1 with HttpConfig

use of org.aisen.android.network.http.HttpConfig in project AisenWeiBo by wangdan.

the class VideoService method getPicture.

public static void getPicture(VideoBean video) throws Exception {
    if (TextUtils.isEmpty(AppContext.getAccount().getCookie())) {
        throw new TaskException("123", "解析链接失败");
    }
    HttpConfig config = new HttpConfig();
    config.baseUrl = video.getShortUrl();
    config.cookie = AppContext.getAccount().getCookie();
    config.addHeader("Content-Type", "text/html;charset=utf-8");
    Setting action = new Setting();
    action.setType("");
    action.setValue("");
    action.setDescription("");
    String response = new DefHttpUtility().doGet(config, action, null, String.class);
    Document dom = Jsoup.parse(response);
    video.setIdStr(KeyGenerator.generateMD5(video.getShortUrl()));
    Elements divs = dom.select("img");
    if (divs != null && divs.size() > 0) {
        video.setImage(divs.get(0).attr("src"));
        video.setImage(video.getImage().replace("bmiddle", "small").replace("thumbnail", "small"));
    }
    if (TextUtils.isEmpty(video.getImage())) {
        String longUrl = video.getLongUrl();
        if (TextUtils.isEmpty(longUrl)) {
            UrlsBean urlsBean = SinaSDK.getInstance(AppContext.getAccount().getAccessToken()).urlShort2Long(video.getShortUrl());
            if (urlsBean.getUrls() != null && urlsBean.getUrls().size() > 0) {
                longUrl = urlsBean.getUrls().get(0).getUrl_long();
                longUrl.replace("bmiddle", "small").replace("thumbnail", "small");
            }
        }
        if (!TextUtils.isEmpty(longUrl)) {
            video.setImage(longUrl);
        }
    }
}
Also used : TaskException(org.aisen.android.network.task.TaskException) Setting(org.aisen.android.common.setting.Setting) HttpConfig(org.aisen.android.network.http.HttpConfig) SpannableString(android.text.SpannableString) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) UrlsBean(org.aisen.weibo.sina.sinasdk.bean.UrlsBean) DefHttpUtility(org.aisen.android.network.http.DefHttpUtility)

Example 2 with HttpConfig

use of org.aisen.android.network.http.HttpConfig in project AisenWeiBo by wangdan.

the class SinaSDK method webConfig.

// 以下开始计划写网页版接口
private HttpConfig webConfig() throws TaskException {
    if (AppContext.getAccount() == null || AppContext.getAccount().getCookie() == null)
        throw new TaskException("", "网页授权已失效,请点击左侧私信菜单再次登录授权");
    HttpConfig config = configHttpConfig();
    config.baseUrl = WEB_BASE_URL;
    config.cookie = AppContext.getAccount().getCookie();
    config.addHeader("User-Agent", "Mozilla/5.0 (Linux; Android 5.1.1; SM801 Build/LMY47V) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36");
    return config;
}
Also used : TaskException(org.aisen.android.network.task.TaskException) HttpConfig(org.aisen.android.network.http.HttpConfig)

Example 3 with HttpConfig

use of org.aisen.android.network.http.HttpConfig in project AisenWeiBo by wangdan.

the class SinaSDK method searchsSuggest.

/**
 * 使用H5页面的接口拉取数据
 *
 * @param q
 * @param cookies
 * @return
 * @throws TaskException
 */
public String[] searchsSuggest(String q, String cookies) throws TaskException {
    // http://m.weibo.cn/searchs/suggest?count=10&q=ann
    Setting action = newSetting("searchsSuggest", "searchs/suggest", "获取搜索建议");
    action.getExtras().put(BASE_URL, newSettingExtra(BASE_URL, "http://m.weibo.cn/", ""));
    Params params = new Params();
    params.addParameter("q", q);
    params.addParameter("count", "5");
    HttpConfig config = configHttpConfig();
    config.cookie = cookies;
    config.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    config.addHeader("Referer", "http://m.weibo.cn/searchs");
    try {
        // ["ana",["anastasia","T-ANA小芹","anastasia 修容","广安门医院官方微博","anastasia 高光"]]
        String response = doPost(config, action, null, params, null, String.class);
        response = AisenUtils.convertUnicode(response);
        Logger.d("SinaSDK", response);
        if (response.toLowerCase().indexOf("<html>") != -1) {
            throw new TaskException("cookieinvalid", "网页版登录失效了");
        }
        // {"request":"/search/suggestions/all.php","error_code":"21405","error":"Operation timed out after 300 milliseconds with 0 bytes received url:http://i.api.weibo.com/users/show_batch.json"}
        if (response.indexOf("error_code") != -1 && response.indexOf("error") != -1) {
            JSONObject jsonRespone = JSONObject.parseObject(response);
            throw new TaskException(jsonRespone.getString("error_code"), jsonRespone.getString("error"));
        } else // {"ok":-100,"msg":"请先登录","url":"https://passport.weibo.cn/signin/welcome?entry=mweibo&r=http%3A%2F%2Fm.weibo.cn%2Fsearchs%2Fsuggest"}
        if (response.indexOf("ok") != -1 && response.indexOf("msg") != -1) {
            JSONObject jsonRespone = JSONObject.parseObject(response);
            throw new TaskException(jsonRespone.getString("ok"), jsonRespone.getString("msg"));
        }
        JSONArray jsonArray = JSON.parseArray(response);
        JSONArray resultArray = jsonArray.getJSONArray(1);
        String[] result = new String[resultArray.size()];
        for (int i = 0; i < resultArray.size(); i++) {
            result[i] = resultArray.getString(i);
        }
        return result;
    } catch (Exception e) {
        e.printStackTrace();
        if (e instanceof TaskException) {
            throw e;
        }
    }
    return new String[0];
}
Also used : TaskException(org.aisen.android.network.task.TaskException) JSONObject(com.alibaba.fastjson.JSONObject) Setting(org.aisen.android.common.setting.Setting) JSONArray(com.alibaba.fastjson.JSONArray) Params(org.aisen.android.network.http.Params) HttpConfig(org.aisen.android.network.http.HttpConfig) ParseException(java.text.ParseException) TaskException(org.aisen.android.network.task.TaskException)

Example 4 with HttpConfig

use of org.aisen.android.network.http.HttpConfig in project AisenWeiBo by wangdan.

the class SinaSDK method commentsHotShow.

/**
 * 热门评论
 *
 * @param statusId
 * @param page
 * @return
 * @throws TaskException
 */
public StatusComments commentsHotShow(String statusId, int page) throws TaskException {
    if (AppContext.getAccount() == null || AppContext.getAccount().getCookie() == null)
        throw new TaskException("", "网页授权已失效,请点击左侧私信菜单再次登录授权");
    HttpConfig config = configHttpConfig();
    config.baseUrl = "http://m.weibo.cn/single/rcList";
    config.cookie = AppContext.getAccount().getCookie();
    Params params = new Params();
    params.addParameter("id", statusId);
    params.addParameter("format", "cards");
    params.addParameter("type", "comment");
    params.addParameter("hot", "1");
    if (page > 1) {
        params.addParameter("page", String.valueOf(page));
    }
    Setting action = newSetting("", "", "");
    action.getExtras().put(HTTP_UTILITY, newSettingExtra(HTTP_UTILITY, CommentsHotHttpUtility.class.getName(), ""));
    return doGet(config, action, params, StatusComments.class);
}
Also used : TaskException(org.aisen.android.network.task.TaskException) Setting(org.aisen.android.common.setting.Setting) Params(org.aisen.android.network.http.Params) HttpConfig(org.aisen.android.network.http.HttpConfig)

Example 5 with HttpConfig

use of org.aisen.android.network.http.HttpConfig in project AisenWeiBo by wangdan.

the class SinaSDK method webStatusLike.

/**
 * 微博点赞
 *
 * @param statusId
 * @param like
 * @param cookie
 * @return
 * @throws TaskException
 */
public LikeResultBean webStatusLike(String statusId, boolean like, String cookie) throws TaskException {
    Params params = new Params();
    params.addParameter("id", statusId);
    if (like)
        params.addParameter("attitude", "heart");
    Setting action = newSetting("webStatusLike", like ? "attitudesDeal/add" : "attitudesDeal/delete", "微博点赞");
    HttpConfig config = webConfig();
    config.addHeader("Referer", config.baseUrl);
    config.addHeader("Content-Type", "application/x-www-form-urlencoded");
    config.addHeader("Host", "m.weibo.cn");
    config.addHeader("Accept-Language", "zh-CN,en-US;q=0.8");
    config.addHeader("Accept", "application/json, text/plain, */*");
    String body = doPost(config, action, null, params, null, String.class);
    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());
        }
    }
    throw new TaskException(TaskException.TaskError.timeout.toString());
}
Also used : LikeResultBean(org.aisen.weibo.sina.support.bean.LikeResultBean) TaskException(org.aisen.android.network.task.TaskException) Setting(org.aisen.android.common.setting.Setting) Params(org.aisen.android.network.http.Params) HttpConfig(org.aisen.android.network.http.HttpConfig)

Aggregations

HttpConfig (org.aisen.android.network.http.HttpConfig)13 Params (org.aisen.android.network.http.Params)8 TaskException (org.aisen.android.network.task.TaskException)8 Setting (org.aisen.android.common.setting.Setting)7 JSONObject (com.alibaba.fastjson.JSONObject)3 ParseException (java.text.ParseException)3 JSONArray (com.alibaba.fastjson.JSONArray)2 ArrayList (java.util.ArrayList)2 LikeResultBean (org.aisen.weibo.sina.support.bean.LikeResultBean)2 ScanResult (android.net.wifi.ScanResult)1 WifiManager (android.net.wifi.WifiManager)1 NeighboringCellInfo (android.telephony.NeighboringCellInfo)1 TelephonyManager (android.telephony.TelephonyManager)1 GsmCellLocation (android.telephony.gsm.GsmCellLocation)1 SpannableString (android.text.SpannableString)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DefHttpUtility (org.aisen.android.network.http.DefHttpUtility)1 SearchsResultUser (org.aisen.weibo.sina.sinasdk.bean.SearchsResultUser)1 SinaLocationMap (org.aisen.weibo.sina.sinasdk.bean.SinaLocationMap)1