Commit 83058c12 by sikang

init

parents
/build
######################
# Builds
######################
*.apk
*.ap_
/*/build/
*.class
bin/
gen/
out/
######################
# Gradle & Gradle Wrapper
######################
.gradle/
build/
!gradle/wrapper/gradle-wrapper.jar
# Local configuration file (sdk path, etc)
local.properties
######################
# Proguard folder generated by Eclipse
######################
proguard/
######################
# Logs
######################
*.log
*.log.gz
######################
# Android Studio
######################
.navigation/
captures/
######################
# Crash
######################
com_crashlytics_export_strings.xml
######################
# Signing
######################
.signing/
######################
# Intellij
######################
*.iml
.idea/
*.iws
*.ipr
*.ids
*.orig
######################
# OS Specified Files
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
\ No newline at end of file
apply plugin: 'com.android.library'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
compileOnly 'com.facebook.android:account-kit-sdk:5.+'
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.common.toolbox;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.common.cash_plugin_toolbox.test", appContext.getPackageName());
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.common.toolbox"/>
package com.common.toolbox.app_utils;
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Base64;
import java.io.*;
import java.util.UUID;
/**
* Created by SiKang on 2019/6/14.
*/
public class DeviceInfo {
private static final String SIGN_PATH = Environment.getExternalStorageDirectory() + "/sw_config/device.json";
/**
* 读取SD卡中的设备指纹
*/
public static String getDeviceSignFromSD() {
String device_sign = "";
File file = new File(SIGN_PATH);
if (file.exists()) {
try {
FileInputStream inputStream = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line);
}
br.close();
device_sign = sb.toString();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
//如果取不到就生成一个新的
if (TextUtils.isEmpty(device_sign)) {
return writeSDSign();
} else {
return device_sign;
}
}
/**
* 在SD卡中保存一个设备指纹
*/
private static String writeSDSign() {
String uuid = UUID.randomUUID().toString();
try {
File dir = new File(Environment.getExternalStorageDirectory() + "/sw_config/");
if (!dir.exists()) {
dir.mkdirs();
}
File file = new File(SIGN_PATH);
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
fw.flush();
fw.write(uuid);
fw.close();
return uuid;
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
/**
* 根据硬件信息计算设备指纹
*/
public static String getSignFromHardware() {
String device_id = Build.BOARD + Build.BRAND +
Build.CPU_ABI + Build.DEVICE +
Build.DISPLAY + Build.HOST +
Build.ID + Build.MANUFACTURER +
Build.MODEL + Build.PRODUCT +
Build.TAGS + Build.TYPE +
Build.USER;
return StringUtils.MD5(device_id);
}
}
package com.common.toolbox.app_utils;
import android.text.TextUtils;
import android.util.Base64;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* Created by SiKang on 2019/6/14.
*/
public class StringUtils {
/**
* MD5
*/
public static String MD5(String key) {
String cacheKey;
try {
final MessageDigest mDigest = MessageDigest.getInstance("MD5");
mDigest.update(key.getBytes());
cacheKey = bytesToHexString(mDigest.digest());
} catch (NoSuchAlgorithmException e) {
cacheKey = String.valueOf(key.hashCode());
}
return cacheKey;
}
private static String bytesToHexString(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
String hex = Integer.toHexString(0xFF & bytes[i]);
if (hex.length() == 1) {
sb.append('0');
}
sb.append(hex);
}
return sb.toString();
}
/**
* base64 解码
*/
public static String fromBase64(String value) {
if (!TextUtils.isEmpty(value))
return new String(Base64.decode(value.getBytes(), Base64.DEFAULT));
else
return "";
}
/**
* String转base64
*/
public static String toBase64(String value) {
byte[] bytes = value.getBytes();
if (bytes != null && bytes.length > 0)
return Base64.encodeToString(bytes, Base64.DEFAULT);
else
return "";
}
}
package com.common.toolbox.sdk_utils;
import com.facebook.accountkit.internal.AccountKitController;
import com.facebook.accountkit.internal.Initializer;
import java.lang.reflect.Field;
/**
* 切换Account Kit APPID & TOKEN
* */
public class AccountKitUtils {
public static boolean initAccountKit(String facebookAppId, String appName, String accoutkitClientToken) {
try {
Class clazz = AccountKitController.class;
Field initializerField = clazz.getDeclaredField("initializer");
initializerField.setAccessible(true);
Initializer initializer = (Initializer) initializerField.get(clazz);
Field dataFiled = initializer.getClass().getDeclaredField("data");
dataFiled.setAccessible(true);
Object data = dataFiled.get(initializer);
Field applicationIdF = data.getClass().getDeclaredField("applicationId");
applicationIdF.setAccessible(true);
Field applicationNameF = data.getClass().getDeclaredField("applicationName");
applicationNameF.setAccessible(true);
Field clientTokenF = data.getClass().getDeclaredField("clientToken");
clientTokenF.setAccessible(true);
applicationIdF.set(data, facebookAppId);
applicationNameF.set(data, appName);
clientTokenF.set(data, accoutkitClientToken);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
package com.common.toolbox.tracker;
/**
* Created by SiKang on 2019/6/14.
*/
public final class TrackEvent {
/**
* Api 参数
*/
private static String type_system = "system";
private static String action_api = "api";
private static String type_user = "user";
private static String actoin_click = "click";
private static String action_screen = "hold";
public enum Screen {
/**
* 进入主页
*/
HOME(type_user, action_screen, "sms_login"),
/**
* 进入FB登录页面
*/
ACCOUNT_KIT(type_user, action_screen, "account_kit"),
/**
* 进入SMS登录页面
*/
SMS_LOGIN(type_user, action_screen, "sms_login");
public String type;
public String action;
public String event;
Screen(String type, String action, String event) {
this.type = type;
this.action = action;
this.event = event;
}
}
public enum Click {
/**
* 点击允许权限 value: 权限名
*/
ALLOW_PERMISSION(type_user, actoin_click, "allow_permission"),
/**
* 点击拒绝权限 value: 权限名
*/
REFUSE_PERMISSION(type_user, actoin_click, "refuse_permission"),
/**
* 点击同意隐私协议
*/
AGREE_PRIVACY(type_user, actoin_click, "agreement_privacy"),
/**
* 点击一个产品
*/
PRODUCT_ITEM(type_user, actoin_click, "product_list"),
/**
* 点击登录(仅限SMS登录)
*/
SMS_LOGIN(type_user, actoin_click, "sms_login"),
/**
* 点击申请产品
*/
LOAN_APPLY(type_user, actoin_click, "Loan_apply"),
/**
* 点击开始活体
*/
START_LIVENESS(type_user, actoin_click, "start_liveness"),
/**
* 点击提交银行卡信息
*/
SUBMIT_BANK_INFO(type_user, actoin_click, "submit_bank_info"),
/**
* 点击开始KTP拍照
*/
KTP_SHOT(type_user, actoin_click, "ktp_shot"),
/**
* 点击提交KTP信息(无api调用)
*/
SUBMIT_KTP_INFO(type_user, actoin_click, "submit_ktp_info"),
/**
* 点击提交个人信息
*/
SUBMIT_PERSONAL_INFO(type_user, actoin_click, "submit_personal_info"),
/**
* 点击提交紧急联系人
*/
SUBMIT_CONTACT_INFO(type_user, actoin_click, "submit_contact_info"),
/**
* 点击开始工作证件拍照
*/
WORK_CARD_SHOT(type_user, actoin_click, "work_card_shot"),
/**
* 点击提交工作信息
*/
SUBMIT_WORK_INFO(type_user, actoin_click, "submit_work_info"),
/**
* 点击三方认证 value: 具体认证项目
*/
THIRD_PART_VERTIFY(type_user, actoin_click, "third_part_vertify"),
/**
* 点击一条贷款记录
*/
LOAN_HISTORY_ITEM(type_user, actoin_click, "loan_history_item"),
/**
* 点击取消贷款
*/
CANCEL_LOAN(type_user, actoin_click, "cancel_loan"),
/**
* 点击查看隐私协议
*/
PRIVACY_AGREEMENT(type_user, actoin_click, "privacy_agreement");
public String type;
public String action;
public String event;
Click(String type, String action, String event) {
this.type = type;
this.action = action;
this.event = event;
}
}
public enum Api {
/**
* FB登录成功
*/
ACCOUNT_KIT_LOGIN_SUCCESS(type_system, action_api, "accountkit_login_success"),
/**
* SMS登录成功
*/
SMS_LOGIN_SUCCESS(type_system, action_api, "sms_login_success"),
/**
* 用户退出登录
*/
LOG_OUT(type_system, action_api, "log_out"),
/**
* 活体识别成功
*/
LIVENESS_SUCCESS(type_system, action_api, "liveness_success"),
/**
* 提交银行卡信息成功
*/
BANK_INFO_SUBMITED(type_system, action_api, "bank_info_submited"),
/**
* 上传KTP照片成功
*/
KTP_UPLOADED(type_system, action_api, "ktp_uploaded"),
/**
* 个人信息提交成功
*/
PERSONAL_INFO_SUBMITED(type_system, action_api, "personal_info_submited"),
/**
* 紧急联系人提交成功
*/
CONTACT_INFO_SUBMITED(type_system, action_api, "contact_info_submited"),
/**
* 工作照上传成功
*/
WORK_CARD_UPLOADED(type_system, action_api, "work_card_uploaded"),
/**
* 工作信息提交成功
*/
WORK_INFO_SUBMITED(type_system, action_api, "work_card_submited"),
/**
* 取消贷款成功
*/
LOAN_CANNELED(type_system, action_api, "loan_canceled");
public String type;
public String action;
public String event;
Api(String type, String action, String event) {
this.type = type;
this.action = action;
this.event = event;
}
}
}
<resources>
<string name="app_name">cash_plugin_toolbox</string>
</resources>
package com.common.toolbox;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
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