|
@@ -4,6 +4,7 @@ import android.app.Activity
|
|
|
import android.content.Context
|
|
|
import android.content.Intent
|
|
|
import android.os.Build
|
|
|
+import android.util.Base64
|
|
|
import android.util.Log
|
|
|
import android.widget.Toast
|
|
|
import com.google.firebase.Firebase
|
|
@@ -15,10 +16,12 @@ import io.newuniverse.SDK.nuSDKService
|
|
|
import io.nexilis.service.core.Data
|
|
|
import io.nexilis.service.core.Network
|
|
|
import io.nexilis.service.core.decrypt
|
|
|
-import io.nexilis.service.core.getSharedPreferences
|
|
|
+import io.nexilis.service.core.domain
|
|
|
+import io.nexilis.service.core.pref
|
|
|
import io.nexilis.service.core.optString
|
|
|
import io.nexilis.service.core.put
|
|
|
import kotlinx.coroutines.launch
|
|
|
+import org.json.JSONObject
|
|
|
import java.security.SecureRandom
|
|
|
import java.util.Locale
|
|
|
import java.util.concurrent.TimeUnit
|
|
@@ -35,10 +38,20 @@ class Api {
|
|
|
|
|
|
fun connect(account: String, activity: Activity) {
|
|
|
Log.d(tag, "connect:$account")
|
|
|
+ activity.startService(Intent(activity, nuSDKService::class.java))
|
|
|
Thread {
|
|
|
try {
|
|
|
- val domain = Network().getSync("https://nexilis.io/dipp/NuN1v3rs3/Qm3r4i0/get_ip_domain?account=$account")
|
|
|
- Log.d(tag, "domain:${domain?.decrypt()}")
|
|
|
+ val urlData = Network().getSync("https://nexilis.io/dipp/NuN1v3rs3/Qm3r4i0/get_ip_domain?account=$account") ?: return@Thread
|
|
|
+ Log.d(tag, "urlData:${urlData}")
|
|
|
+ val decode = Base64.decode(urlData, Base64.DEFAULT).toString(Charsets.UTF_8)
|
|
|
+ val json = JSONObject(decode.decrypt())
|
|
|
+ val arrayAddress = json.getJSONArray("address")
|
|
|
+ val domain = json.getString("domain")
|
|
|
+ val address = arrayAddress.getJSONObject(0)
|
|
|
+ val ip = address.getString("ip")
|
|
|
+ val port = address.getString("portA").toInt()
|
|
|
+ activity.pref().domain = domain
|
|
|
+ Log.d(tag, "domain:${activity.pref().domain}")
|
|
|
val options = FirebaseOptions.Builder()
|
|
|
.setProjectId("push-kit-de2e3")
|
|
|
.setApplicationId("1:36827599888:android:29e65c0ec8a560c5916695")
|
|
@@ -50,11 +63,10 @@ class Api {
|
|
|
} catch (e: Exception) {
|
|
|
Firebase.initialize(activity.applicationContext, options, FirebaseApp.DEFAULT_APP_NAME)
|
|
|
}
|
|
|
- activity.startService(Intent(activity, nuSDKService::class.java))
|
|
|
while (!nuSDKService.bServiceStarted()) {
|
|
|
Thread.sleep(100)
|
|
|
}
|
|
|
- val preferences = activity.getSharedPreferences()
|
|
|
+ val preferences = activity.pref()
|
|
|
preferences.put(key = "api", value = account)
|
|
|
val random =
|
|
|
String.format(Locale.getDefault(), "%010d", SecureRandom().nextInt(Int.MAX_VALUE))
|
|
@@ -68,12 +80,12 @@ class Api {
|
|
|
activity,
|
|
|
SdkCallback::class.java,
|
|
|
SdkCallback(),
|
|
|
- "202.158.33.26",
|
|
|
- 62823,
|
|
|
+ ip,
|
|
|
+ port,
|
|
|
session,
|
|
|
"09:00",
|
|
|
false,
|
|
|
- "202.158.33.26:62823"
|
|
|
+ "$ip:$port"
|
|
|
)
|
|
|
val signature: String = nuSDKService.getInstance(pass).sGetSignature()
|
|
|
if ("1,1,1,1,1,1,1,1,1,1,1,1" != signature) nuSDKService.getInstance(pass)
|
|
@@ -128,8 +140,8 @@ class Api {
|
|
|
}
|
|
|
|
|
|
internal fun sendToken(context: Context, token: String) {
|
|
|
- if (context.getSharedPreferences().getBoolean("is_login", false)) {
|
|
|
- context.getSharedPreferences().getString("pin", null)?.let {
|
|
|
+ if (context.pref().getBoolean("is_login", false)) {
|
|
|
+ context.pref().getString("pin", null)?.let {
|
|
|
apiScope.launch {
|
|
|
Service.sendAsync(
|
|
|
Data(
|