version:1.5
fix:迁移到奥乐云平台 add:
This commit is contained in:
1 parent
2462bafa85
commit
ed8310da47
713 files changed
+6024
-4805
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package com.aoleyun.os.network;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : fanhuitong
|
||||
* e-mail :
|
||||
* @date : 2021/10/22 18:09
|
||||
* desc :
|
||||
* version: 1.0
|
||||
*/
|
||||
public class AppPasswdBean implements Serializable {
|
||||
private static final long serialVersionUID = 777139872907974502L;
|
||||
|
||||
String app_package;
|
||||
String password;
|
||||
|
||||
public String getApp_package() {
|
||||
return app_package;
|
||||
}
|
||||
|
||||
public void setApp_package(String app_package) {
|
||||
this.app_package = app_package;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.aoleyun.os.network;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
public class BaseResponse<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 5468533687801294972L;
|
||||
|
||||
public int code;
|
||||
public String msg;
|
||||
public T data;
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.aoleyun.os.network;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.aoleyun.os.jpush.TagAliasOperatorHelper;
|
||||
import com.aoleyun.os.uiuiutils.JGYUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.annotations.NonNull;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
import static com.aoleyun.os.jpush.TagAliasOperatorHelper.ACTION_SET;
|
||||
import static com.aoleyun.os.jpush.TagAliasOperatorHelper.sequence;
|
||||
|
||||
/**
|
||||
* @author : fanhuitong
|
||||
* e-mail :
|
||||
* @date : 2021/10/27 15:31
|
||||
* desc :
|
||||
* version: 1.0
|
||||
*/
|
||||
public class HTTPInterface {
|
||||
private static final String TAG = HTTPInterface.class.getSimpleName();
|
||||
|
||||
public static void getAppPasswd() {
|
||||
NetWorkManager.getInstance().getAppPasswordObservable()
|
||||
.subscribe(new Observer<BaseResponse<List<AppPasswdBean>>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("getAppPasswd", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse<List<AppPasswdBean>> listBaseResponse) {
|
||||
Log.e("getAppPasswd", "onNext: " + listBaseResponse);
|
||||
if (listBaseResponse.code == 200) {
|
||||
List<AppPasswdBean> beanList = listBaseResponse.data;
|
||||
String jsonString = JsonParser.parseString(new Gson().toJson(beanList)).getAsJsonArray().toString();
|
||||
MMKV.defaultMMKV().encode("ApplicationLock", jsonString);
|
||||
Log.e("getAppPasswd", "onNext: " + jsonString);
|
||||
} else {
|
||||
MMKV.defaultMMKV().encode("ApplicationLock", "");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("getAppPasswd", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getAppPasswd", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
synchronized public static void setJpushTags(final Context context) {
|
||||
NetWorkManager.getInstance()
|
||||
.getJpushTagsObservable()
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(@NonNull Disposable d) {
|
||||
Log.e(TAG + ":" + "setJpushTags", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(@NonNull BaseResponse response) {
|
||||
if (response.code == 200) {
|
||||
JsonObject jsonObject = JsonParser.parseString(new Gson().toJson(response.data)).getAsJsonObject();
|
||||
String batch = jsonObject.get("batch").getAsString();
|
||||
Log.e(TAG + ":" + "setJpushTags", "onNext: " + batch);
|
||||
if (!TextUtils.isEmpty(batch)) {
|
||||
Set set = new HashSet();
|
||||
set.add(batch);
|
||||
JGYUtils.getInstance().getAppPlatform(new JGYUtils.GetAppPlatformCallback() {
|
||||
@Override
|
||||
public void AppPlatform(int platform) {
|
||||
if (platform == JGYUtils.MTKPlatform) {
|
||||
set.add(JGYUtils.MTKTag);
|
||||
} else if (platform == JGYUtils.ZhanruiPlatform) {
|
||||
set.add(JGYUtils.ZhanruiTag);
|
||||
}
|
||||
}
|
||||
});
|
||||
setTag(context, set);
|
||||
} else {
|
||||
Log.e(TAG + ":" + "setJpushTags", "onNext: " + "batch empty");
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG + ":" + "setJpushTags", "onNext: " + response.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable e) {
|
||||
Log.e(TAG + ":" + "setJpushTags", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e(TAG + ":" + "setJpushTags", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void setTag(Context context, Set set) {
|
||||
TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
|
||||
tagAliasBean.action = ACTION_SET;
|
||||
sequence++;
|
||||
tagAliasBean.tags = set;
|
||||
tagAliasBean.isAliasAction = false;
|
||||
TagAliasOperatorHelper.getInstance().handleAction(context, sequence, tagAliasBean);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.aoleyun.os.network;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
|
||||
import com.aoleyun.os.TTUtils.Utils;
|
||||
import com.aoleyun.os.network.api.AddAppLog;
|
||||
import com.aoleyun.os.network.api.CheckUpdate;
|
||||
import com.aoleyun.os.network.api.GetAppPassword;
|
||||
import com.aoleyun.os.network.api.GetJpushTagsApi;
|
||||
import com.aoleyun.os.network.api.RunningApp;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.OkHttpClient;
|
||||
import retrofit2.CallAdapter;
|
||||
import retrofit2.Converter;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public class NetWorkManager {
|
||||
private static NetWorkManager sInstance;
|
||||
private Context mContext;
|
||||
private static Retrofit mRetrofit;
|
||||
|
||||
private NetWorkManager(Context context) {
|
||||
this.mContext = context;
|
||||
if (null == mRetrofit) {
|
||||
mRetrofit = new Retrofit.Builder()
|
||||
.client(okHttpClient)
|
||||
.baseUrl(ROOT_URL)
|
||||
.addConverterFactory(gsonConverterFactory)
|
||||
.addCallAdapterFactory(rxJavaCallAdapterFactory)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static void init(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new NetWorkManager(context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static NetWorkManager getInstance() {
|
||||
if (sInstance == null) {
|
||||
throw new IllegalStateException("You must be init NetworkManager first");
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private static final String ROOT_URL = URLPath.ROOT_URL;
|
||||
|
||||
private static final long CACHE_SIZE = 1024 * 1024 * 32;// 缓存文件最大限制大小20M
|
||||
private static String cacheDirectory = Environment.getExternalStorageDirectory() + "/okttpcaches"; // 设置缓存文件路径
|
||||
private static Cache cache = new Cache(new File(cacheDirectory), CACHE_SIZE); //
|
||||
private static final OkHttpClient okHttpClient;
|
||||
private static final int TIME_OUT = 5;
|
||||
|
||||
static {
|
||||
//如果无法生存缓存文件目录,检测权限使用已经加上,检测手机是否把文件读写权限禁止了
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||
builder.connectTimeout(TIME_OUT, TimeUnit.SECONDS); // 设置连接超时时间
|
||||
builder.writeTimeout(TIME_OUT, TimeUnit.SECONDS);// 设置写入超时时间
|
||||
builder.readTimeout(TIME_OUT, TimeUnit.SECONDS);// 设置读取数据超时时间
|
||||
builder.retryOnConnectionFailure(true);// 设置进行连接失败重试
|
||||
builder.cache(cache);// 设置缓存
|
||||
okHttpClient = builder.build();
|
||||
}
|
||||
|
||||
private static CallAdapter.Factory rxJavaCallAdapterFactory = RxJava2CallAdapterFactory.create();
|
||||
private static Converter.Factory gsonConverterFactory = GsonConverterFactory.create();
|
||||
|
||||
public Observable<BaseResponse> getRunningAppObservable(String json) {
|
||||
return mRetrofit.create(RunningApp.class)
|
||||
.sendAppInfo(Utils.getSerial(), json)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public Observable<BaseResponse<List<AppPasswdBean>>> getAppPasswordObservable() {
|
||||
return mRetrofit.create(GetAppPassword.class)
|
||||
.getAppPasswd(Utils.getSerial())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取极光推送的tag
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Observable<BaseResponse> getJpushTagsObservable() {
|
||||
return mRetrofit.create(GetJpushTagsApi.class)
|
||||
.getJpushTags(Utils.getSerial())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
public AddAppLog getapplogControl() {
|
||||
return mRetrofit.create(AddAppLog.class);
|
||||
}
|
||||
|
||||
public CheckUpdate getCheckUpdateObservable() {
|
||||
return mRetrofit.create(CheckUpdate.class);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.aoleyun.os.network;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class NewestAppUpdateResult implements Serializable {
|
||||
private static final long serialVersionUID = -934484906663584753L;
|
||||
|
||||
long id ;
|
||||
String url;
|
||||
int version_code;
|
||||
String app_name;
|
||||
@SerializedName("package")
|
||||
String app_package;
|
||||
String app_md5;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getApp_name() {
|
||||
return app_name;
|
||||
}
|
||||
|
||||
public void setApp_name(String app_name) {
|
||||
this.app_name = app_name;
|
||||
}
|
||||
|
||||
public String getApp_package() {
|
||||
return app_package;
|
||||
}
|
||||
|
||||
public void setApp_package(String app_package) {
|
||||
this.app_package = app_package;
|
||||
}
|
||||
|
||||
public int getVersion_code() {
|
||||
return version_code;
|
||||
}
|
||||
|
||||
public void setVersion_code(int version_code) {
|
||||
this.version_code = version_code;
|
||||
}
|
||||
|
||||
public String getApp_md5() {
|
||||
return app_md5;
|
||||
}
|
||||
|
||||
public void setApp_md5(String app_md5) {
|
||||
this.app_md5 = app_md5;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonParser.parseString(new Gson().toJson(this)).getAsJsonObject().toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.aoleyun.os.network;
|
||||
|
||||
public class URLPath {
|
||||
public static final String ROOT_URL = "https://led.aoleyun.cn/api/";
|
||||
public static final String APP_LOG = "app/addAppLog";
|
||||
public static final String RUN_NEW_APP = "app/runNewApp";
|
||||
//更新
|
||||
public final static String GET_NEWESTAPPUPDATE = "Silent/silent";
|
||||
//是否有应用密码锁
|
||||
public final static String GET_APP_ISLOCKED = "And/isApplicationLock";
|
||||
//验证应用密码锁
|
||||
public final static String CHECK_APP_PASSWD = "And/checkApplicationLock";
|
||||
//获取所有应用密码
|
||||
public final static String GET_APP_PASSWD = "And/getApplicationLock";
|
||||
//获取设备标签
|
||||
public static final String GET_DEVICES_TAGS = "Sn/getSnTag";
|
||||
|
||||
|
||||
//删除alias
|
||||
public static final String DELETE_JPUSH_ALIAS = "https://device.jpush.cn/v3/aliases/";
|
||||
//删除tags
|
||||
public static final String DELETE_JPUSH_TAG = "https://device.jpush.cn/v3/tags/";
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.aoleyun.os.network.api;
|
||||
|
||||
import com.aoleyun.os.network.BaseResponse;
|
||||
import com.aoleyun.os.network.URLPath;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface AddAppLog {
|
||||
@FormUrlEncoded
|
||||
@POST(URLPath.APP_LOG)
|
||||
Observable<BaseResponse> addLog(
|
||||
@Field("sn") String sn,
|
||||
@Field("packageName") String packageName,
|
||||
@Field("versionCode") long versionCode,
|
||||
@Field("createTime") long createTime,
|
||||
@Field("type") long type
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.aoleyun.os.network.api;
|
||||
|
||||
import com.aoleyun.os.network.BaseResponse;
|
||||
import com.aoleyun.os.network.NewestAppUpdateResult;
|
||||
import com.aoleyun.os.network.URLPath;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface CheckUpdate {
|
||||
@FormUrlEncoded
|
||||
@POST(URLPath.GET_NEWESTAPPUPDATE)
|
||||
Observable<BaseResponse<NewestAppUpdateResult>> getCheckUpdate(
|
||||
@Field("package")String packageName,
|
||||
@Field("versionCode")int versionCode,
|
||||
@Field("type")int type
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.aoleyun.os.network.api;
|
||||
|
||||
import com.aoleyun.os.network.AppPasswdBean;
|
||||
import com.aoleyun.os.network.BaseResponse;
|
||||
import com.aoleyun.os.network.URLPath;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
/**
|
||||
* @author : fanhuitong
|
||||
* e-mail :
|
||||
* @date : 2021/10/22 18:06
|
||||
* desc :
|
||||
* version: 1.0
|
||||
*/
|
||||
public interface GetAppPassword {
|
||||
@GET(URLPath.GET_APP_PASSWD)
|
||||
Observable<BaseResponse<List<AppPasswdBean>>> getAppPasswd(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.aoleyun.os.network.api;
|
||||
|
||||
|
||||
import com.aoleyun.os.network.BaseResponse;
|
||||
import com.aoleyun.os.network.URLPath;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface GetJpushTagsApi {
|
||||
@GET(URLPath.GET_DEVICES_TAGS)
|
||||
Observable<BaseResponse> getJpushTags(
|
||||
@Query("sn") String sn
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.aoleyun.os.network.api;
|
||||
|
||||
import com.aoleyun.os.network.BaseResponse;
|
||||
import com.aoleyun.os.network.URLPath;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface RunningApp {
|
||||
@FormUrlEncoded
|
||||
@POST(URLPath.RUN_NEW_APP)
|
||||
Observable<BaseResponse> sendAppInfo(
|
||||
@Field("sn") String sn,
|
||||
@Field("app") String app
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user