阴影添加,对接v1d1的user.ghzhushou.com接口

This commit is contained in:
huangzhuanghua
2016-12-23 11:00:40 +08:00
parent 46668e32f6
commit 4b2e3d876b
36 changed files with 355 additions and 199 deletions

View File

@ -4,12 +4,14 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Environment;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import com.gh.common.constant.Config;
import com.gh.gamecenter.retrofit.Response;
import com.gh.gamecenter.retrofit.RetrofitManager;
import com.gh.gamecenter.retrofit.StringResponse;
import com.tencent.stat.StatConfig;
@ -30,6 +32,9 @@ import java.net.URL;
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;
@ -38,6 +43,10 @@ public class TokenUtils {
// 注册设备
public static synchronized String register(final Context context) {
HashMap<String, String> params = new HashMap<>();
params.put("MANUFACTURER", Build.MANUFACTURER);
params.put("MODEL", Build.MODEL);
params.put("ANDROID_SDK", String.valueOf(Build.VERSION.SDK_INT));
params.put("ANDROID_VERSION", Build.VERSION.RELEASE);
String android_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
if (!TextUtils.isEmpty(android_id)) {
params.put("ANDROID_ID", android_id);
@ -113,7 +122,6 @@ public class TokenUtils {
// 获取用户token
public static synchronized String getToken(Context context, boolean isCheck) {
SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
String token = sp.getString("token", null);
if (isCheck) {
@ -183,6 +191,54 @@ public class TokenUtils {
return null;
}
// 检查设备信息是否已经上传完整
public static synchronized void checkDeviceInfo(final Context context) {
final SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
final HashMap<String, String> params = new HashMap<>();
if (!sp.getBoolean("isUploadExtra", false)) {
params.put("MANUFACTURER", Build.MANUFACTURER);
params.put("MODEL", Build.MODEL);
params.put("ANDROID_SDK", String.valueOf(Build.VERSION.SDK_INT));
params.put("ANDROID_VERSION", Build.VERSION.RELEASE);
}
if (!sp.getBoolean("isUploadMac", true)) {
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
String mac = wm.getConnectionInfo().getMacAddress();
if (!TextUtils.isEmpty(mac) || !":::::".equals(mac)) {
params.put("MAC", mac);
}
}
if (!sp.getBoolean("isUploadMid", true)) {
String mid = StatConfig.getMid(context);
if (!TextUtils.isEmpty(mid) || !"0".equals(mid)) {
params.put("MTA_ID", mid);
}
}
if (params.size() != 0) {
new Thread(){
@Override
public void run() {
RequestBody body = RequestBody.create(MediaType.parse("application/json"),
new JSONObject(params).toString());
RetrofitManager.getUser().postDevice(TokenUtils.getToken(context), body,
TokenUtils.getDeviceId(context))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Response<ResponseBody>() {
@Override
public void onResponse(ResponseBody response) {
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean("isUploadExtra", true);
editor.putBoolean("isUploadMac", true);
editor.putBoolean("isUploadMid", true);
editor.apply();
}
});
}
}.start();
}
}
// 获取服务器时间
public static synchronized void getTime(Context context) {
final SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
@ -268,29 +324,6 @@ public class TokenUtils {
}
// 启动助手时检查uuid
public static void checkDeviceID(Context context) {
String uuid = loadSharedPreferences(context, false);
if (uuid == null) {
// 重新获取uuid保存
return;
}
// 检查
if (loadSharedPreferences(context, true) == null){
saveSharedPreferences(context, uuid);
}
if (loadDataFile(context ,true) == null){
saveDataFile(context, uuid);
}
String[] dirName = {"/gh-uuid", "/system", "/data"};
for (int i = 0; i< 3; i++) {
String s = loadSDCard(dirName[i]);
if (s == null) {
svaeSDCard(uuid, dirName[i]);
}
}
}
public static synchronized String getDeviceId(Context context) {
return loadSharedPreferences(context, false);
}