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];
}
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);
}
}
}
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;
}
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);
}
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;
}
}
Aggregations