diff --git a/qqinterface/src/main/java/mqq/app/AppRuntime.java b/qqinterface/src/main/java/mqq/app/AppRuntime.java index fc8d304e..55628079 100644 --- a/qqinterface/src/main/java/mqq/app/AppRuntime.java +++ b/qqinterface/src/main/java/mqq/app/AppRuntime.java @@ -5,6 +5,7 @@ import androidx.annotation.NonNull; +import com.tencent.qphone.base.remote.SimpleAccount; import com.tencent.qphone.base.remote.ToServiceMsg; import mqq.app.api.IRuntimeService; @@ -72,6 +73,10 @@ public T getRuntimeService(Class cls, String name public T getRuntimeServiceIPCSync(@NonNull Class cls, String str) { throw new UnsupportedOperationException(); } + + public void switchAccount(SimpleAccount simpleAccount, String process) { + + } public String getAccount() { return ""; } diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/ActionManager.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/ActionManager.kt index fb57d241..cb7e0e00 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/ActionManager.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/ActionManager.kt @@ -18,6 +18,7 @@ internal object ActionManager { arrayOf( // Framework Info TestHandler, GetLatestEvents, GetSupportedActions, GetStatus, GetVersionInfo, GetSelfInfo, GetLoginInfo, + SwitchAccount, // UserActions GetProfileCard, GetFriendList, SendLike, GetUid, GetUinByUid, ScanQRCode, SetProfileCard, diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/SwitchAccount.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/SwitchAccount.kt new file mode 100644 index 00000000..187e93dd --- /dev/null +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/action/handlers/SwitchAccount.kt @@ -0,0 +1,35 @@ +package moe.fuqiuluo.shamrock.remote.action.handlers + +import kotlinx.serialization.json.JsonElement +import moe.fuqiuluo.shamrock.remote.action.ActionSession +import moe.fuqiuluo.shamrock.remote.action.IActionHandler +import moe.fuqiuluo.shamrock.tools.EmptyJsonString +import moe.fuqiuluo.shamrock.xposed.helper.AppRuntimeFetcher +import mqq.app.MobileQQ + +internal object SwitchAccount: IActionHandler() { + override suspend fun internalHandle(session: ActionSession): String { + val userId = session.getString("user_id") + return invoke(userId, session.echo) + } + + operator fun invoke( + userId: String, + echo: JsonElement = EmptyJsonString + ): String { + val account = MobileQQ.getMobileQQ().allAccounts.firstOrNull { it.uin == userId } + ?: return error("账号不存在", echo) + val runtime = AppRuntimeFetcher.appRuntime + val result = kotlin.runCatching { + runtime.switchAccount(account, null) + } + if (result.isFailure) { + return error(result.exceptionOrNull()?.message ?: "切换账号失败", echo) + } + return ok("切换成功", echo) + } + + override val requiredParams: Array = arrayOf("user_id") + + override fun path(): String = "switch_account" +} \ No newline at end of file diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/api/UserAction.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/api/UserAction.kt index 5b43b28f..44a7c6c9 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/api/UserAction.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/api/UserAction.kt @@ -12,6 +12,11 @@ import moe.fuqiuluo.shamrock.tools.* import moe.fuqiuluo.shamrock.utils.PlatformUtils fun Routing.userAction() { + getOrPost("/switch_account") { + val userId = fetchOrThrow("user_id") + call.respondText(SwitchAccount(userId), ContentType.Application.Json) + } + getOrPost("/set_group_leave") { val group = fetchOrThrow("group_id") call.respondText(LeaveTroop(group), ContentType.Application.Json) diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/api/GlobalEventTransmitter.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/api/GlobalEventTransmitter.kt index 9757a3bb..5b7f1575 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/api/GlobalEventTransmitter.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/remote/service/api/GlobalEventTransmitter.kt @@ -104,7 +104,7 @@ internal object GlobalEventTransmitter: BaseSvc() { var nickName = record.sendNickName if (nickName.isNullOrBlank()) { CardSvc.getProfileCard(record.senderUin.toString()).onSuccess { - nickName = it.strNick ?: "" + nickName = it.strNick ?: record.peerName } } transMessageEvent(record,