Search in sources :

Example 6 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 7 with HttpConfig

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

the class SinaSDK method locationMobileGetLocation.

/**
 * 根据移动基站WIFI等数据获取当前位置信息
 *
 * @return
 * @throws TaskException
 */
public SinaLocationMap locationMobileGetLocation() throws TaskException {
    Map<String, Object> requestMap = new HashMap<String, Object>();
    // 请求版本信息
    requestMap.put("version", "2.0");
    // 请求地址信息
    requestMap.put("host", "api.weibo.com");
    // 请求类型
    requestMap.put("radio_type", "gsm");
    // 是否需要返回详细地址,可选,默认:false
    requestMap.put("request_address", "true");
    // 返回坐标是否偏移处理,偏移后坐标适合在新浪地图上使用(http://map.sina.com.cn),
    // 不适用于百度地图(各地图偏移量不同,请谨慎处理);可选,默认:false
    requestMap.put("decode_pos", "true");
    TelephonyManager mTelNet = (TelephonyManager) GlobalContext.getInstance().getSystemService(Context.TELEPHONY_SERVICE);
    GsmCellLocation location = null;
    if (mTelNet != null)
        location = (GsmCellLocation) mTelNet.getCellLocation();
    if (location != null) {
        String operator = mTelNet.getNetworkOperator();
        int mcc = Integer.parseInt(operator.substring(0, 3));
        int mnc = Integer.parseInt(operator.substring(3));
        List<NeighboringCellInfo> cellInfoList = mTelNet.getNeighboringCellInfo();
        ArrayList<Map<String, Object>> cellMapList = new ArrayList<Map<String, Object>>();
        for (NeighboringCellInfo cellInfo : cellInfoList) {
            // 基站信息
            Map<String, Object> cellMap = new HashMap<String, Object>();
            // 基站号
            cellMap.put("cell_id", location.getCid());
            // 小区号
            cellMap.put("location_area_code", cellInfo.getLac());
            // 地区代码
            cellMap.put("mobile_country_code", mcc);
            // 运营商号
            cellMap.put("mobile_network_code", mnc);
            // 信号强度
            cellMap.put("signal_strength", cellInfo.getRssi());
            cellMapList.add(cellMap);
        }
        if (cellMapList.size() > 0)
            requestMap.put("cell_towers", cellMapList);
    }
    WifiManager wm = (WifiManager) GlobalContext.getInstance().getSystemService(Context.WIFI_SERVICE);
    List<ScanResult> scanResultList = wm.getScanResults();
    if (scanResultList != null && scanResultList.size() > 0) {
        ArrayList<Map<String, Object>> wifiMapList = new ArrayList<Map<String, Object>>();
        for (ScanResult scanResult : scanResultList) {
            // WIFI信息
            Map<String, Object> wifiMap = new HashMap<String, Object>();
            wifiMapList.add(wifiMap);
            wifiMap.put("mac_address", scanResult.BSSID);
            wifiMap.put("mac_name", scanResult.SSID);
            // 信号强度
            wifiMap.put("signal_strength", scanResult.level);
        }
        if (wifiMapList.size() > 0)
            requestMap.put("wifi_towers", wifiMapList);
    }
    HttpConfig config = getHttpConfig();
    Params params = new Params();
    params.addParameter("json", JSON.toJSONString(requestMap));
    return doPost(config, getSetting("locationMobileGetLocation"), null, params, null, SinaLocationMap.class);
}
Also used : WifiManager(android.net.wifi.WifiManager) ScanResult(android.net.wifi.ScanResult) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Params(org.aisen.android.network.http.Params) NeighboringCellInfo(android.telephony.NeighboringCellInfo) TelephonyManager(android.telephony.TelephonyManager) JSONObject(com.alibaba.fastjson.JSONObject) HttpConfig(org.aisen.android.network.http.HttpConfig) GsmCellLocation(android.telephony.gsm.GsmCellLocation) Map(java.util.Map) SinaLocationMap(org.aisen.weibo.sina.sinasdk.bean.SinaLocationMap) HashMap(java.util.HashMap)

Example 8 with HttpConfig

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

the class SinaSDK method friendshipGroupsOrder.

/**
 * 调整当前登录用户的好友分组顺序
 *
 * @param groupList
 * @return
 * @throws TaskException
 */
