Search in sources :

Example 11 with Setting

use of org.aisen.android.common.setting.Setting 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 12 with Setting

use of org.aisen.android.common.setting.Setting 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 13 with Setting

use of org.aisen.android.common.setting.Setting in project AisenWeiBo by wangdan.

the class ABizLogic method newSetting.

protected Setting newSetting(String type, String value, String desc) {
    Setting extra = new Setting();
    extra.setType(type);
    extra.setValue(value);
    extra.setDescription(desc);
    return extra;
}
Also used : Setting(org.aisen.android.common.setting.Setting)

Example 14 with Setting

use of org.aisen.android.common.setting.Setting in project AisenWeiBo by wangdan.

the class SDK method getPictureSize.

/**
 * 获取图片大小
 *
 * @param url
 * @return
 * @throws TaskException
 */
public PictureSize getPictureSize(String url) throws TaskException {
    Setting action = newSetting("getPictureSize", "", "读取图片的尺寸");
    action.getExtras().put(HTTP_UTILITY, newSettingExtra(HTTP_UTILITY, PictureSizeHttpUtility.class.getName(), "获取图片尺寸的HttpUtility"));
    Params params = new Params();
    params.addParameter("path", url);
    return doGet(action, params, PictureSize.class);
}
Also used : Setting(org.aisen.android.common.setting.Setting) Params(org.aisen.android.network.http.Params)

Example 15 with Setting

use of org.aisen.android.common.setting.Setting in project AisenWeiBo by wangdan.

the class SinaSDK method webGetHotTopics.

/**
 * 热门话题
 *
 * @param sinceId
 * @return
 * @throws TaskException
 */
public WebHotTopicssBean webGetHotTopics(String containerId, String sinceId, int page) throws TaskException {
    Params params = new Params();
    params.addParameter("containerid", containerId);
    if (!TextUtils.isEmpty(sinceId)) {
        params.addParameter("since_id", sinceId);
    } else if (page > 0) {
        params.addParameter("page", String.valueOf(page));
    }
    Setting action = newSetting("webGetHotTopics", "container/getIndex", "热门话题");
    action.getExtras().put(HTTP_UTILITY, newSettingExtra(HTTP_UTILITY, TopicHotHttpUtility.class.getName(), ""));
    try {
        return doGet(webConfig(), action, params, WebHotTopicssBean.class);
    } catch (Exception e) {
        if (e instanceof TaskException)
            checkWebResult((TaskException) e);
        throw e;
    }
}
Also used : TaskException(org.aisen.android.network.task.TaskException) Setting(org.aisen.android.common.setting.Setting) Params(org.aisen.android.network.http.Params) ParseException(java.text.ParseException) TaskException(org.aisen.android.network.task.TaskException)

Aggregations

Setting (org.aisen.android.common.setting.Setting)26 Params (org.aisen.android.network.http.Params)17 TaskException (org.aisen.android.network.task.TaskException)11 HttpConfig (org.aisen.android.network.http.HttpConfig)7 ParseException (java.text.ParseException)6 JSONArray (com.alibaba.fastjson.JSONArray)3 JSONObject (com.alibaba.fastjson.JSONObject)3 ArrayList (java.util.ArrayList)2 LikeResultBean (org.aisen.weibo.sina.support.bean.LikeResultBean)2 SpannableString (android.text.SpannableString)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 DefHttpUtility (org.aisen.android.network.http.DefHttpUtility)1 PicUrls (org.aisen.weibo.sina.sinasdk.bean.PicUrls)1 SearchsResultUser (org.aisen.weibo.sina.sinasdk.bean.SearchsResultUser)1 StatusContent (org.aisen.weibo.sina.sinasdk.bean.StatusContent)1 UrlsBean (org.aisen.weibo.sina.sinasdk.bean.UrlsBean)1 WallpaperBeans (org.aisen.weibo.sina.support.bean.WallpaperBeans)1 Document (org.jsoup.nodes.Document)1 Elements (org.jsoup.select.Elements)1