Commit ceda4d81 authored by leichao.gao's avatar leichao.gao

配置

parent b5d1e4be
package com.base.datarecovery.bean
class ConfigBean() {
var open: Int = 0
var num: Int = 0
var delay: Long = 0
var actionS: Int = 1
var lockS: Int = 1
var adClickCount: Int = 10
var adShowCount: Int = 45
var adInterval: Int = 10
var notificationInterval: Int = 60
var timerS: Int = 1
var timerDelay: Int = 1
var timerInterval: Int = 5
var maxMultiClick: Int = 4
var naAdS: Int = 0
}
......@@ -9,7 +9,7 @@ object ConfigHelper {
// 域名
const val eventUrl = "https://rp.easyfilemanager.xyz"
// const val apiUrl = "https://api.easyfilemanager.xyz"
const val apiUrl = "https://api.easyfilemanager.xyz"
// admob广告id
const val openAdmobId = "/6499/example/app-open"
......
package com.base.datarecovery.utils
import android.util.Base64
import java.security.SecureRandom
import javax.crypto.Cipher
import javax.crypto.spec.GCMParameterSpec
import javax.crypto.spec.SecretKeySpec
object AESHelper {
private const val aesKey = "r07y7is0zk7bej34"
private val cipher by lazy {
Cipher.getInstance("AES/GCM/NoPadding")
}
fun encrypt(content: String): String {
try {
val iv = ByteArray(12).apply {
SecureRandom().nextBytes(this)
}
val contentBytes = content.toByteArray(Charsets.UTF_8)
val params = GCMParameterSpec(128, iv)
cipher.init(
Cipher.ENCRYPT_MODE,
secretKey, params
)
val encryptData = cipher.doFinal(contentBytes)
if (encryptData.size != contentBytes.size + 16) {
throw IllegalStateException("Encryption failed")
}
val message = ByteArray(12 + contentBytes.size + 16)
System.arraycopy(iv, 0, message, 0, 12)
System.arraycopy(encryptData, 0, message, 12, encryptData.size)
return String(Base64.encode(message, Base64.NO_WRAP), Charsets.UTF_8)
} catch (_: Exception) {
}
return content
}
@Synchronized
fun decrypt(content: String): String {
try {
val con = content.replace(" ".toRegex(), "+")
val contentByte = Base64.decode(con, Base64.NO_WRAP)
require(contentByte.size >= 12 + 16)
val params = GCMParameterSpec(128, contentByte, 0, 12)
cipher.init(
Cipher.DECRYPT_MODE,
secretKey, params
)
val decryptData = cipher.doFinal(contentByte, 12, contentByte.size - 12)
return String(decryptData, Charsets.UTF_8)
} catch (_: Exception) {
}
return content
}
private val secretKey by lazy {
SecretKeySpec(aesKey.toByteArray(), "AES")
}
}
\ No newline at end of file
package com.test.easy.easycleanerjunk.helps
import android.util.Log
import com.base.datarecovery.bean.ConfigBean
import com.base.datarecovery.help.ConfigHelper
import com.base.datarecovery.utils.AESHelper
import com.google.gson.Gson
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.HttpURLConnection
import java.net.URL
object ComUtils {
//
private val url by lazy {
val pkg = ConfigHelper.packageName
val url = StringBuilder(
"${ConfigHelper.apiUrl}/${
pkg.filter { it.isLowerCase() }.substring(4, 9)
}spk"
)
url.append("?pkg=$pkg")
url.toString()
}
fun doGet(): String {
val urlPath = url
Log.d("okhttp", urlPath ?: "")
try {
val conn: HttpURLConnection = URL(urlPath).openConnection() as HttpURLConnection
conn.setRequestMethod("GET")
conn.connectTimeout = 150000
if (200 == conn.getResponseCode()) {
val json = BufferedReader(InputStreamReader(conn.getInputStream())).readLine()
Log.d("okhttp", json)
return json
}
} catch (e: Exception) {
e.printStackTrace()
Log.d("okhttp", e.toString())
}
return "{ \"success\": false,\n \"errorMsg\": \"后台服务器开小差了!\",\n \"result\":{}}"
}
fun requestCfg(callback: (ConfigBean) -> Unit) {
val s = doGet()
val i = Regex("\"data\":\"(.*?)\"").find(s)
if (i.toString() != "null") {
i!!.groupValues[1].let {
val str = AESHelper.decrypt(it)
val gson = Gson()
val bean = gson.fromJson(str, Map::class.java)
// Log.d("jiekou",str)
// SPUtils.getInstance().put("actionS", bean.actionS);
// SPUtils.getInstance().put("open", bean.open);
// SPUtils.getInstance().put("num", bean.num);
// SPUtils.getInstance().put("delay", bean.delay);
// SPUtils.getInstance().put("lockS", bean.lockS);
// SPUtils.getInstance().put("notification_interval", bean.notificationInterval);
// SPUtils.getInstance().put("timerS", bean.timerS)
// SPUtils.getInstance().put("timerDelay", bean.timerDelay)
// SPUtils.getInstance().put("timerInterval", bean.timerInterval)
// SPUtils.getInstance().put("naAdS", bean.naAdS)
// adDisplayInterval = bean.adInterval
// maxMultiClick = bean.maxMultiClick
// AdDisplayUtils.getInstance().setMaxAdDisplayCount(bean.adShowCount)
// AdDisplayUtils.getInstance().maxAdClickCount = bean.adClickCount
// callback(bean)
}
}
}
}
\ 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