浏览代码

1.添加网络白名单地址接口请求。

20241218TB223FC(测试jar包)
wangwanlei 9 个月前
父节点
当前提交
a6e44095b4

+ 3
- 0
app/src/main/java/com/xhly/manageapp/ManageApplication.kt 查看文件

@@ -471,6 +471,9 @@ class ManageApplication : MultiDexApplication() {
471 471
         fun setUrlWhiteListWrite(list:ArrayList<String>){
472 472
             if (ModelNameUtils.IS_LianxX505f()) {
473 473
                 csdkManager?.SetEnable(true)
474
+                //默认添加自己应用为白名单
475
+                list.add("mcapitest.xhkjedu.com")
476
+                list.add("mcwstest.xhkjedu.com")
474 477
                 csdkManager?.urlWhiteListWrite(list)
475 478
             }
476 479
         }

+ 5
- 0
app/src/main/java/com/xhly/manageapp/network/UriAdress.kt 查看文件

@@ -31,6 +31,11 @@ object UriAdress {
31 31
      */
32 32
     const val APP_LISTPAD = "/stApp/list_pad"
33 33
 
34
+    /**
35
+     * 网址白名单
36
+     */
37
+    const val APP_NET_WHITELIST="/white/list_pad"
38
+
34 39
     /**
35 40
      * 设备--地理位置添加
36 41
      */

+ 12
- 1
app/src/main/java/com/xhly/manageapp/network/strategy/StrategyService.kt 查看文件

@@ -9,9 +9,14 @@ import retrofit2.http.Body
9 9
 import retrofit2.http.POST
10 10
 
11 11
 interface StrategyService {
12
+    /**
13
+     * 获得平板策略
14
+     */
12 15
     @POST(UriAdress.DETAIL_PAD)
13 16
     suspend fun postDetailPad(): ResponseData<StrategyBean>
14
-
17
+    /**
18
+     * 获得应用策略
19
+     */
15 20
     @POST(UriAdress.APP_LISTPAD)
16 21
     suspend fun postAppListPad():ResponseData<ArrayList<AppTimeManageBean>>
17 22
 
@@ -20,4 +25,10 @@ interface StrategyService {
20 25
      */
21 26
     @POST(UriAdress.DEVICESETDETAIL)
22 27
     suspend fun postDevicesetDetail(@Body map:HashMap<String,Any>):ResponseData<SchoolDeviceSetBean>
28
+
29
+    /**
30
+     * 获得网络白名单
31
+     */
32
+    @POST(UriAdress.APP_NET_WHITELIST)
33
+    suspend fun postAppNetWhiteList():ResponseData<ArrayList<String>>
23 34
 }

+ 4
- 0
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt 查看文件

@@ -191,6 +191,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
191 191
                 })
192 192
             }
193 193
         }
194
+        viewModel.netWhiteListData.observe(this){
195
+           StrategyUtils.setNetWhiteList(it)
196
+        }
194 197
         startWorkManager()
195 198
     }
196 199
 
@@ -232,6 +235,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
232 235
         viewModel.updateStrategy()
233 236
         viewModel.uploadAppStrategy()
234 237
         viewModel.getAppList()
238
+        viewModel.postAppNetWhiteList()
235 239
         userBean?.let {
236 240
             viewModel.postDevicesetDetail(it.schoolid)
237 241
         }

+ 24
- 1
app/src/main/java/com/xhly/manageapp/ui/main/viewmodel/MainViewModel.kt 查看文件

@@ -40,9 +40,10 @@ class MainViewModel : CommonBaseViewModel() {
40 40
     val loginOutData: LiveData<Boolean> = loginOut
41 41
     private val schoolSet=MutableLiveData<SchoolDeviceSetBean>()
42 42
     val schoolSetData:LiveData<SchoolDeviceSetBean> =schoolSet
43
-
44 43
     private val wallpaper=MutableLiveData<WallpaperBean>()
45 44
     val wallpaperData:LiveData<WallpaperBean> =wallpaper
45
+    private val netWhiteList=MutableLiveData<ArrayList<String>>()
46
+    val netWhiteListData:LiveData<ArrayList<String>> =netWhiteList
46 47
 
47 48
     fun getAppList() {
48 49
         launchUI {
@@ -174,4 +175,26 @@ class MainViewModel : CommonBaseViewModel() {
174 175
             }
175 176
         }
176 177
     }
178
+
179
+    /**
180
+     * 获得网址白名单
181
+     */
182
+    fun postAppNetWhiteList(){
183
+        launchUI {
184
+            val postAppNetWhiteList = strategyService.postAppNetWhiteList()
185
+            if (postAppNetWhiteList.code==0){
186
+                 val urlList= arrayListOf<String>()
187
+                postAppNetWhiteList.obj.forEach {
188
+                    if (it.contains(";")){
189
+                        it.split(";").forEach {str->
190
+                            urlList.add(str)
191
+                        }
192
+                    }else{
193
+                        urlList.add(it)
194
+                    }
195
+                }
196
+                  netWhiteList.value=urlList
197
+            }
198
+        }
199
+    }
177 200
 }

+ 7
- 0
app/src/main/java/com/xhly/manageapp/utils/StrategyUtils.kt 查看文件

@@ -283,4 +283,11 @@ object StrategyUtils {
283 283
         }
284 284
         return schoolDeviceSetBean
285 285
     }
286
+
287
+    /**
288
+     * 设置网络白名单
289
+     */
290
+    public fun setNetWhiteList(data:ArrayList<String>){
291
+        ManageApplication.setUrlWhiteListWrite(data)
292
+    }
286 293
 }

正在加载...
取消
保存