honghengqiang 8 months ago
parent
commit
77876d8101

+ 2 - 2
app/build.gradle

@@ -15,8 +15,8 @@ android {
         applicationId "com.swago.app"
         minSdkVersion 21
         targetSdkVersion 33
-        versionCode 1401
-        versionName "1.4.0.1"
+        versionCode 1402
+        versionName "1.4.0.2"
         multiDexEnabled true
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
 

+ 2 - 2
app/src/main/java/com/swago/app/SplashVm.kt

@@ -112,8 +112,8 @@ class SplashVm(application: Application) : BaseViewModel(application) {
 
     private fun setBaseUrl(baseUrl: String) {
         if (BuildConfig.DEBUG) {
-//            UrlConstant.BASE_URL =   "http:test-api.swago.cn"
-            UrlConstant.BASE_URL =   "https://pro-api.swago.cn"
+            UrlConstant.BASE_URL =   "http:test-api.swago.cn"
+//            UrlConstant.BASE_URL =   "https://pro-api.swago.cn"
         } else {
             UrlConstant.BASE_URL = baseUrl
         }

+ 14 - 15
baseswago/src/main/java/com/swago/baseswago/constant/UrlConstant.kt

@@ -14,11 +14,11 @@ import java.io.File
 object UrlConstant {
 
     var BASE_URL = if (BuildConfig.DEBUG) {
-//            "http:test-api.swago.cn"
-        "https://pro-api.swago.cn"
+            "http:test-api.swago.cn"
+//        "https://pro-api.swago.cn"
     } else {
-            "https://pro-api.swago.cn"
-        }
+        "https://pro-api.swago.cn"
+    }
 
     private val BASE_WEB_URL by lazy {
         if (BuildConfig.DEBUG) {
@@ -36,7 +36,7 @@ object UrlConstant {
     //声网id
     private var agoraId = ""
 
-    fun getConfigModel():ConfigModel?{
+    fun getConfigModel(): ConfigModel? {
         val infoJson = SpUtil.readString("configModel")
         return if (infoJson.isNullOrEmpty()) {
             null
@@ -45,32 +45,32 @@ object UrlConstant {
         }
     }
 
-    fun getAgoraId():String{
-        if (agoraId.isEmpty()){
-            agoraId = getConfigModel()?.agoral_app_id?:""
+    fun getAgoraId(): String {
+        if (agoraId.isEmpty()) {
+            agoraId = getConfigModel()?.agoral_app_id ?: ""
         }
         // !!! 为了防止获取到的agoraId不是空的这里如果获取到之后还是空  那么给个默认值
-        if (agoraId.isEmpty()){
+        if (agoraId.isEmpty()) {
             agoraId = "ae14303e10bd4d98acbd8f63e09fb19b"
         }
         return agoraId
     }
 
-    fun setAgoraId(agoraId:String){
+    fun setAgoraId(agoraId: String) {
         this.agoraId = agoraId
     }
 
     //腾讯IM
     private var imId = 0
 
-    fun getImId():Int{
-        if (imId==0){
-            imId = getConfigModel()?.im_app_id?:0
+    fun getImId(): Int {
+        if (imId == 0) {
+            imId = getConfigModel()?.im_app_id ?: 0
         }
         return imId
     }
 
-    fun setImId(imId:Int){
+    fun setImId(imId: Int) {
         this.imId = imId
     }
 
@@ -85,7 +85,6 @@ object UrlConstant {
         AppContext.getContext().getExternalFilesDir("")?.absolutePath + File.separator + "gameFile"
 
 
-
     var lottieResourcePath =
         AppContext.getContext().getExternalFilesDir("")?.absolutePath + File.separator + "lottie"
     var lottieDownloadUrl = ""

+ 18 - 1
baseswago/src/main/java/com/swago/baseswago/http/JsonResponseBodyConverter.kt

@@ -6,9 +6,11 @@ import com.google.gson.Gson
 import okhttp3.ResponseBody
 import kotlin.Throws
 import com.swago.baseswago.model.HttpResponseModel
+import com.swago.baseswago.util.MD5Util
 import org.json.JSONArray
 import org.json.JSONException
 import org.json.JSONObject
+import org.json.JSONTokener
 import retrofit2.Converter
 import java.io.IOException
 import java.lang.reflect.Type
@@ -20,7 +22,7 @@ class JsonResponseBodyConverter<T>(
 ) : Converter<ResponseBody, T?> {
     @Throws(IOException::class)
     override fun convert(value: ResponseBody): T? {
-        val response = value.string()
+        var response = value.string()
         try {
             val jsonObject = JSONObject(response)
             val status = jsonObject.getBoolean("status")
@@ -28,6 +30,21 @@ class JsonResponseBodyConverter<T>(
                 throw SwagoException(jsonObject.getInt("code"), jsonObject.getString("msg"))
             }
 
+            val encode = jsonObject.optInt("encode",0)
+            if (encode == 1){
+                val data = jsonObject.getString("data")
+                val dataStr = MD5Util.decryptAES(data,"0129456789abcdeg0123456789adcdef")
+                val obj = JSONTokener(dataStr).nextValue()
+                if (obj is JSONObject){
+                    val dataStrJSONObject = JSONObject(dataStr)
+                    jsonObject.put("data",dataStrJSONObject)
+                }else if(obj is JSONArray){
+                    val dataStrJSONArray = JSONArray(dataStr)
+                    jsonObject.put("data",dataStrJSONArray)
+                }
+                response = jsonObject.toString()
+            }
+
             if (type.toString().contains("HttpResponseModel")) {
                 val baseBean = gson.fromJson<HttpResponseModel<*>>(response, type)
                 return baseBean as T

+ 21 - 0
baseswago/src/main/java/com/swago/baseswago/util/MD5Util.java

@@ -5,6 +5,11 @@ import com.google.android.gms.common.util.Hex;
 
 import java.nio.charset.StandardCharsets;
 import java.security.MessageDigest;
+import java.util.Arrays;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
 
 public class MD5Util {
 
@@ -37,4 +42,20 @@ public class MD5Util {
             throw new RuntimeException("解密失败", e);
         }
     }
+
+
+    public static String decryptAES(String encrypted, String key) throws Exception {
+        final byte[] encryptedBytes = android.util.Base64.decode(encrypted, android.util.Base64.DEFAULT);
+        final byte[] iv = Arrays.copyOfRange(encryptedBytes, 0, 16);
+        final byte[] encryptedData = Arrays.copyOfRange(encryptedBytes, 16, encryptedBytes.length);
+
+        SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
+        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+        IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
+        cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivParameterSpec);
+
+        byte[] original = cipher.doFinal(encryptedData);
+        return new String(original, StandardCharsets.UTF_8);
+    }
+
 }

+ 23 - 4
room/src/main/java/com/swago/room/base/BaseComFragment.kt

@@ -842,7 +842,6 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
         if (gamePackageUrl.isEmpty() || gameVersionCode.isEmpty()) {
             return false
         }
-
         val zipNames = gamePackageUrl.split("/")
         val gameName = zipNames.last()
         if (TextUtils.isEmpty(UrlConstant.appGameRootPath) || !File(UrlConstant.appGameRootPath + File.separator + gameId).exists()) {
@@ -853,12 +852,23 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
                 downLoadGamePackage(gameId, gamePackageUrl, gameVersionCode, gameName)
                 false
             } else {
+                if(!File(UrlConstant.appGameRootPath + File.separator + gameId + File.separator + "index.html").exists()){
+                    val t = UrlConstant.appGameRootPath + File.separator + gameId
+                    val packagePath = UrlConstant.appGameRootPath + File.separator + gameId + File.separator + gameName
+                    FileUtil.upZipFile(packagePath, t + File.separator)
+                }
                 val localGameVersionCode = SpUtil.readInt(gameId)
                 if (localGameVersionCode == 0 || (gameVersionCode.isNotEmpty() && localGameVersionCode < gameVersionCode.toInt())) {
                     downLoadGamePackage(gameId, gamePackageUrl, gameVersionCode, gameName)
                     false
                 } else {
-                    true
+                    if(File(UrlConstant.appGameRootPath + File.separator + gameId + File.separator + "index.html").exists()){
+                        true
+                    }else{
+                        downLoadGamePackage(gameId, gamePackageUrl, gameVersionCode, gameName)
+                        false
+                    }
+
                 }
             }
         }
@@ -921,15 +931,24 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
 
             override fun fetchStart(task: DownloadTask, blockIndex: Int, contentLength: Long) {}
 
-            override fun fetchProgress(task: DownloadTask, blockIndex: Int, increaseBytes: Long) {}
+            override fun fetchProgress(task: DownloadTask, blockIndex: Int, increaseBytes: Long) {
+                Log.d("进度条","fetchProgress--$increaseBytes---$blockIndex")
+            }
 
-            override fun fetchEnd(task: DownloadTask, blockIndex: Int, contentLength: Long) {}
+            override fun fetchEnd(task: DownloadTask, blockIndex: Int, contentLength: Long) {
+                Log.d("进度条","fetchEnd--$contentLength---$blockIndex")
+            }
 
             override fun taskEnd(task: DownloadTask, cause: EndCause, realCause: Exception?) {
+                if (cause.name == EndCause.SAME_TASK_BUSY.name){
+                    task.cancel()
+                }
+                Log.d("进度条","taskEnd--${cause.name}")
                 GlobalScope.launch(Dispatchers.IO) {
                     val packagePath = path + File.separator + name
                     FileUtil.upZipFile(packagePath, path + File.separator)
                     SpUtil.putInt(gameId, gameVersionCode.toInt())
+                    Log.d("游戏下载","${gameId}----${gameVersionCode}")
                 }
             }
 

+ 5 - 0
room/src/main/java/com/swago/room/game/GamePlayDialog.kt

@@ -277,6 +277,11 @@ class GamePlayDialog : BaseXDFragment<DialogGamePlayBinding>(), IRoomActiveListe
             dismissAllowingStateLoss()
         }
 
+        @JavascriptInterface
+        fun decodeStr(encodeData:String):String{
+            return  MD5Util.decryptAES(encodeData,"0129456789abcdeg0123456789adcdef")
+        }
+
     }