Commit dc4c934e authored by fengruiyu's avatar fengruiyu

项目正常跑起来

parent 7c16a2b2
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="CompilerConfiguration"> <component name="CompilerConfiguration">
<bytecodeTargetLevel target="1.8" /> <bytecodeTargetLevel target="11" />
</component> </component>
</project> </project>
\ No newline at end of file
...@@ -5,10 +5,13 @@ ...@@ -5,10 +5,13 @@
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" /> <configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
</configurations> </configurations>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
<option name="id" value="Android" /> <option name="id" value="Android" />
</component> </component>
<component name="SuppressKotlinCodeStyleNotification">
<option name="disableForAll" value="true" />
</component>
</project> </project>
\ No newline at end of file
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<component name="RunConfigurationProducerService"> <component name="RunConfigurationProducerService">
<option name="ignoredProducers"> <option name="ignoredProducers">
<set> <set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" /> <option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" /> <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" /> <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
......
...@@ -10,6 +10,10 @@ android { ...@@ -10,6 +10,10 @@ android {
targetSdkVersion rootProject.ext.android.targetSdkVersion targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode rootProject.ext.android.versionCode versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName versionName rootProject.ext.android.versionName
//flavorDimensions "default"
buildConfigField ("boolean","IS_DEV","false")
} }
dataBinding { dataBinding {
...@@ -19,31 +23,50 @@ android { ...@@ -19,31 +23,50 @@ android {
sourceCompatibility rootProject.ext.java_version["compileJavaVersion"] sourceCompatibility rootProject.ext.java_version["compileJavaVersion"]
targetCompatibility rootProject.ext.java_version["targetJavaVersion"] targetCompatibility rootProject.ext.java_version["targetJavaVersion"]
} }
productFlavors { // buildTypes {
// 开发版本 // debug {
auto { // minifyEnabled false
buildConfigField ('boolean','IS_DEV',"true") // //signingConfig signingConfigs.release
manifestPlaceholders = [ // zipAlignEnabled true
app_logo_name: "Auto" // versionNameSuffix "-dev"
] // proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} // }
// 线上产品版本 // release {
product { // minifyEnabled false
buildConfigField ('boolean','IS_DEV',"false") // zipAlignEnabled true
manifestPlaceholders = [ // shrinkResources false
app_logo_name: "线上" // //signingConfig signingConfigs.release
] // proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} // }
} // }
// productFlavors {
// // 开发版本
// auto {
// buildConfigField ('boolean','IS_DEV',"true")
// manifestPlaceholders = [
// app_logo_name: "Auto"
// ]
// }
// // 线上产品版本
// product {
// buildConfigField ('boolean','IS_DEV',"false")
// manifestPlaceholders = [
// app_logo_name: "线上"
// ]
// }
// }
} }
dependencies { dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"]) implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' testImplementation rootProject.ext.support["junit"]
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1' // implementation 'androidx.appcompat:appcompat:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' // implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// testImplementation 'junit:junit:4.12'
// androidTestImplementation 'androidx.test.ext:junit:1.1.1'
// androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
api project(':library_base') api project(':library_base')
......
# 环境名
name=product
api.base.url=https://
isProduct=true
\ No newline at end of file
# 环境名 默认
name=test
api.base.url=http://apitest.
isProduct=false
\ No newline at end of file
{
"supplier":{
"vivo":{
"appid":"103881568"
},
"xiaomi":{
"appid": "2882303761518348857"
},
"huawei":{
"appid": "101833995"
},
"oppo":{
"appid": "30251013"
}
}
}
# 环境名
name=product
api.base.url=https://api.
isProduct=true
\ No newline at end of file
{
"supplier":{
"vivo":{
"appid":"103881568"
},
"xiaomi":{
"appid": "2882303761518348857"
},
"huawei":{
"appid": "101833995"
},
"oppo":{
"appid": "30251013"
}
}
}
...@@ -15,8 +15,11 @@ android { ...@@ -15,8 +15,11 @@ android {
versionName rootProject.ext.android.versionName versionName rootProject.ext.android.versionName
flavorDimensions '23' flavorDimensions '23'
multiDexEnabled true multiDexEnabled true
buildConfigField ("boolean","IS_DEV","false") buildConfigField ("boolean","IS_DEV","false")
buildConfigField ("String","AppKeyPre","abcd") //从com.android.tools.build:gradle:4.1.0开始,build.gradle文件正式移除了versionName和versionCode,参照Android开发者官网。
buildConfigField ("String","VERSION_NAME", "\"" + rootProject.ext.android.versionName + "\"")
buildConfigField ("String","VERSION_CODE", "\"" + rootProject.ext.android.versionCode + "\"")
buildConfigField ("String","AppKeyPre","\"" + "abcd" + "\"")
} }
...@@ -52,17 +55,17 @@ android { ...@@ -52,17 +55,17 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
} }
productFlavors { // productFlavors {
//包含所有环境 // //包含所有环境
auto { // auto {
buildConfigField ("boolean","IS_DEV","true") // buildConfigField ("boolean","IS_DEV","true")
} // }
// 线上产品版本 // // 线上产品版本
product { // product {
buildConfigField ("boolean","IS_DEV","false") // buildConfigField ("boolean","IS_DEV","false")
} // }
} // }
//
compileOptions { compileOptions {
sourceCompatibility rootProject.ext.java_version["compileJavaVersion"] sourceCompatibility rootProject.ext.java_version["compileJavaVersion"]
......
...@@ -23,13 +23,13 @@ android { ...@@ -23,13 +23,13 @@ android {
buildConfigField ("int","BUILD_VERSION","${buildVersion}") buildConfigField ("int","BUILD_VERSION","${buildVersion}")
} }
// noArg { noArg {
// annotation("com.jeme.base.annotation.Poko") annotation("com.jeme.base.annotation.Poko")
// } }
//
// allOpen { allOpen {
// annotation("com.jeme.base.annotation.Poko") annotation("com.jeme.base.annotation.Poko")
// } }
} }
dependencies { dependencies {
implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs') implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
......
...@@ -4,9 +4,7 @@ import android.app.Application; ...@@ -4,9 +4,7 @@ import android.app.Application;
import android.view.Gravity; import android.view.Gravity;
import com.alibaba.android.arouter.launcher.ARouter; import com.alibaba.android.arouter.launcher.ARouter;
import com.fry.base.BuildConfig;
import com.fry.base.global.Constants; import com.fry.base.global.Constants;
import com.fry.base.utils.PropertyUtils;
import com.tencent.bugly.crashreport.CrashReport; import com.tencent.bugly.crashreport.CrashReport;
import me.goldze.mvvmhabit.utils.KLog; import me.goldze.mvvmhabit.utils.KLog;
...@@ -21,15 +19,14 @@ import me.goldze.mvvmhabit.utils.ToastUtils; ...@@ -21,15 +19,14 @@ import me.goldze.mvvmhabit.utils.ToastUtils;
public class BaseModuleInit implements IModuleInit<Void> { public class BaseModuleInit implements IModuleInit<Void> {
@Override @Override
public boolean onInitAhead(Application application,boolean isMainProcess) { public boolean onInitAhead(Application application,boolean isMainProcess) {
// 环境配置读取初始化优先级最高,要先初始化
PropertyUtils.init(application);
//开启打印日志 //开启打印日志
KLog.init(BuildConfig.DEBUG); // KLog.init(BuildConfig.DEBUG);
//初始化阿里路由框架 // //初始化阿里路由框架
if (BuildConfig.DEBUG) { // if (BuildConfig.DEBUG) {
ARouter.openLog(); // 打印日志 // ARouter.openLog(); // 打印日志
ARouter.openDebug(); // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险) // ARouter.openDebug(); // 开启调试模式(如果在InstantRun模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险)
} // }
// 尽可能早,推荐在Application中初始化 // 尽可能早,推荐在Application中初始化
ARouter.init(application); ARouter.init(application);
ToastUtils.setGravity(Gravity.CENTER,0,0); ToastUtils.setGravity(Gravity.CENTER,0,0);
...@@ -42,9 +39,9 @@ public class BaseModuleInit implements IModuleInit<Void> { ...@@ -42,9 +39,9 @@ public class BaseModuleInit implements IModuleInit<Void> {
// 这里实现SDK初始化,appId替换成你的在Bugly平台申请的appId // 这里实现SDK初始化,appId替换成你的在Bugly平台申请的appId
// 调试时,将第三个参数改为true // 调试时,将第三个参数改为true
// Bugly.init(application, Constants.BUGLY_APP_ID, BuildConfig.IS_DEV); // Bugly.init(application, Constants.BUGLY_APP_ID, BuildConfig.IS_DEV);
if(!BuildConfig.IS_DEV && ! SPUtils2.getInstance().decodeBoolean("isFirstOpen", true)){ // if(!BuildConfig.IS_DEV && ! SPUtils2.getInstance().decodeBoolean("isFirstOpen", true)){
CrashReport.initCrashReport(application, Constants.BUGLY_APP_ID, false); // CrashReport.initCrashReport(application, Constants.BUGLY_APP_ID, false);
} // }
return null; return null;
} }
......
package com.fry.base.global; package com.fry.base.global;
import com.fry.base.utils.PropertyUtils;
/** /**
* Created by jeme on 2019/9/17 * Created by jeme on 2019/9/17
*/ */
...@@ -56,6 +54,8 @@ public class Constants { ...@@ -56,6 +54,8 @@ public class Constants {
} }
public static String getBaseUrl() { public static String getBaseUrl() {
return PropertyUtils.getApiBaseUrl(); //fry
// return PropertyUtils.getApiBaseUrl();
return "";
} }
} }
\ No newline at end of file
...@@ -52,7 +52,9 @@ public class InitConstants { ...@@ -52,7 +52,9 @@ public class InitConstants {
public static int getVersionCode() { public static int getVersionCode() {
if (VERSION_CODE == null) { if (VERSION_CODE == null) {
return BuildConfig.VERSION_CODE; //fry
//return BuildConfig.VERSION_CODE;
return 0;
} }
return VERSION_CODE; return VERSION_CODE;
} }
...@@ -66,6 +68,7 @@ public class InitConstants { ...@@ -66,6 +68,7 @@ public class InitConstants {
public static String getVersionName() { public static String getVersionName() {
if (VERSION_NAME == null) { if (VERSION_NAME == null) {
return BuildConfig.VERSION_NAME; return BuildConfig.VERSION_NAME;
return "";
} }
return VERSION_NAME; return VERSION_NAME;
} }
......
package com.fry.base.netwrok package com.fry.base.netwrok
import android.text.TextUtils import android.text.TextUtils
import android.util.Log import android.util.Log
import com.fry.base.bean.AppRequest import com.fry.base.BuildConfig
import com.fry.base.utils.encry.AESUtils import com.fry.base.bean.AppRequest
import com.fry.base.utils.encry.Base64 import com.fry.base.utils.encry.AESUtils
import com.fry.base.utils.encry.MD5 import com.fry.base.utils.encry.Base64
import com.google.gson.Gson import com.fry.base.utils.encry.MD5
import okhttp3.* import com.google.gson.Gson
import okio.Buffer import okhttp3.*
import org.json.JSONObject import okio.Buffer
import java.io.IOException import org.json.JSONObject
import java.io.UnsupportedEncodingException import java.io.IOException
import java.nio.charset.Charset import java.io.UnsupportedEncodingException
import java.nio.charset.Charset
/**
* 拦截器 /**
*/ * 拦截器
class OkHttpInterceptor(aesKey: String) : Interceptor { */
private var aesKey = "" class OkHttpInterceptor(aesKey: String) : Interceptor {
private var aesKey = ""
/**
* 实例化拦截器对象 /**
*/ * 实例化拦截器对象
init { */
this.aesKey = aesKey init {
} this.aesKey = aesKey
}
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response { @Throws(IOException::class)
// val tokenID: String = UserManager.INSTANCE.getTokenID() override fun intercept(chain: Interceptor.Chain): Response {
val tokenID: String = "" // val tokenID: String = UserManager.INSTANCE.getTokenID()
val time = System.currentTimeMillis() val tokenID: String = ""
val channel = createChannel() val time = System.currentTimeMillis()
var request = chain.request() val channel = createChannel()
// 加密 var request = chain.request()
request = encrypt(request, tokenID, time, channel) // 加密
// header request = encrypt(request, tokenID, time, channel)
val builder = addHeader(request, tokenID, time, channel) // header
// 解密 val builder = addHeader(request, tokenID, time, channel)
var response = chain.proceed(builder) // 解密
response = decrypt(response) var response = chain.proceed(builder)
return response response = decrypt(response)
} return response
}
/**
* 创建渠道 /**
* * 创建渠道
* @return *
*/ * @return
private fun createChannel(): String { */
var channel: String = "" private fun createChannel(): String {
// var channel: String = CommonUtils.getAppMetaData(App.instance, "CHANNEL_NAME") var channel: String = ""
// try { // var channel: String = CommonUtils.getAppMetaData(App.instance, "CHANNEL_NAME")
// // 穿山甲分包渠道 // try {
// val ttChannel = HumeSDK.getChannel(App.instance) // // 穿山甲分包渠道
// if (!TextUtils.isEmpty(ttChannel)) { // val ttChannel = HumeSDK.getChannel(App.instance)
// // 此处方式不能修改,已和后端约定 // if (!TextUtils.isEmpty(ttChannel)) {
// channel = channel + "_" + ttChannel // // 此处方式不能修改,已和后端约定
// } // channel = channel + "_" + ttChannel
// } catch (e: Exception) { // }
// e.printStackTrace() // } catch (e: Exception) {
// } // e.printStackTrace()
return channel // }
} return channel
}
/**
* 添加header /**
* * 添加header
* @param request *
* @param tokenID * @param request
* @param time * @param tokenID
* @param channel * @param time
* @return * @param channel
*/ * @return
@Throws(UnsupportedEncodingException::class) */
private fun addHeader(request: Request, tokenID: String, time: Long, channel: String): Request { @Throws(UnsupportedEncodingException::class)
return request.newBuilder() private fun addHeader(request: Request, tokenID: String, time: Long, channel: String): Request {
.addHeader("version", BuildConfig.VERSION_NAME) return request.newBuilder()
.addHeader("token", tokenID) .addHeader("version", BuildConfig.VERSION_NAME)
.addHeader("channel", channel) .addHeader("token", tokenID)
.addHeader("new-session", MD5.GetMD5Code(time.toString())) .addHeader("channel", channel)
.addHeader("last-session", Base64.encode(time.toString().toByteArray(charset("UTF-8")))) .addHeader("new-session", MD5.GetMD5Code(time.toString()))
.build() .addHeader("last-session", Base64.encode(time.toString().toByteArray(charset("UTF-8"))))
} .build()
}
/**
* json加密 /**
* * json加密
* @param request *
* @param tokenID * @param request
* @param time * @param tokenID
* @param channel * @param time
* @return * @param channel
* @throws IOException * @return
*/ * @throws IOException
@Throws(IOException::class) */
private fun encrypt(request: Request, tokenID: String, time: Long, channel: String): Request { @Throws(IOException::class)
//获取请求body,只有@Body 参数的requestBody 才不会为 null private fun encrypt(request: Request, tokenID: String, time: Long, channel: String): Request {
var request = request //获取请求body,只有@Body 参数的requestBody 才不会为 null
val requestBody = request.body var request = request
if (requestBody != null) { val requestBody = request.body
val buffer = Buffer() if (requestBody != null) {
requestBody.writeTo(buffer) val buffer = Buffer()
var charset = Charset.forName("UTF-8") requestBody.writeTo(buffer)
val contentType = requestBody.contentType() var charset = Charset.forName("UTF-8")
if (contentType != null) { val contentType = requestBody.contentType()
charset = contentType.charset(charset) if (contentType != null) {
} charset = contentType.charset(charset)
}
// 原始报文
var valueStr = buffer.readString(charset!!) // 原始报文
val checkStr = valueStr var valueStr = buffer.readString(charset!!)
val checkStr = valueStr
//加密
if (isSign(request) && !TextUtils.isEmpty(valueStr)) { //加密
valueStr = AESUtils.encrypt(valueStr, aesKey) if (isSign(request) && !TextUtils.isEmpty(valueStr)) {
} valueStr = AESUtils.encrypt(valueStr, aesKey)
}
// 渠道
val channelName = "android_$channel" // 渠道
val channelName = "android_$channel"
// sign
val requestSign = "$tokenID:$channelName:$time" // sign
val sign = MD5.GetMD5Code(requestSign) val requestSign = "$tokenID:$channelName:$time"
// 验证 val sign = MD5.GetMD5Code(requestSign)
val check = MD5.GetMD5Code("$requestSign:$checkStr") // 验证
val appRequest = AppRequest(channelName, sign, check, valueStr) val check = MD5.GetMD5Code("$requestSign:$checkStr")
val appRequest = AppRequest(channelName, sign, check, valueStr)
val body: RequestBody = RequestBody.create(contentType, Gson().toJson(appRequest))
request = request.newBuilder() val body: RequestBody = RequestBody.create(contentType, Gson().toJson(appRequest))
.post(body) request = request.newBuilder()
.build() .post(body)
} .build()
return request }
} return request
}
/**
* json解密 /**
* * json解密
* @param response *
* @return * @param response
* @throws IOException * @return
*/ * @throws IOException
@Throws(IOException::class) */
private fun decrypt(response: Response): Response { @Throws(IOException::class)
var response = response private fun decrypt(response: Response): Response {
if (response.isSuccessful && isSign(response.request)) { var response = response
//the response data if (response.isSuccessful && isSign(response.request)) {
val body = response.body //the response data
val source = body!!.source() val body = response.body
source.request(Long.MAX_VALUE) // Buffer the entire body. val source = body!!.source()
val buffer = source.buffer() source.request(Long.MAX_VALUE) // Buffer the entire body.
var charset = Charset.defaultCharset() val buffer = source.buffer()
val contentType = body.contentType() var charset = Charset.defaultCharset()
if (contentType != null) { val contentType = body.contentType()
charset = contentType.charset(charset) if (contentType != null) {
} charset = contentType.charset(charset)
var rspString: String? = buffer.clone().readString(charset!!) }
// 解密 var rspString: String? = buffer.clone().readString(charset!!)
try { // 解密
val json = JSONObject(rspString) try {
if (!json.isNull("data")) { val json = JSONObject(rspString)
val data = json["data"] if (!json.isNull("data")) {
rspString = AESUtils.detrypt(data.toString(), aesKey) val data = json["data"]
val jsonArray = JSONObject(rspString) rspString = AESUtils.detrypt(data.toString(), aesKey)
json.put("data", jsonArray) val jsonArray = JSONObject(rspString)
rspString = json.toString() json.put("data", jsonArray)
// rspString = json.toString().replace("\\", ""); rspString = json.toString()
} // rspString = json.toString().replace("\\", "");
} catch (e: Exception) { }
Log.d("OkHttpInterceptor", "json解密失败。url:${response.request.url}响应报文:${buffer.clone().readString(charset)}") } catch (e: Exception) {
e.printStackTrace() Log.d("OkHttpInterceptor", "json解密失败。url:${response.request.url}响应报文:${buffer.clone().readString(charset)}")
} e.printStackTrace()
val responseBody = ResponseBody.create(contentType, rspString!!) }
response = response.newBuilder().body(responseBody).build() val responseBody = ResponseBody.create(contentType, rspString!!)
} response = response.newBuilder().body(responseBody).build()
return response }
} return response
}
/**
* 是否加/解密 - 接口非common都加/解密 /**
* * 是否加/解密 - 接口非common都加/解密
* @param request *
* @return true=加/解密 * @param request
*/ * @return true=加/解密
private fun isSign(request: Request): Boolean { */
val url = request.url.toString() private fun isSign(request: Request): Boolean {
//是否加密标识 val url = request.url.toString()
var isSign = true //是否加密标识
if (!TextUtils.isEmpty(url)) { var isSign = true
isSign = !url.contains("common/") if (!TextUtils.isEmpty(url)) {
} isSign = !url.contains("common/")
return isSign }
} return isSign
}
} }
\ No newline at end of file
package com.fry.base.utils;
import android.content.Context;
import androidx.annotation.StringDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Field;
/**
* 2019-10-18 created
*
* @author KOM
*/
public class BuildConfigUtils {
/**
* 在build.gradle中配置字段的KEY
*/
@StringDef({ConfigField.DEBUG, ConfigField.APPLICATION_ID,
ConfigField.BUILD_TYPE, ConfigField.FLAVOR,
ConfigField.VERSION_CODE, ConfigField.VERSION_NAME})
@Retention(RetentionPolicy.SOURCE)
public @interface ConfigField {
String DEBUG = "DEBUG";
String APPLICATION_ID = "APPLICATION_ID";
String BUILD_TYPE = "BUILD_TYPE";
String FLAVOR = "FLAVOR";
String VERSION_CODE = "VERSION_CODE";
String VERSION_NAME = "VERSION_NAME";
}
/**
* 获取APP模块下配置的 buildConfigField 的值
*/
public static <T> T getBuildConfigValue(Context context, @ConfigField String fieldName) {
try {
Class<?> clazz = Class.forName(context.getPackageName() + ".BuildConfig");
Field field = clazz.getField(fieldName);
return (T) field.get(null);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
}
package com.fry.base.utils;
import androidx.annotation.StringDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* 2019-10-18 created
*
* @author KOM
*/
@StringDef({PropertyKey.BASE_URL,PropertyKey.IS_PRODUCT})
@Retention(RetentionPolicy.SOURCE)
public @interface PropertyKey {
String NAME = "name";
String BASE_URL = "api.base.url";
String IS_PRODUCT = "isProduct";
}
package com.fry.base.utils;
import android.content.Context;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import me.goldze.mvvmhabit.utils.Utils;
/**
* 2019-10-18 created
*
* @author KOM
*/
public class PropertyUtils {
private static Properties mProps = new Properties();
private static boolean mHasLoadProps = false;
private static final Object mLock = new Object();
private static final String TAG = "PropertyUtils";
public PropertyUtils() {
}
/**
* 初始化 级别应该最高
*/
public static void init(Context context) {
if (!mHasLoadProps) {
synchronized (mLock) {
if (!mHasLoadProps) {
try {
ConfigManager.EnvironmentType environmentType = ConfigManager.getDefault().getAppEnv();
InputStream is = context.getAssets().open(environmentType.configType+".properties");
mProps.load(is);
mHasLoadProps = true;
Log.d("PropertyUtils", "load config.properties successfully!");
} catch (IOException var4) {
Log.e("PropertyUtils", "load config.properties error!", var4);
}
}
}
}
}
public static String getApiBaseUrl() {
if (mProps == null) {
throw new IllegalArgumentException("must call #UtilsManager.init(context) in application");
} else {
return mProps.getProperty(PropertyKey.BASE_URL, "");
}
}
public static boolean isProduct() {
return mProps.getProperty(PropertyKey.IS_PRODUCT, "false").equals("true");
}
public static String getEnvironmentName() {
return mProps.getProperty(PropertyKey.NAME, "");
}
public static ConfigManager.EnvironmentType environmentMap() {
String envName = getEnvironmentName();
switch (envName){
case "product":
return ConfigManager.EnvironmentType.PRODUCT;
default:
return ConfigManager.EnvironmentType.TEST;
}
}
public static boolean isDebug() {
Boolean isDebug = BuildConfigUtils.getBuildConfigValue(
Utils.getContext(), BuildConfigUtils.ConfigField.DEBUG);
return isDebug == null ? true : isDebug;
}
public static String getValueByKey(String key) {
return mProps.getProperty(key, "");
}
}
package com.fry.base.utils.encry; package com.fry.base.utils.encry;
import android.util.Log; import android.util.Log;
import javax.crypto.Cipher; import com.fry.base.BuildConfig;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import Decoder.BASE64Decoder; import javax.crypto.spec.SecretKeySpec;
import Decoder.BASE64Encoder;
import Decoder.BASE64Decoder;
public class AESUtils { import Decoder.BASE64Encoder;
private static final String vis = MD5.GetMD5Code("goldcamera_2021").substring(8, 24); public class AESUtils {
// public static final String key = "123456";
public static String CIPHER_ALGORITHM = "AES/CBC/PKCS5Padding"; // optional value AES/DES/DESede private static final String vis = MD5.GetMD5Code("goldcamera_2021").substring(8, 24);
// public static final String key = "123456";
private static SecretKeySpec getKey(String strKey) throws Exception { public static String CIPHER_ALGORITHM = "AES/CBC/PKCS5Padding"; // optional value AES/DES/DESede
byte[] arrBTmp = strKey.getBytes();
byte[] arrB = new byte[16]; // 创建一个空的16位字节数组(默认值为0) private static SecretKeySpec getKey(String strKey) throws Exception {
byte[] arrBTmp = strKey.getBytes();
for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) { byte[] arrB = new byte[16]; // 创建一个空的16位字节数组(默认值为0)
arrB[i] = arrBTmp[i];
} for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
SecretKeySpec skeySpec = new SecretKeySpec(arrB, "AES"); arrB[i] = arrBTmp[i];
return skeySpec; }
} SecretKeySpec skeySpec = new SecretKeySpec(arrB, "AES");
return skeySpec;
public static String encrypt(String message, String key) { }
try {
SecretKeySpec skeySpec = getKey(key); public static String encrypt(String message, String key) {
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); try {
IvParameterSpec iv = new IvParameterSpec(vis.getBytes()); SecretKeySpec skeySpec = getKey(key);
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
byte[] encrypted = cipher.doFinal(message.getBytes("UTF-8")); IvParameterSpec iv = new IvParameterSpec(vis.getBytes());
return new BASE64Encoder().encode(encrypted); cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
} catch (Exception e) { byte[] encrypted = cipher.doFinal(message.getBytes("UTF-8"));
} return new BASE64Encoder().encode(encrypted);
return ""; } catch (Exception e) {
} }
return "";
}
public static String detrypt(String message, String key) {
try {
byte[] res = new BASE64Decoder().decodeBuffer(message); public static String detrypt(String message, String key) {
SecretKeySpec skeySpec = getKey(key); try {
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); byte[] res = new BASE64Decoder().decodeBuffer(message);
IvParameterSpec iv = new IvParameterSpec(vis.getBytes()); SecretKeySpec skeySpec = getKey(key);
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
byte[] detrypted = cipher.doFinal(res); IvParameterSpec iv = new IvParameterSpec(vis.getBytes());
return new String(detrypted, "UTF-8"); cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
} catch (Exception e) { byte[] detrypted = cipher.doFinal(res);
} return new String(detrypted, "UTF-8");
return ""; } catch (Exception e) {
} }
return "";
private static String getBK1() { }
return BuildConfig.AppKeyPre;
} private static String getBK1() {
return BuildConfig.AppKeyPre;
private static String getBK2() { }
return "nnnnnn";
} private static String getBK2() {
return "nnnnnn";
private static String getBK3(int size) { }
StringBuffer sb = new StringBuffer();
for (int i = 1; i <= size; i++) { private static String getBK3(int size) {
sb.append(i); StringBuffer sb = new StringBuffer();
} for (int i = 1; i <= size; i++) {
return sb.toString(); sb.append(i);
} }
return sb.toString();
public static String getDefaultKey() { }
StringBuffer sb = new StringBuffer();
sb.append(getBK1()) public static String getDefaultKey() {
.append(getBK2()) StringBuffer sb = new StringBuffer();
.append(getBK3(6)); sb.append(getBK1())
return sb.toString(); .append(getBK2())
} .append(getBK3(6));
} return sb.toString();
}
}
#Wed Jun 30 17:38:32 CST 2021 #Wed Jun 30 19:52:15 CST 2021
VERSION_BUILD=2228 VERSION_BUILD=2320
...@@ -19,7 +19,9 @@ android { ...@@ -19,7 +19,9 @@ android {
} }
dependencies { dependencies {
implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs') //implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
provided files('libs\\xpopup-release.aar')
//support //support
api rootProject.ext.support["support-v4"] api rootProject.ext.support["support-v4"]
api rootProject.ext.support["appcompat-v7"] api rootProject.ext.support["appcompat-v7"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment