| | |
| | | import java.io.File; |
| | | import java.io.FileNotFoundException; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | | import java.util.Iterator; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map.Entry; |
| | | import java.util.Set; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import android.content.Context; |
| | |
| | | import android.widget.Toast; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.JsonObject; |
| | | import com.lcjian.library.DeviceUuidFactory; |
| | | import com.lcjian.library.okhttp.OkHttpUtils; |
| | | import com.lcjian.library.util.ManifestDataUtil; |
| | |
| | | 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.weikou.beibeivideo.util.BeibeiConstant; |
| | | import com.weikou.beibeivideo.util.UserUtil; |
| | | |
| | | import org.json.JSONArray; |
| | | |
| | | import okhttp3.Call; |
| | | import okhttp3.Callback; |
| | |
| | | params.put("Lat", lat); |
| | | params.put("Lng", lng); |
| | | params.put("Channel", channel); |
| | | try { |
| | | params.put("UtdId", UTDevice.getUtdid(context)); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | if (!StringUtils.isBlank(BeibeiVideoApplication.deviceNumber)) { |
| | | params.put("DeviceName", BeibeiVideoApplication.deviceName); |
| | | params.put("DeviceNumber", BeibeiVideoApplication.deviceNumber); |
| | |
| | | params.put("Page", page); |
| | | commonPost(context, BASE_URL + "class", params, handler); |
| | | } |
| | | |
| | | /** |
| | | * 获取观看记录 |
| | | * |
| | | * @param context |
| | | * @param uid |
| | | * @param page |
| | | * @param handler |
| | | */ |
| | | |
| | | public static void getWatchHistory(Context context, String uid, int page, |
| | | ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); |
| | | params.put("Method", "getWatchHistory"); |
| | | params.put("Uid", uid); |
| | | params.put("Page", page + ""); |
| | | commonPost(context, BASE_URL + "userVideo", params, handler); |
| | | } |
| | | |
| | | /** |
| | | * 删除历史记录 |
| | | * |
| | | * @param context |
| | | * @param uid |
| | | * @param ids |
| | | * @param handler |
| | | */ |
| | | public static void deleteWatchHistory(Context context, String uid, Set<String> ids, |
| | | ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); |
| | | params.put("Method", "deleteWatchHistory"); |
| | | params.put("Uid", uid); |
| | | params.put("Ids", new JSONArray(ids).toString()); |
| | | commonPost(context, BASE_URL + "userVideo", params, handler); |
| | | } |
| | | |
| | | |
| | | public static void search(Context context, String uid, String key, |
| | | String contentType, String page, ResponseHandlerInterface handler) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 电话号码绑定 |
| | | * |
| | | * @param context |
| | | * @param loginUid |
| | | * @param phone |
| | | * @param code |
| | | * @param accessToken |
| | | * @param handler |
| | | */ |
| | | |
| | | public static void bindPhone(Context context, String loginUid, String phone, String code, String accessToken, ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); |
| | | params.put("Method", "bindPhone"); |
| | | params.put("loginUid", loginUid); |
| | | if (phone != null) |
| | | params.put("phone", phone); |
| | | if (code != null) |
| | | params.put("code", code); |
| | | if (accessToken != null) |
| | | params.put("accessToken", accessToken); |
| | | commonPost(context, BASE_URL + "user", params, handler); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 绑定QQ |
| | | * |
| | | * @param context |
| | | * @param loginUid |
| | | * @param name |
| | | * @param portrait |
| | | * @param openId |
| | | * @param handler |
| | | */ |
| | | public static void bindQQ(Context context, String loginUid, String name, String portrait, String openId, ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); |
| | | params.put("Method", "bindQQ"); |
| | | params.put("loginUid", loginUid); |
| | | if (name != null) |
| | | params.put("Name", name); |
| | | if (portrait != null) |
| | | params.put("Portrait", portrait); |
| | | if (openId != null) |
| | | params.put("OpenId", openId); |
| | | commonPost(context, BASE_URL + "user", params, handler); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 是否允许一键登录 |
| | | * |
| | | * @param context |
| | | * @param loginUid |
| | | * @param handler |
| | | */ |
| | | public static void allowOneKeyLogin(Context context, String loginUid, ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); |
| | | params.put("Method", "allowOneKeyLogin"); |
| | | params.put("loginUid", loginUid); |
| | | commonPost(context, BASE_URL + "user", params, handler); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 绑定微信 |
| | | * |
| | | * @param context |
| | | * @param loginUid |
| | | * @param code |
| | | * @param handler |
| | | */ |
| | | public static void bindWX(Context context, String loginUid, String code, ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); |
| | | params.put("Method", "bindWX"); |
| | | params.put("loginUid", loginUid); |
| | | if (code != null) |
| | | params.put("code", code); |
| | | commonPost(context, BASE_URL + "user", params, handler); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取验证码 |
| | | * |
| | | * @param context |
| | |
| | | params.put("Method", "sendVerifyCode"); |
| | | params.put("Uid", uid); |
| | | params.put("Email", name); |
| | | commonPost(context, BASE_URL + "user", params, handler); |
| | | } |
| | | |
| | | /** |
| | | * 发送绑定验证码 |
| | | * |
| | | * @param context |
| | | * @param loginUid |
| | | * @param phone |
| | | * @param handler |
| | | */ |
| | | public static void sendBindVerifyCode(Context context, String loginUid, String phone, |
| | | ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); |
| | | params.put("Method", "sendBindVerifyCode"); |
| | | params.put("loginUid", loginUid); |
| | | params.put("phone", phone); |
| | | commonPost(context, BASE_URL + "user", params, handler); |
| | | } |
| | | |
| | |
| | | public static void getPersonInfo(Context context, String uid, String loginUid, |
| | | ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); |
| | | params.put("Method", "getLoginUserInfo"); |
| | | params.put("Uid", uid); |
| | | params.put("LoginUid", loginUid); |
| | | commonPost(context, BASE_URL + "user", params, handler); |
| | | params.put("loginUid", loginUid); |
| | | commonPost(context, BASE_URL + "user/getUserInfo", params, handler); |
| | | } |
| | | |
| | | /** |
| | |
| | | String personSign, String portrait, String nickName, |
| | | ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); |
| | | params.put("Method", "updateLoginUserInfo"); |
| | | 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", params, handler); |
| | | params.put("loginUid", loginUid); |
| | | if (sex != null) |
| | | params.put("sex", sex); |
| | | if (birthday != null) |
| | | params.put("birthday", birthday); |
| | | if (personSign != null) |
| | | params.put("personSign", personSign); |
| | | if (portrait != null) |
| | | params.put("portrait", portrait); |
| | | if (nickName != null) |
| | | params.put("nickName", nickName); |
| | | commonPost(context, BASE_URL + "user/updateUserInfo", params, handler); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | |
| | | public static void getHomeAd(Context context, String uid, String vtid, |
| | | 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 + "recommend", params, handler); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | public static void getHomeType(Context context, String uid, String vtid, |
| | | 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", "getHomeType"); |
| | | 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 + "recommend", params, handler); |
| | | } |
| | | |
| | | |
| | | public static void getHomeVideoList(Context context, String id, int page, |
| | | ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); |
| | | params.put("Method", "getHomeVideoList"); |
| | | params.put("Id", id); |
| | | params.put("Page", page + ""); |
| | | commonPost(context, BASE_URL + "recommend", params, handler); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | public static void getVideoDetail(Context context, String uid, |
| | | String ResourceId, String videoId, String loginid, String type, |
| | | String ResourceId, String videoId, Integer position, String loginid, String type, String from, |
| | | ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); |
| | | params.put("Method", "getVideoDetail"); |
| | | params.put("Uid", uid); |
| | | params.put("LoginUid", loginid); |
| | | params.put("VideoId", videoId); |
| | | if (position != null) { |
| | | params.put("Position", position + ""); |
| | | } |
| | | |
| | | if (from != null) { |
| | | params.put("From", from + ""); |
| | | } |
| | | params.put("ResourceId", ResourceId); |
| | | params.put("Type", type); |
| | | commonPost(context, BASE_URL + "recommend", params, handler); |
| | | |
| | | } |
| | | |
| | | |
| | | public static void uploadSession(Context context, String sessionId, |
| | | String type, |
| | | ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); |
| | | params.put("Method", "uploadSession"); |
| | | if (sessionId != null) |
| | | params.put("sessionId", sessionId); |
| | | if (type != null) |
| | | params.put("type", type); |
| | | commonPost(context, BASE_URL + "session", params, handler); |
| | | |
| | | } |
| | | |
| | |
| | | * @param handler |
| | | */ |
| | | public static void getVideoEpisodeList(Context context, String uid, |
| | | String ResourceId, String videoId, int page, |
| | | String ResourceId, String videoId, int page,int pageSize, |
| | | ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); |
| | | params.put("Method", "getVideoEpisodeList"); |
| | | params.put("Uid", uid); |
| | | params.put("Page", page + ""); |
| | | params.put("PageSize", pageSize + ""); |
| | | params.put("VideoId", videoId); |
| | | params.put("ResourceId", ResourceId); |
| | | commonPost(context, BASE_URL + "recommend", params, handler); |
| | |
| | | params.put("Method", "advice"); |
| | | params.put("Uid", uid); |
| | | params.put("Content", content); |
| | | commonPost(context, BASE_URL + "other", params, handler); |
| | | } |
| | | |
| | | |
| | | //播放统计 |
| | | public static void playStatistic(Context context, String videoId, String resourceId, |
| | | ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); |
| | | params.put("Method", "playStatistic"); |
| | | params.put("VideoId", videoId); |
| | | params.put("ResourceId", resourceId); |
| | | commonPost(context, BASE_URL + "other", params, handler); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | public static void getFuntvAuthCode(Context context, |
| | | ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); |
| | | params.put("Method", "getFuntvAuthCode"); |
| | | commonPost(context, BASE_URL + "other", params, handler); |
| | | } |
| | | |
| | | |
| | | public static void getBaiDuNewsTypeList(Context context, |
| | | ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<>(); |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 推送绑定Token |
| | | * |
| | | * @param context |
| | | * @param type |
| | | * @param token |
| | | * @param handler |
| | | */ |
| | | public static void pushBindToken(Context context, String type, String token, |
| | | ResponseHandlerInterface handler, boolean async) { |
| | | String loginUid = UserUtil.getLoginUid(context); |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<>(); |
| | | if (loginUid != null) |
| | | |
| | | if (type != null) |
| | | params.put("type", type); |
| | | |
| | | if (token != null) |
| | | params.put("regId", token); |
| | | |
| | | String model = android.os.Build.MODEL; |
| | | if (model != null) |
| | | params.put("model", model); |
| | | |
| | | String version = android.os.Build.VERSION.RELEASE; |
| | | if (version != null) { |
| | | params.put("androidVersion", version); |
| | | } |
| | | |
| | | |
| | | commonPost(context, BASE_URL + "push/bindDeviceToken", params, null, handler, async, false); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 上传PPTV播放记录 |
| | | * |
| | | * @param context |
| | | * @param cid |
| | | * @param vid |
| | | * @param handler |
| | | */ |
| | | public static void uploadPPTVPlayRecord(Context context, String cid, String vid, |
| | | ResponseHandlerInterface handler) { |
| | | String loginUid = UserUtil.getLoginUid(context); |
| | | String uid = UserUtil.getUid(context); |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<>(); |
| | | if (loginUid != null) |
| | | params.put("loginUid", loginUid); |
| | | if (uid != null) |
| | | params.put("Uid", uid); |
| | | params.put("Cid", cid); |
| | | params.put("Vid", vid); |
| | | commonPost(context, BASE_URL + "video/play/pptvPlay", params, handler); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 付费视频的购买活动 |
| | | * |
| | | * @param context |
| | | * @param cid |
| | | * @param vid |
| | | * @param handler |
| | | */ |
| | | public static void getPPTVVIPVideoActivity(Context context, String url, String cid, String vid, |
| | | ResponseHandlerInterface handler) { |
| | | String loginUid = UserUtil.getLoginUid(context); |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<>(); |
| | | if (loginUid != null) |
| | | params.put("loginUid", loginUid); |
| | | if (url != null) { |
| | | params.put("url", url); |
| | | } |
| | | params.put("cid", cid); |
| | | params.put("vid", vid); |
| | | commonPost(context, BASE_URL + "video/play/getPPTVVIPVideoActivity", params, handler); |
| | | } |
| | | |
| | | |
| | | 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("Channel", ManifestDataUtil.getAppMetaData(context, "UMENG_CHANNEL")); |
| | | |
| | | //签名 |
| | | List<String> list = new ArrayList<>(); |
| | | for (Iterator<String> its = params.keySet().iterator(); its.hasNext(); ) { |
| | | String key = its.next(); |
| | | list.add(key + "=" + params.get(key)); |
| | | } |
| | | Collections.sort(list); |
| | | String str = StringUtils.toString(list, "&"); |
| | | String sign = MD5Utils.getMD532(str + "8888B&*@-uWan88/',@@^"); |
| | | params.put("Sign", sign); |
| | | return params; |
| | | } |
| | | |
| | |
| | | private static void commonPost(Context context, String url, |
| | | LinkedHashMap<String, String> params, |
| | | ResponseHandlerInterface handler) { |
| | | |
| | | LinkedHashMap<String, String> newParams = new LinkedHashMap<String, String>(); |
| | | //移除为null的值 |
| | | for (Iterator<String> its = params.keySet().iterator(); its.hasNext(); ) { |
| | | String key = its.next(); |
| | | if (params.get(key) != null) { |
| | | newParams.put(key, params.get(key)); |
| | | } |
| | | } |
| | | |
| | | |
| | | if (BeibeiConstant.isDisableProxy()) { |
| | | commonPost(context, url, params, null, handler); |
| | | commonPost(context, url, newParams, null, handler); |
| | | } else { |
| | | Toast.makeText(context, "服务器拒绝访问,请查看是否禁用了代理服务器!", |
| | | Toast.LENGTH_SHORT).show(); |
| | |
| | | int version = PackageUtils2.getVersionCode(context); |
| | | params.put("Version", version + ""); |
| | | params.put("Device", getDeviceId(context)); |
| | | try { |
| | | params.put("UtdId", UTDevice.getUtdid(context)); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | LinkedHashMap<String, String> map = validateParams(params, context); |
| | | FormBody.Builder builder = new FormBody.Builder(); |
| | | for (String key : map.keySet()) { |
| | |
| | | int version = PackageUtils2.getVersionCode(context); |
| | | params.put("Version", version + ""); |
| | | params.put("Device", getDeviceId(context)); |
| | | try { |
| | | params.put("UtdId", UTDevice.getUtdid(context)); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | LinkedHashMap<String, String> map = validateParams(params, context); |
| | | RequestParams requestParams = new RequestParams(map); |
| | | if (BuildConfig.DEBUG) { |