public GroupSortResult friendshipGroupsOrder(List<Group> groupList) throws TaskException {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < groupList.size(); i++) {
        sb.append(groupList.get(i).getIdstr());
        if (i != groupList.size() - 1)
            sb.append(",");
    }
    Params params = new Params();
    params.addParameter("count", String.valueOf(groupList.size()));
    params.addParameter("list_ids", sb.toString());
    HttpConfig config = getHttpConfig();
    return doPost(config, getSetting("friendshipGroupsOrder"), null, params, null, GroupSortResult.class);
}
Also used : Params(org.aisen.android.network.http.Params) HttpConfig(org.aisen.android.network.http.HttpConfig)

Example 9 with HttpConfig

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

the class SinaSDK method configHttpConfig.

@Override
protected HttpConfig configHttpConfig() {
    HttpConfig httpConfig = new HttpConfig();
    httpConfig.baseUrl = getSetting(BASE_URL).getValue();
    if (token != null) {
        httpConfig.addHeader("Authorization", "OAuth2 " + token.getToken());
    }
    return httpConfig;
}
Also used : HttpConfig(org.aisen.android.network.http.HttpConfig)

Example 10 with HttpConfig

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

the class SinaSDK method searchsResultUsers.

/**
 * 使用H5页面查询用户
 *
 * @param q
 * @param cookies
 * @return
 * @throws TaskException
 */
public ArrayList<SearchsResultUser> searchsResultUsers(String q, String cookies) throws TaskException {
    ArrayList<SearchsResultUser> resultUsers = new ArrayList<>();
    Setting action = newSetting("searchsResultUsers", "page/pageJson", "获取用户");
    action.getExtras().put(BASE_URL, newSettingExtra(BASE_URL, "http://m.weibo.cn/", ""));
    Params params = new Params();
    // params.addParameter("containerid", "100103");
    // params.addParameter("type", "3");
    // params.addParameter("page", "1");
    // params.addParameter("q", q);
    // 我也搞不懂这个脑残接口到底怎么玩的
    // http://m.weibo.cn/page/pageJson?containerid=100103type%3D3%26q%3Dwang&page=1
    params.addParameter("containerid", "100103type%3D3%26q%3D" + q + "&page=1");
    try {
        HttpConfig config = getHttpConfig();
        // config.cookie = cookies;
        // config.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        // config.addHeader("Referer", "http://m.weibo.cn/searchs");
        String response = doGet(config, action, params, String.class);
        JSONObject responseJSON = JSONObject.parseObject(response);
        int ok = responseJSON.getInteger("ok");
        if (ok == 1) {
            JSONArray cardsArray = responseJSON.getJSONArray("cards");
            if (cardsArray.size() > 0) {
                JSONObject cardGroupsObject = cardsArray.getJSONObject(1);
                JSONArray cardGroupArray = cardGroupsObject.getJSONArray("card_group");
                for (int i = 0; i < cardGroupArray.size(); i++) {
                    JSONObject cardGroup = cardGroupArray.getJSONObject(i);
                    SearchsResultUser user = new SearchsResultUser();
                    user.setDesc1(cardGroup.getString("desc1"));
                    user.setDesc2(cardGroup.getString("desc2"));
                    JSONObject userJSON = cardGroup.getJSONObject("user");
                    user.setId(userJSON.getString("id"));
                    user.setFollowing(userJSON.getBoolean("following"));
                    user.setFollow_me(userJSON.getBoolean("follow_me"));
                    user.setFansNum(userJSON.getString("fansNum"));
                    user.setScreen_name(userJSON.getString("screen_name"));
                    user.setDescription(userJSON.getString("description"));
                    user.setProfile_image_url(userJSON.getString("profile_image_url"));
                    user.setStatuses_count(userJSON.getInteger("statuses_count"));
                    user.setGender(userJSON.getString("gender"));
                    user.setRemark(userJSON.getString("remark"));
                    resultUsers.add(user);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        if (e instanceof TaskException) {
            throw e;
        }
    }
    return resultUsers;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) TaskException(org.aisen.android.network.task.TaskException) SearchsResultUser(org.aisen.weibo.sina.sinasdk.bean.SearchsResultUser) Setting(org.aisen.android.common.setting.Setting) ArrayList(java.util.ArrayList) 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)

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