Ver código fonte

1.修改Socket接收和发送的数据结构

master
wangwanlei 10 meses atrás
pai
commit
8c65b7c750

+ 1
- 1
app/src/main/java/com/xhly/manageapp/broadcastreceiver/XhlyBroadCastReceiver.kt Ver arquivo

@@ -9,7 +9,7 @@ import com.xhly.corelib.utils.AppUtils
9 9
 class XhlyBroadCastReceiver : BroadcastReceiver() {
10 10
     override fun onReceive(context: Context?, intent: Intent?) {
11 11
         Log.i("收到广播", "这是finish广播")
12
-        val getAppList1 = AppUtils.GetAppList1(context)
12
+        val getAppList1 = AppUtils.GetAppList(context)
13 13
         getAppList1?.forEach {
14 14
             if (it.packageName.equals("com.xhly.easystud")) {
15 15
                 it.intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

+ 15
- 0
app/src/main/java/com/xhly/manageapp/service/websocket/AppSocketService.kt Ver arquivo

@@ -14,13 +14,17 @@ import com.xhly.corelib.bean.AppInfo
14 14
 import com.xhly.corelib.eventbus.UIEvent
15 15
 import com.xhly.corelib.network.RetrofitService
16 16
 import com.xhly.corelib.utils.AppUtils
17
+import com.xhly.corelib.utils.GsonUtils
17 18
 import com.xhly.corelib.utils.LogShow
19
+import com.xhly.corelib.utils.MD5Utils
18 20
 import com.xhly.corelib.utils.SharedPreferencesUtils
19 21
 import com.xhly.manageapp.ManageApplication
20 22
 import com.xhly.manageapp.bean.LogAppStartBean
21 23
 import com.xhly.manageapp.bean.LogdOperateBean
22 24
 import com.xhly.manageapp.network.LogService
25
+import com.xhly.websocket.bean.WebSocketData
23 26
 import com.xhly.websocket.service.LongConnService
27
+import com.xhly.websocket.service.WebSocketHelper
24 28
 import com.xhly.websocket.utils.SocketPushUtils.dealPushMessage
25 29
 import kotlinx.coroutines.CoroutineScope
26 30
 import kotlinx.coroutines.MainScope
@@ -29,6 +33,7 @@ import kotlinx.coroutines.launch
29 33
 import org.greenrobot.eventbus.EventBus
30 34
 import org.greenrobot.eventbus.Subscribe
31 35
 import org.greenrobot.eventbus.ThreadMode
36
+import java.util.UUID
32 37
 
33 38
 open class AppSocketService : LongConnService() {
34 39
     var CHANNEL_ID = "1"
@@ -64,6 +69,7 @@ open class AppSocketService : LongConnService() {
64 69
         appList = AppUtils.GetAppList(this) as ArrayList<AppInfo>
65 70
     }
66 71
 
72
+
67 73
     override fun processTextMessage(text: String) {
68 74
         //Log.v("websocket收到的消息", text);
69 75
         dealPushMessage(text)
@@ -72,6 +78,15 @@ open class AppSocketService : LongConnService() {
72 78
     override fun onConnectedSuccess() {
73 79
         super.onConnectedSuccess()
74 80
         UIEvent(Const.UPDATE_CONNECTED_SUCCESS).post()
81
+        val webData=WebSocketData()
82
+        webData.code=1002
83
+        webData.mid=UUID.randomUUID().toString()
84
+        val currentTimeSeconds = System.currentTimeMillis() / 1000
85
+        webData.timeunix=currentTimeSeconds
86
+        webData.fid=1
87
+        val jsMD5 = MD5Utils.getJsMD5(webData.code.toString()+"_"+webData.mid+"_"+webData.timeunix.toString())
88
+        webData.sign=MD5Utils.getJsMD5(jsMD5)
89
+        WebSocketHelper.getInstance().sendSocketString(GsonUtils.parseClassToJson(webData))
75 90
     }
76 91
 
77 92
     @Subscribe(threadMode = ThreadMode.MAIN)

+ 0
- 3
app/src/main/java/com/xhly/manageapp/ui/MainActivity.kt Ver arquivo

@@ -52,9 +52,6 @@ class MainActivity : BaseActivity<CommonBaseViewModel, ActivityMainBinding>() {
52 52
         }
53 53
         val getAppList1 = AppUtils.GetAppList(this)
54 54
         dataList.addAll(getAppList1)
55
-        dataList.forEach {
56
-            LogShow("数据" + it.packageName + "|||")
57
-        }
58 55
         adapter = AppAdapter(this, dataList)
59 56
         mBinding.rv.layoutManager = GridLayoutManager(this, 6, GridLayoutManager.VERTICAL, false)
60 57
         mBinding.rv.adapter = adapter

+ 3
- 3
websocket/src/main/java/com/xhly/websocket/bean/WebSocketData.kt Ver arquivo

@@ -8,7 +8,7 @@ class WebSocketData() {
8 8
 
9 9
     //两次md5加密timeunix
10 10
     var sign: String? = null
11
-    var fid: String? = null
12
-    var tids: String? = null
13
-    var body: String? = null
11
+    var fid: Int = 0
12
+    var tids: IntArray = intArrayOf()
13
+    var body: Any? = null
14 14
 }

+ 1
- 2
websocket/src/main/java/com/xhly/websocket/utils/SocketPushUtils.kt Ver arquivo

@@ -9,9 +9,8 @@ object SocketPushUtils {
9 9
     fun dealPushMessage(content: String) {
10 10
         try {
11 11
             //没用泛型是因为如果带有泛型的类型,可能会遇到解析异常的问题。需要使用TypeToken
12
-          /*  var socketData = GsonUtils.parseJsonWithGson(content, WebSocketData::class.java)*/
12
+            var socketData = GsonUtils.parseJsonWithGson(content, WebSocketData::class.java)
13 13
             LogShow("数据$content")
14
-            var socketData=WebSocketData()
15 14
             socketData.code.let { code ->
16 15
                 when (code) {
17 16
                     1001 -> {

Carregando…
Cancelar
Salvar