91 lines
3.1 KiB
Java
91 lines
3.1 KiB
Java
package com.gh.common.util;
|
|
|
|
import android.content.Context;
|
|
|
|
import com.gh.base.AppController;
|
|
import com.gh.download.DownloadEntity;
|
|
import com.gh.gamecenter.retrofit.Response;
|
|
import com.gh.gamecenter.retrofit.RetrofitManager;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
import okhttp3.MediaType;
|
|
import okhttp3.RequestBody;
|
|
import okhttp3.ResponseBody;
|
|
import rx.android.schedulers.AndroidSchedulers;
|
|
import rx.schedulers.Schedulers;
|
|
|
|
/**
|
|
* Created by LGT on 2016/12/8.
|
|
* 日志上传工具类
|
|
*/
|
|
public class DataLogUtils {
|
|
|
|
// 轮播图
|
|
public static void uploadLunbotuLog(Context context, String type, String title, String location) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("location", location);
|
|
map.put("type", type);
|
|
map.put("title", title);
|
|
map.put("form", "click");
|
|
uploadLog(context, "lunbotu", map);
|
|
}
|
|
|
|
// 上传日志
|
|
public static void uploadLog(Context context, String topic, Map<String, Object> map) {
|
|
String version = PackageUtils.getVersionName(context);
|
|
String user = Installation.getUUID(context);
|
|
String channel = AppController.getInstance().getChannel();
|
|
map.put("version", version);
|
|
map.put("user", user);
|
|
map.put("device_id", TokenUtils.getDeviceId(context));
|
|
map.put("channel", channel);
|
|
|
|
Map<String, String> params = new HashMap<>();
|
|
params.put("topic", topic);
|
|
params.put("source", "GH-ASSIST-Client");
|
|
params.put("time", String.valueOf(Utils.getTime(context)));
|
|
params.put("content", new JSONObject(map).toString());
|
|
|
|
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
|
|
new JSONObject(params).toString());
|
|
RetrofitManager.getData().postLog(body)
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new Response<ResponseBody>());
|
|
}
|
|
|
|
// 网络错误
|
|
public static void uploadNeterrorLog(Context context, DownloadEntity downloadEntity) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("url", downloadEntity.getUrl());
|
|
map.put("game", downloadEntity.getName());
|
|
map.put("game_id", downloadEntity.getGameId());
|
|
map.put("platform", downloadEntity.getPlatform());
|
|
map.put("error", downloadEntity.getError());
|
|
uploadLog(context, "neterror", map);
|
|
}
|
|
|
|
// 助手更新
|
|
public static void uploadUpgradeLog(Context context, String step) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("step", step);
|
|
uploadLog(context, "upgrade", map);
|
|
}
|
|
|
|
// 链接劫持
|
|
public static void uploadHijack(Context context, DownloadEntity downloadEntity) {
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("url", downloadEntity.getUrl());
|
|
map.put("game", downloadEntity.getName());
|
|
map.put("game_id", downloadEntity.getGameId());
|
|
map.put("platform", downloadEntity.getPlatform());
|
|
map.put("hijack_url", downloadEntity.getError());
|
|
uploadLog(context, "hijack", map);
|
|
}
|
|
|
|
}
|