package com.hanju.video.app.util.http;
|
|
import android.content.Context;
|
import android.content.SharedPreferences;
|
import android.util.Log;
|
import android.widget.Toast;
|
|
import com.hanju.video.app.BuildConfig;
|
import com.hanju.video.app.HanJuApplication;
|
import com.hanju.video.app.util.HanJuConstant;
|
import com.hanju.video.app.util.UserUtil;
|
import com.hanju.lib.library.util.ManifestDataUtil;
|
import com.hanju.lib.library.util.common.PackageUtils2;
|
import com.hanju.lib.library.util.common.StringUtils;
|
import com.hanju.lib.library.util.security.MD5Utils;
|
import com.loopj.android.http.AsyncHttpClient;
|
import com.loopj.android.http.RequestParams;
|
import com.loopj.android.http.ResponseHandlerInterface;
|
import com.loopj.android.http.SyncHttpClient;
|
import com.ut.device.UTDevice;
|
import com.video.youth.util.YouthUtil;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
import java.io.File;
|
import java.io.FileNotFoundException;
|
import java.util.HashMap;
|
import java.util.LinkedHashMap;
|
import java.util.Map.Entry;
|
import java.util.concurrent.TimeUnit;
|
|
import okhttp3.Call;
|
import okhttp3.Callback;
|
import okhttp3.FormBody;
|
import okhttp3.MediaType;
|
import okhttp3.OkHttpClient;
|
import okhttp3.Request;
|
import okhttp3.RequestBody;
|
|
public class HttpApiUtil {
|
|
public static final boolean isDebug = false;
|
|
private static final String TAG = "HttpApiUtil";
|
|
public static String ERROR_NOTICE = "";
|
|
public static String BASE_URL = HanJuConstant.HOST + "/BuWan/api/";
|
|
public static String BASE_URL_V2 = HanJuConstant.HOST + "/BuWan/api/v2/";
|
|
public static String BASE_URL_V3 = HanJuConstant.HOST + "/BuWan/api/v3/";
|
|
private static AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
|
|
private static SyncHttpClient syncHttpClient = new SyncHttpClient();
|
|
private static AsyncHttpClient sortTimeAsyncHttpClient = new AsyncHttpClient();
|
|
static {
|
|
mOkHttpClient = new OkHttpClient().newBuilder()
|
.connectTimeout(10 * 1000, TimeUnit.SECONDS)//设置超时时间
|
.readTimeout(10 * 1000, TimeUnit.SECONDS)//设置读取超时时间
|
.writeTimeout(10 * 1000, TimeUnit.SECONDS)//设置写入超时时间
|
.build();
|
asyncHttpClient.setTimeout(60 * 1000);
|
syncHttpClient.setTimeout(60 * 1000);
|
//5s
|
sortTimeAsyncHttpClient.setTimeout(5 * 1000);
|
|
asyncHttpClient.setURLEncodingEnabled(false);
|
syncHttpClient.setURLEncodingEnabled(false);
|
sortTimeAsyncHttpClient.setURLEncodingEnabled(false);
|
}
|
|
public static void getUid(Context context, String channel, String device,
|
String imei, String mac, String lat, String lng,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Device", device);
|
params.put("Imei", imei);
|
params.put("Mac", mac);
|
params.put("Lat", lat);
|
params.put("Lng", lng);
|
params.put("Channel", channel);
|
if (!StringUtils.isBlank(HanJuApplication.deviceNumber)) {
|
params.put("DeviceName", HanJuApplication.deviceName);
|
params.put("DeviceNumber", HanJuApplication.deviceNumber);
|
}
|
commonPost(context, BASE_URL + "user/getUid", params, handler);
|
}
|
|
|
/**
|
* 获取配置信息
|
*
|
* @param context
|
* @param handler
|
*/
|
public static void getConfig(Context context,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
if (!StringUtils.isBlank(HanJuApplication.deviceNumber)) {
|
params.put("DeviceName", HanJuApplication.deviceName);
|
params.put("DeviceNumber", HanJuApplication.deviceNumber);
|
}
|
commonPost(context, BASE_URL + "config/getConfig", params, null, handler, true, true);
|
}
|
|
/**
|
* 获取推荐页面右面广告状态
|
*
|
* @param context
|
* @param handler
|
*/
|
public static void getAdRecommendRight(Context context, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
commonPost(context, BASE_URL + "other/adRecommendRight", params, handler);
|
}
|
|
public static void suggestSearch(Context context, String uid, String key,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Key", key);
|
commonPost(context, BASE_URL + "user/suggestSearch", params, handler);
|
}
|
|
|
/**
|
* 用户登录
|
*
|
* @param context
|
* @param uid 用户uid
|
* @param name 用户名称
|
* @param openId 用户第三方登录唯一识别码
|
* @param portrait 头像
|
* @param sex 性别
|
* @param loginType 登录类型:1 QQ
|
* @param handler
|
*/
|
public static void userLogin(Context context, String uid, String name,
|
String openId, String portrait, String sex, String province, String city, String loginType,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Name", name);
|
params.put("OpenId", openId);
|
params.put("Portrait", portrait);
|
params.put("Province", province);
|
params.put("City", city);
|
params.put("Sex", sex);
|
params.put("LoginType", loginType);
|
commonPost(context, BASE_URL + "comment/userLogin", params, handler);
|
}
|
|
|
/**
|
* 微信登录
|
*
|
* @param context
|
* @param uid
|
* @param code
|
* @param handler
|
*/
|
public static void wxLogin(Context context, String uid, String code,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Code", code);
|
commonPost(context, BASE_URL + "comment/wxLogin", params, handler);
|
}
|
|
/**
|
* 获取专题列表
|
*
|
* @param context
|
* @param uid
|
* @param page 分页数
|
* @param handler
|
*/
|
public static void getSpecialList(Context context, String uid, String page,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Page", page);
|
commonPost(context, BASE_URL + "class/getSpecialList", params, handler);
|
}
|
|
public static void search(Context context, String uid, String key,
|
String contentType, String page, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Key", key);
|
params.put("Type", contentType);
|
params.put("Page", page);
|
commonPost(context, BASE_URL + "user/searchNew", params, handler);
|
}
|
|
/**
|
* 获取商品详情
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void getWareDetail(Context context, String uid, String id, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Id", id);
|
commonPost(context, BASE_URL + "shop/getGoodsItemDetail", params, handler);
|
}
|
|
/**
|
* 获取商品评论列表
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void getWareCommentList(Context context, String uid, String id, String page, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Id", id);
|
params.put("Page", page);
|
commonPost(context, BASE_URL + "shop/getCommentList", params, handler);
|
}
|
|
/**
|
* 发表评论
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void addComment(Context context, String uid, String id, String loginID, String content, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Id", id);
|
params.put("LoginUid", loginID);
|
params.put("Content", content);
|
commonPost(context, BASE_URL + "shop/addComment", params, handler);
|
}
|
|
/**
|
* 添加收藏
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void addGoodsFavourite(Context context, String uid, String loginUid, String id, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Id", id);
|
params.put("LoginUid", loginUid);
|
commonPost(context, BASE_URL + "shop/addCollect", params, handler);
|
}
|
|
/**
|
* 取消收藏
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void cancelGoodsFavourite(Context context, String uid, String loginUid, String id, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Id", id);
|
params.put("LoginUid", loginUid);
|
commonPost(context, BASE_URL + "shop/cancelCollect", params, handler);
|
}
|
|
/**
|
* 淘宝客收藏列表
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void getCollectList(Context context, String uid, String loginUid, String page, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("LoginUid", loginUid);
|
params.put("Page", page);
|
commonPost(context, BASE_URL + "shop/getCollectList", params, handler);
|
}
|
|
/**
|
* Email登录
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void emailLogin(Context context, String uid, String name,
|
String pwd, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Email", name);
|
params.put("Pwd", pwd);
|
commonPost(context, BASE_URL + "user/login", params, handler);
|
}
|
|
/**
|
* 获取验证码
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void getVerficationCode(Context context, String uid, String name,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Email", name);
|
commonPost(context, BASE_URL + "user/sendVerifyCode", params, handler);
|
}
|
|
/**
|
* Email注册
|
*
|
* @param context
|
* @param uid
|
* @param name
|
* @param handler
|
*/
|
public static void emailRegister(Context context, String uid, String email, String pwd, String verficationCode, String name,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Email", email);
|
params.put("Pwd", pwd);
|
params.put("VerifyCode", verficationCode);
|
params.put("NickName", name);
|
commonPost(context, BASE_URL + "user/register", params, handler);
|
}
|
|
/**
|
* 获取个人信息
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void getPersonInfo(Context context, String uid, String loginUid,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("LoginUid", loginUid);
|
commonPost(context, BASE_URL + "user/getLoginUserInfo", params, handler);
|
}
|
|
/**
|
* 上传个人信息
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void upLoadPersonInfo(Context context, String uid, String loginUid, String sex, String birthday,
|
String personSign, String portrait, String nickName,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("LoginUid", loginUid);
|
params.put("Sex", sex);
|
params.put("BirthDay", birthday);
|
params.put("PersonalSign", personSign);
|
params.put("Portrait", portrait);
|
params.put("NickName", nickName);
|
commonPost(context, BASE_URL + "user/updateLoginUserInfo", params, handler);
|
}
|
|
/**
|
* 修改密码
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void revisePwd(Context context, String uid, String email, String verfycode, String pwd,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Email", email);
|
params.put("Pwd", pwd);
|
params.put("VerifyCode", verfycode);
|
commonPost(context, BASE_URL + "user/setPwd", params, handler);
|
}
|
|
|
/**
|
* 美女直播热门
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void getLiveCategoryList(Context context, String uid, String id, String page,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Type", id);
|
params.put("Page", page);
|
commonPost(context, BASE_URL + "zhibo/getLiveListByType", params, handler);
|
}
|
|
|
public static void sendLiveClick(Context context, String uid, String type, String roomid,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Type", type);
|
params.put("RoomId", roomid);
|
commonPost(context, BASE_URL + "zhibo/addStatistics", params, handler);
|
}
|
|
|
/**
|
* 广告点击上报
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void reportCommonAd(Context context, String uid, String pId, String adId,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Pid", pId);
|
params.put("AdId", adId);
|
params.put("Type", "3");
|
commonPost(context, BASE_URL + "ad/reportCommonAd", params, handler);
|
}
|
|
|
public static void getHotSearch(Context context, String uid,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
commonPost(context, BASE_URL + "user/getHotSearch", params, handler);
|
}
|
|
|
/**
|
* 获取我是否拥有新消息
|
*/
|
public static void getReadState(Context context, String uid,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
commonPost(context, BASE_URL + "comment/getReadState", params, handler);
|
}
|
|
/**
|
* 首页猜你喜欢
|
*
|
* @param context
|
* @param page
|
* @param handler
|
*/
|
public static void getGuessLike(Context context, String page,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Page", page);
|
commonPost(context, BASE_URL + "found/guessLike", params, handler);
|
}
|
|
/**
|
* 相关视频
|
*
|
* @param context
|
* @param uid
|
* @param videoId
|
* @param handler
|
*/
|
public static void getRelativeVideos(Context context, String uid,
|
String videoId, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("VideoId", videoId);
|
params.put("Uid", uid);
|
commonPost(context, BASE_URL + "user/getRelativeVideos", params, handler);
|
}
|
|
/**
|
* 猜你喜欢
|
*
|
* @param context
|
* @param uid
|
* @param videoId
|
* @param handler
|
*/
|
public static void guessLike(Context context, String uid, String videoId,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("VideoId", videoId);
|
params.put("Uid", uid);
|
commonPost(context, BASE_URL + "user/guessLike", params, handler);
|
}
|
|
|
public static void getCollectedVideo(Context context, String uid, String loginUid,
|
String page, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("LoginUid", loginUid);
|
params.put("Page", page);
|
commonPost(context, BASE_URL + "user/getCollectedVideo", params, handler);
|
}
|
|
|
public static void getScoreOpen(Context context, String uid,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
commonPost(context, BASE_URL + "user/getScoreOpen", params, handler);
|
}
|
|
public static void getScoreWatch(Context context, String uid,
|
String videoDetailId, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("VideoDetailId", videoDetailId);
|
commonPost(context, BASE_URL + "user/getScoreWatch", params, handler);
|
}
|
|
public static void getScoreSave(Context context, String uid,
|
String videoDetailId, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("VideoDetailId", videoDetailId);
|
commonPost(context, BASE_URL + "user/getScoreSave", params, handler);
|
}
|
|
public static void getScoreCollect(Context context, String uid, String LoginUid,
|
String videoId, String thirdType, String type,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("LoginUid", LoginUid);
|
params.put("VideoId", videoId);
|
params.put("ThirdType", thirdType);
|
params.put("Type", type);
|
commonPost(context, BASE_URL + "user/getScoreCollect", params, handler);
|
}
|
|
|
public static void getHomeAd(Context context, String uid, String vtid, String dataKey,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Method", "getHomeAd");
|
params.put("Uid", uid);
|
params.put("Vtid", vtid);
|
if (dataKey != null) {
|
params.put("DataKey", dataKey);
|
}
|
commonPost(context, BASE_URL_V2 + "recommend", params, handler);
|
}
|
|
|
public static void getRecommendSearchSpecial(Context context,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
String uid = UserUtil.getUid(context);
|
params.put("Method", "getRecommendSearchSpecial");
|
if (uid != null)
|
params.put("Uid", uid);
|
commonPost(context, BASE_URL_V2 + "recommend", params, handler);
|
}
|
|
/**
|
* 获取搜索专题视频
|
*
|
* @param context
|
* @param id
|
* @param handler
|
*/
|
public static void getSearchSpecialVideos(Context context, String id, int page,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
String uid = UserUtil.getUid(context);
|
params.put("Method", "getSpecialVideo");
|
params.put("key", id);
|
params.put("page", page + "");
|
if (uid != null)
|
params.put("Uid", uid);
|
commonPost(context, BASE_URL_V2 + "search", params, handler);
|
}
|
|
|
/**
|
* 添加关注
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void addAttention(Context context, String uid, String loginId, String videoId,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("LoginUid", loginId);
|
params.put("VideoId", videoId);
|
commonPost(context, BASE_URL + "attention/addAttention", params, handler);
|
}
|
|
/**
|
* 取消关注
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void cancelAttention(Context context, String uid, String loginId, String videoId,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("LoginUid", loginId);
|
params.put("VideoId", videoId);
|
commonPost(context, BASE_URL + "attention/cancelAttention", params, handler);
|
}
|
|
|
/**
|
* 获取关注列表
|
*
|
* @param context
|
* @param uid
|
* @param loginId
|
* @param page
|
* @param handler
|
*/
|
public static void getAttentionList(Context context, String uid, String loginId, String page,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("LoginUid", loginId);
|
params.put("Page", page);
|
commonPost(context, BASE_URL + "attention/getAttentionList", params, handler);
|
}
|
|
public static void getCategoryBanner(Context context, String uid, String cateId,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Type", cateId);
|
commonPost(context, BASE_URL + "class/getRecommendCategoryVideoBanner", params, handler);
|
}
|
|
public static void getHomeType(Context context, String uid, String vtid, String dataKey, int page, int pageSize,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Method", "getHomeTypeNew");
|
params.put("Uid", uid);
|
params.put("Vtid", vtid);
|
params.put("Page", page + "");
|
params.put("PageSize", pageSize + "");
|
if (dataKey != null) {
|
params.put("DataKey", dataKey);
|
}
|
commonPost(context, BASE_URL_V2 + "recommend", params, handler);
|
}
|
|
|
public static void getMoreVideo(Context context, String uid, String type,
|
String page, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Type", type);
|
params.put("Page", page);
|
commonPost(context, BASE_URL + "recommend/getMoreVideo", params, handler);
|
}
|
|
/**
|
* 主页分类
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void getClass(Context context, String uid,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
commonPost(context, BASE_URL + "class/getNewClass", params, handler);
|
}
|
|
/**
|
* 精选分类
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void getChoiceClass(Context context, String uid,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Method", "getHomeClass");
|
params.put("Uid", uid);
|
commonPost(context, BASE_URL_V2 + "class", params, handler);
|
}
|
|
public static void getHotStars(Context context, String uid, String page,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Page", page);
|
commonPost(context, BASE_URL + "class/getHotStars", params, handler);
|
}
|
|
/**
|
* 发现页明星合辑
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void getRecommendStars(Context context, String uid,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
commonPost(context, BASE_URL + "found/getHotStarMainList", params, handler);
|
}
|
|
|
public static void getHotStarsVideo(Context context, String uid,
|
String starId, String page, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("StarId", starId);
|
params.put("Page", page);
|
commonPost(context, BASE_URL + "class/getHotStarsVideo", params, handler);
|
}
|
|
/**
|
* 获取真实播放路劲
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void getPlayUrl(Context context, String uid, String type, String videoId,
|
String vid, String resourceId, String eId, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Type", type);
|
params.put("VideoId", videoId);
|
params.put("Id", vid);
|
params.put("EId", eId);
|
params.put("ResourceId", resourceId);
|
commonPost(context, BASE_URL + "recommend/getPlayUrl", params, handler);
|
}
|
|
public static void getVideoList(Context context, String uid, String starId,
|
String homeType, String videoType, String page,
|
String category_two, String categoryType, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("StarId", starId);
|
params.put("HomeType", homeType);
|
params.put("VideoType", videoType);
|
params.put("Page", page);
|
params.put("Order", category_two);
|
params.put("CategoryType", categoryType);
|
commonPost(context, BASE_URL + "class/getVideoList", params, handler);
|
|
}
|
|
/**
|
* 分类首页推荐
|
*
|
* @param context
|
* @param uid
|
* @param categoryType
|
* @param handler
|
*/
|
public static void getCategoryRecommend(Context context, String uid, String categoryType, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Type", categoryType);
|
commonPost(context, BASE_URL + "class", params, handler);
|
|
}
|
|
public static void getMVideoList(Context context, String uid, String id,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Id", id);
|
commonPost(context, BASE_URL + "other/getIntersection", params, handler);
|
}
|
|
/**
|
* 专题详情
|
*
|
* @param context
|
* @param uid
|
* @param id
|
* @param handler
|
*/
|
public static void getSpecialDetail(Context context, String uid, String id,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Id", id);
|
commonPost(context, BASE_URL + "class/getSpecialDetail", params, handler);
|
}
|
|
/**
|
* 明星详情
|
*
|
* @param context
|
* @param id
|
* @param handler
|
*/
|
public static void getHotStarDetail(Context context, String uid, String id,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Id", id);
|
commonPost(context, BASE_URL + "class/getHotStarDetail", params, handler);
|
}
|
|
/**
|
* 视频评论列表
|
*
|
* @param context
|
* @param uid
|
* @param handler
|
*/
|
public static void getVideoCommentList(Context context, String uid,
|
String videoId, String thirdType, String Page,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("VideoId", videoId);
|
params.put("ThirdType", thirdType);
|
params.put("Page", Page);
|
commonPost(context, BASE_URL + "comment/getVideoCommentList", params, handler);
|
}
|
|
public static void getFirstChildType(Context context, String ParentId,
|
String uid, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("ParentId", ParentId);
|
params.put("Uid", uid);
|
commonPost(context, BASE_URL + "class/getFirstChildTypeNew", params, handler);
|
}
|
|
|
/**
|
* 么么直播数据请求
|
*
|
* @param context
|
* @param page
|
* @param handler
|
*/
|
public static void getMeMeVideoLiveList(Context context, String page,
|
ResponseHandlerInterface handler) {
|
RequestParams params = new RequestParams();
|
asyncHttpClient.post(context,
|
"http://api.memeyule.com/union/star_json?from=mugua_2&page="
|
+ page + "&size=20&sort=1", params, handler);
|
}
|
|
public static void getVideoDetail(Context context, String uid,
|
String ResourceId, String videoId, String loginid, String type,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("LoginUid", loginid);
|
params.put("VideoId", videoId);
|
params.put("ResourceId", ResourceId);
|
params.put("Type", type);
|
commonPost(context, BASE_URL + "recommend/getVideoDetail", params, handler);
|
|
}
|
|
public static void advice(Context context, String uid, String content,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Content", content);
|
commonPost(context, BASE_URL + "other/advice", params, handler);
|
}
|
|
|
public static void isCollect(Context context, String uid, String videoId,
|
String thirdType, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
params.put("Id", videoId);
|
params.put("ThirdType", thirdType);
|
commonPost(context, BASE_URL + "recommend/isCollect", params, handler);
|
}
|
|
public static void getNotice(Context context, String uid,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Uid", uid);
|
commonPost(context, BASE_URL + "other/getNotice", params, handler);
|
}
|
|
public static void getUserVideoDataCount(Context context, String uid,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Method", "getUserVideoDataCount");
|
params.put("Uid", uid);
|
String loginUid = UserUtil.getLoginUid(context);
|
if (loginUid != null) {
|
params.put("LoginUid", loginUid);
|
}
|
commonPost(context, BASE_URL_V2 + "userVideo", params, handler);
|
}
|
|
public static void getSearchVideoType(Context context, String pid,
|
ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
params.put("Method", "getSearchVideoType");
|
if (UserUtil.getUid(context) != null)
|
params.put("Uid", UserUtil.getUid(context));
|
params.put("pid", pid);
|
String loginUid = UserUtil.getLoginUid(context);
|
if (loginUid != null) {
|
params.put("LoginUid", loginUid);
|
}
|
commonPost(context, BASE_URL_V2 + "search", params, handler);
|
}
|
|
/*************事件上报**************/
|
|
public static void readNews(Context context, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
if (UserUtil.getUid(context) != null)
|
params.put("Uid", UserUtil.getUid(context));
|
String loginUid = UserUtil.getLoginUid(context);
|
if (loginUid != null) {
|
params.put("LoginUid", loginUid);
|
}
|
commonPost(context, BASE_URL_V2 + "event/readNews", params, handler);
|
}
|
|
|
public static void playDrawVideo(Context context, String from, boolean finish, ResponseHandlerInterface handler) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
if (UserUtil.getUid(context) != null)
|
params.put("Uid", UserUtil.getUid(context));
|
String loginUid = UserUtil.getLoginUid(context);
|
if (loginUid != null) {
|
params.put("LoginUid", loginUid);
|
}
|
params.put("From", from);
|
params.put("Finish", finish + "");
|
commonPost(context, BASE_URL_V2 + "event/playDrawVideo", params, handler);
|
}
|
|
public static void readNovel(Context context, long duration) {
|
LinkedHashMap<String, String> params = new LinkedHashMap<String, String>();
|
String loginUid = UserUtil.getLoginUid(context);
|
if (loginUid != null) {
|
params.put("LoginUid", loginUid);
|
}
|
params.put("Duration", duration + "");
|
commonPost(context, BASE_URL_V2 + "event/readNovel", params, new BasicTextHttpResponseCallback() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
|
}
|
});
|
}
|
|
|
public static LinkedHashMap<String, String> validateParams(
|
LinkedHashMap<String, String> params, Context context) {
|
params.put("System", "1");
|
StringBuilder sign = new StringBuilder();
|
// for (Entry<String, String> entry : params.entrySet()) {
|
// sign.append(entry.getValue());
|
// }
|
sign.append(params.get("Method"))
|
.append(StringUtils.isEmpty(params.get("Uid")) ? params.get("Device")
|
: params.get("Uid")).append(params.get("System"));
|
if (BuildConfig.DEBUG) {
|
Log.i(TAG, "sign: " + sign);
|
}
|
params.put("Sign", MD5Utils.getMD532(sign.toString()));
|
params.put("Platform", "Android");
|
params.put("YouthMode", YouthUtil.isOpenYouthMode(context) + "");
|
params.put("Channel", ManifestDataUtil.getAppMetaData(context, "UMENG_CHANNEL"));
|
return params;
|
}
|
|
@SuppressWarnings("unused")
|
private static void commonGet(Context context, String url,
|
LinkedHashMap<String, String> params,
|
ResponseHandlerInterface handler) {
|
commonGet(context, url, params, handler, true);
|
}
|
|
public static void commonGet(Context context, String url,
|
LinkedHashMap<String, String> params,
|
ResponseHandlerInterface handler, boolean asyn) {
|
params.put("Package", context.getPackageName());
|
LinkedHashMap<String, String> map = validateParams(params, context);
|
|
RequestParams requestParams = new RequestParams(map);
|
if (BuildConfig.DEBUG) {
|
Log.i(TAG, "get url: " + url + "?" + requestParams.toString());
|
}
|
if (asyn) {
|
(asyncHttpClient).get(context, url, requestParams, handler);
|
} else {
|
(syncHttpClient).get(context, url, requestParams, handler);
|
}
|
}
|
|
private static void commonPost(Context context, String url,
|
LinkedHashMap<String, String> params,
|
ResponseHandlerInterface handler) {
|
if (HanJuConstant.isDisableProxy()) {
|
commonPost(context, url, params, null, handler);
|
} else {
|
Toast.makeText(context, "服务器拒绝访问,请查看是否禁用了代理服务器!",
|
Toast.LENGTH_SHORT).show();
|
return;
|
}
|
}
|
|
private static void commonPost1(Context context, String url,
|
LinkedHashMap<String, String> params,
|
ResponseHandlerInterface handler) {
|
if (HanJuConstant.isDisableProxy()) {
|
commonPost1(context, url, params, null, handler);
|
} else {
|
Toast.makeText(context, "服务器拒绝访问,请查看是否禁用了代理服务器!",
|
Toast.LENGTH_SHORT).show();
|
return;
|
}
|
}
|
|
private static void commonPost(Context context, String url,
|
LinkedHashMap<String, String> params, HashMap<String, File> files,
|
ResponseHandlerInterface handler) {
|
commonPost(context, url, params, files, handler, true, false);
|
}
|
|
private static void commonPost1(Context context, String url,
|
LinkedHashMap<String, String> params, HashMap<String, File> files,
|
ResponseHandlerInterface handler) {
|
commonPost(context, url, params, files, handler, false, false);
|
}
|
|
/**
|
* 测试
|
*
|
* @param context
|
* @param url
|
* @param params
|
* @param files
|
* @param handler
|
*/
|
private static void commonPostTest(Context context, String url,
|
LinkedHashMap<String, String> params, HashMap<String, File> files,
|
Callback handler) {
|
requestPostByAsynWithForm(context, url, params, files, handler, false);
|
}
|
|
private static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/x-www-form-urlencoded; charset=utf-8");//mdiatype 这个需要和服务端保持一致
|
|
private static void commonPost(Context context, String url,
|
LinkedHashMap<String, String> params,
|
Callback handler) {
|
|
|
if (HanJuConstant.isDisableProxy()) {
|
commonPostTest(context, url, params, null, handler);
|
} else {
|
Toast.makeText(context, "服务器拒绝访问,请查看是否禁用了代理服务器!",
|
Toast.LENGTH_SHORT).show();
|
return;
|
}
|
}
|
|
/**
|
* okHttp post异步请求表单提交
|
*
|
* @param actionUrl 接口地址
|
* @param paramsMap 请求参数
|
* @param callBack 请求返回数据回调
|
* @param <T> 数据泛型
|
* @return
|
*/
|
private static OkHttpClient mOkHttpClient = new OkHttpClient();//okHttpClient 实例
|
|
private static void requestPostByAsynWithForm(Context context, String url,
|
LinkedHashMap<String, String> params, HashMap<String, File> files,
|
Callback handler, boolean asyn) {
|
|
try {
|
params.put("Package", context.getPackageName());
|
int version = PackageUtils2.getVersionCode(context);
|
params.put("Version", version + "");
|
params.put("Device", getDeviceId(context));
|
|
LinkedHashMap<String, String> map = validateParams(params, context);
|
FormBody.Builder builder = new FormBody.Builder();
|
for (String key : map.keySet()) {
|
params.put(key, map.get(key));
|
}
|
|
RequestBody formBody = builder.build();
|
Request.Builder builder1 = new Request.Builder();
|
final Request request = builder1.url(url).post(formBody).build();
|
final Call call = mOkHttpClient.newCall(request);
|
call.enqueue(handler);
|
} catch (Exception e) {
|
Log.e(TAG, e.toString());
|
}
|
}
|
|
public static String getDeviceId(Context context) {
|
SharedPreferences deviceInfo = context.getSharedPreferences("deviceInfo", Context.MODE_PRIVATE);
|
String deviceId = deviceInfo.getString("device", "");
|
if (StringUtils.isEmpty(deviceId)) {
|
deviceId = UTDevice.getUtdid(context);
|
if (!StringUtils.isEmpty(deviceId)) {
|
SharedPreferences.Editor editor = deviceInfo.edit();
|
editor.putString("device", deviceId);
|
editor.commit();
|
}
|
}
|
return deviceId;
|
}
|
|
private static void commonPost(Context context, String url,
|
LinkedHashMap<String, String> params, HashMap<String, File> files,
|
ResponseHandlerInterface handler, boolean asyn, boolean shortTime) {
|
params.put("Package", context.getPackageName());
|
int version = PackageUtils2.getVersionCode(context);
|
params.put("Version", version + "");
|
params.put("Device", getDeviceId(context));
|
LinkedHashMap<String, String> map = validateParams(params, context);
|
RequestParams requestParams = new RequestParams(map);
|
if (BuildConfig.DEBUG) {
|
Log.i(TAG, "post url: " + url + "?" + requestParams.toString());
|
}
|
if (files != null) {
|
for (Entry<String, File> entry : files.entrySet()) {
|
try {
|
requestParams.put(entry.getKey(), entry.getValue());
|
} catch (FileNotFoundException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
if (asyn) {
|
// asyncHttpClient.setProxy("192.168.1.122", 8888);
|
if (!shortTime)
|
asyncHttpClient.post(context, url, requestParams, handler);
|
else {
|
sortTimeAsyncHttpClient.post(context, url, requestParams, handler);
|
}
|
|
} else {
|
// syncHttpClient.post(context, url, requestParams, handler);
|
// asyncHttpClient.setProxy("192.168.1.122", 8888);
|
final Context context2 = context;
|
final String url2 = url;
|
final RequestParams requestParams2 = requestParams;
|
final ResponseHandlerInterface handler2 = handler;
|
|
syncHttpClient.post(context2, url2, requestParams2, handler2);
|
|
}
|
}
|
|
public static void commonGet(Context context, String url,
|
RequestParams params, ResponseHandlerInterface handler, boolean asyn) {
|
if (asyn) {
|
asyncHttpClient.get(context, url, params, handler);
|
} else {
|
syncHttpClient.get(context, url, params, handler);
|
}
|
}
|
|
public static void commonGet(Context context, String url,
|
ResponseHandlerInterface handler, boolean asyn) {
|
if (asyn) {
|
asyncHttpClient.get(context, url, handler);
|
} else {
|
syncHttpClient.get(context, url, handler);
|
}
|
|
}
|
}
|