opt
This commit is contained in:
@@ -12,9 +12,13 @@ import com.mogo.commons.network.AllAllowedHostnameVerifier;
|
||||
import com.mogo.commons.network.Constants;
|
||||
import com.mogo.commons.network.ParamsUtil;
|
||||
import com.mogo.commons.network.X509TrustManagerImpl;
|
||||
import com.mogo.commons.storage.SpStorage;
|
||||
import com.mogo.utils.TipToast;
|
||||
import com.mogo.utils.glide.GlideApp;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.NetConfig;
|
||||
import com.zhidao.account.sdk.AccountClientManager;
|
||||
import com.zhidao.account.sdk.callback.TicketInfoCallback;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.security.SecureRandom;
|
||||
@@ -32,6 +36,8 @@ import okhttp3.OkHttpClient;
|
||||
*/
|
||||
public class AbsMogoApplication extends Application {
|
||||
|
||||
private static final String TAG = "AbsMogoApplication";
|
||||
|
||||
private static Application sApp;
|
||||
|
||||
public static Application getApp() {
|
||||
@@ -66,7 +72,7 @@ public class AbsMogoApplication extends Application {
|
||||
TipToast.init( sApp, null );
|
||||
|
||||
initNetConfig();
|
||||
initAccountSdk();
|
||||
// initAccountSdk();
|
||||
}
|
||||
|
||||
private static void initNetConfig() {
|
||||
@@ -96,7 +102,18 @@ public class AbsMogoApplication extends Application {
|
||||
return sc;
|
||||
}
|
||||
|
||||
private static void initAccountSdk(){
|
||||
// AccountClientManager.init(context,businessType,appId);
|
||||
private static void initAccountSdk() {
|
||||
AccountClientManager.init( sApp, 1, "os2.0-launcher" );
|
||||
AccountClientManager.getTicket( new TicketInfoCallback() {
|
||||
@Override
|
||||
public void onSuccess( String ticket ) {
|
||||
SpStorage.setTicket( ticket );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure( int code, String msg ) {
|
||||
Logger.w( TAG, "request ticket error code = %d, msg = %s", code, msg );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,4 +27,44 @@ public class DebugConfig {
|
||||
public static void setDebug( boolean sDebug ) {
|
||||
DebugConfig.sDebug = sDebug;
|
||||
}
|
||||
|
||||
/**
|
||||
* 研发环境
|
||||
*/
|
||||
public static final int NET_MODE_DEV = 1;
|
||||
|
||||
/**
|
||||
* 测试环境
|
||||
*/
|
||||
public static final int NET_MODE_QA = 2;
|
||||
|
||||
/**
|
||||
* 生产环境
|
||||
*/
|
||||
public static final int NET_MODE_RELEASE = 3;
|
||||
|
||||
|
||||
private static int sNetMode = NET_MODE_RELEASE;
|
||||
|
||||
/**
|
||||
* 获取网络环境类型
|
||||
*
|
||||
* @return {@link #NET_MODE_DEV}
|
||||
* {@link #NET_MODE_QA}
|
||||
* {@link #NET_MODE_RELEASE}
|
||||
*/
|
||||
public static int getNetMode() {
|
||||
return sNetMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置网络环境类型
|
||||
*
|
||||
* @param netMode {@link #NET_MODE_DEV}
|
||||
* {@link #NET_MODE_QA}
|
||||
* {@link #NET_MODE_RELEASE}
|
||||
*/
|
||||
public static void setNetMode( int netMode ) {
|
||||
DebugConfig.sNetMode = netMode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import androidx.collection.ArrayMap;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.commons.storage.SpStorage;
|
||||
import com.mogo.map.location.MogoLocation;
|
||||
import com.mogo.utils.CommonUtils;
|
||||
import com.mogo.utils.DeviceIdUtils;
|
||||
@@ -42,6 +43,7 @@ public class ParamsUtil {
|
||||
|
||||
params.put( ServerParam.DISPLAY_ID, DeviceUtil.getSystemVersion() );
|
||||
params.put( ServerParam.SN, Utils.getSn() );
|
||||
params.put( ServerParam.TICKET, SpStorage.getTicket() );
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package com.mogo.commons.network;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.mogo.commons.data.BaseData;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.RequestOptions;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
import com.mogo.utils.network.utils.Util;
|
||||
|
||||
import rx.Subscriber;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
|
||||
/**
|
||||
* Created by congtaowang on 2018/10/14.
|
||||
*/
|
||||
public abstract class SubscribeImpl< T extends BaseData > extends Subscriber< T > {
|
||||
public abstract class SubscribeImpl< T extends BaseData > implements Observer< T > {
|
||||
|
||||
protected final RequestOptions mRequestOptions;
|
||||
|
||||
@@ -29,32 +29,11 @@ public abstract class SubscribeImpl< T extends BaseData > extends Subscriber< T
|
||||
mAutoTipMsg = autoTipMsg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if ( !Util.checkAlive( mRequestOptions.getCaller() ) ) {
|
||||
unsubscribe();
|
||||
return;
|
||||
}
|
||||
final Context context = Util.getContext( mRequestOptions.getCaller() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
onFinish();
|
||||
}
|
||||
|
||||
private void onFinish() {
|
||||
onUnsubscribe();
|
||||
if ( !Util.checkAlive( mRequestOptions.getCaller() ) ) {
|
||||
unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
private void onUnsubscribe() {
|
||||
final Context context = Util.getContext( mRequestOptions.getCaller() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError( Throwable e ) {
|
||||
onFinish();
|
||||
@@ -74,18 +53,28 @@ public abstract class SubscribeImpl< T extends BaseData > extends Subscriber< T
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSubscribe( Disposable d ) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
onFinish();
|
||||
}
|
||||
|
||||
public void onSuccess( T o ) {
|
||||
Logger.e( TAG, GsonUtil.jsonFromObject( o ) );
|
||||
}
|
||||
|
||||
public void onError( String message, int code ) {
|
||||
|
||||
Logger.e( TAG, "%d - %s", code, message );
|
||||
}
|
||||
|
||||
private static boolean isTicketUpdated = false;
|
||||
|
||||
private void onUpdateTicket() {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.mogo.commons.storage;
|
||||
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.utils.storage.SharedPrefsMgr;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-01-03
|
||||
* <p>
|
||||
* sp 公共缓存区域
|
||||
*/
|
||||
public class SpStorage {
|
||||
|
||||
public static String getTicket() {
|
||||
return SharedPrefsMgr.getInstance( AbsMogoApplication.getApp() ).getString( "ticket" );
|
||||
}
|
||||
|
||||
public static void setTicket( String ticket ) {
|
||||
SharedPrefsMgr.getInstance( AbsMogoApplication.getApp() ).putString( "ticket", ticket );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user