Shamrock: JSON メッセージのクラッシュと QQ ミュージックのカバーを修正

This commit is contained in:
ikechan8370 2023-12-01 15:21:58 +08:00
parent 2fdcfe332b
commit 48773cc47c
5 changed files with 41 additions and 6 deletions

View File

@ -22,6 +22,7 @@ import moe.fuqiuluo.shamrock.helper.ContactHelper
import moe.fuqiuluo.shamrock.helper.Level import moe.fuqiuluo.shamrock.helper.Level
import moe.fuqiuluo.shamrock.helper.LogCenter import moe.fuqiuluo.shamrock.helper.LogCenter
import moe.fuqiuluo.shamrock.helper.MessageHelper import moe.fuqiuluo.shamrock.helper.MessageHelper
import moe.fuqiuluo.shamrock.helper.SendMsgException
import moe.fuqiuluo.shamrock.tools.EMPTY_BYTE_ARRAY import moe.fuqiuluo.shamrock.tools.EMPTY_BYTE_ARRAY
import moe.fuqiuluo.shamrock.xposed.helper.NTServiceFetcher import moe.fuqiuluo.shamrock.xposed.helper.NTServiceFetcher
import moe.fuqiuluo.shamrock.xposed.helper.msgService import moe.fuqiuluo.shamrock.xposed.helper.msgService
@ -194,8 +195,10 @@ internal object MsgSvc: BaseSvc() {
fromId, fromId,
MessageCallback(peedId, 0) MessageCallback(peedId, 0)
) )
return if (result.isFailure && retryCnt > 0) { return if (result.isFailure
// 可能网络问题出现红色感叹号,重试 && result.exceptionOrNull()?.javaClass == SendMsgException::class.java
&& retryCnt > 0) {
// 发送失败,可能网络问题出现红色感叹号,重试
// 例如 rich media transfer failed // 例如 rich media transfer failed
delay(100) delay(100)
sendToAio(chatType, peedId, message, fromId, retryCnt - 1) sendToAio(chatType, peedId, message, fromId, retryCnt - 1)

View File

@ -22,6 +22,9 @@ import com.tencent.qqnt.kernel.nativeinterface.ReplyElement
import com.tencent.qqnt.kernel.nativeinterface.RichMediaFilePathInfo import com.tencent.qqnt.kernel.nativeinterface.RichMediaFilePathInfo
import com.tencent.qqnt.kernel.nativeinterface.TextElement import com.tencent.qqnt.kernel.nativeinterface.TextElement
import com.tencent.qqnt.kernel.nativeinterface.VideoElement import com.tencent.qqnt.kernel.nativeinterface.VideoElement
import kotlinx.serialization.SerializationException
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.json.JsonPrimitive
import moe.fuqiuluo.qqinterface.servlet.CardSvc import moe.fuqiuluo.qqinterface.servlet.CardSvc
@ -191,7 +194,20 @@ internal object MessageMaker {
): Result<MsgElement> { ): Result<MsgElement> {
data.checkAndThrow("data") data.checkAndThrow("data")
val jsonStr = data["data"].let { val jsonStr = data["data"].let {
if (it is JsonObject) it.asJsonObject.toString() else it.asString if (it is JsonObject) it.asJsonObject.toString() else {
val str = it.asStringOrNull ?: ""
// 检查字符串是否是合法json不然qq会闪退
try {
val element = Json.decodeFromString<JsonElement>(str)
if (element !is JsonObject) {
return Result.failure(Exception("不合法的JSON字符串"))
}
} catch (err: Throwable) {
LogCenter.log(err.stackTraceToString(), Level.ERROR)
return Result.failure(Exception("不合法的JSON字符串"))
}
str
}
} }
val element = MsgElement() val element = MsgElement()
element.elementType = MsgConstant.KELEMTYPEARKSTRUCT element.elementType = MsgConstant.KELEMTYPEARKSTRUCT

View File

@ -12,3 +12,4 @@ internal class LogicException(why: String) : InternalMessageMakerError(why)
internal object ErrorTokenException : InternalMessageMakerError("access_token error") internal object ErrorTokenException : InternalMessageMakerError("access_token error")
internal class SendMsgException(why: String) : InternalMessageMakerError(why)

View File

@ -86,10 +86,9 @@ internal object MessageHelper {
} }
} }
if (sendRet?.first != 0) { if (sendRet?.first != 0) {
return Result.failure(Exception(sendRet?.second ?: "发送消息超时")) return Result.failure(SendMsgException(sendRet?.second ?: "发送消息超时"))
} }
return Result.success(sendResultPair) return Result.success(sendResultPair)
// return sendMessageWithoutMsgId(chatType, peerId, msg, fromId, callback)
} }
suspend fun sendMessageWithoutMsgId( suspend fun sendMessageWithoutMsgId(

View File

@ -8,8 +8,10 @@ import moe.fuqiuluo.qqinterface.servlet.ark.ArkMsgSvc
import moe.fuqiuluo.shamrock.tools.GlobalClient import moe.fuqiuluo.shamrock.tools.GlobalClient
import moe.fuqiuluo.shamrock.tools.asInt import moe.fuqiuluo.shamrock.tools.asInt
import moe.fuqiuluo.shamrock.tools.asJsonArray import moe.fuqiuluo.shamrock.tools.asJsonArray
import moe.fuqiuluo.shamrock.tools.asJsonArrayOrNull
import moe.fuqiuluo.shamrock.tools.asJsonObject import moe.fuqiuluo.shamrock.tools.asJsonObject
import moe.fuqiuluo.shamrock.tools.asString import moe.fuqiuluo.shamrock.tools.asString
import moe.fuqiuluo.shamrock.tools.asStringOrNull
import moe.fuqiuluo.shamrock.utils.MD5 import moe.fuqiuluo.shamrock.utils.MD5
internal object MusicHelper { internal object MusicHelper {
@ -53,12 +55,26 @@ internal object MusicHelper {
val trackInfo = data["track_info"].asJsonObject val trackInfo = data["track_info"].asJsonObject
val mid = trackInfo["mid"].asString val mid = trackInfo["mid"].asString
val previewMid = trackInfo["album"].asJsonObject["mid"].asString val previewMid = trackInfo["album"].asJsonObject["mid"].asString
val singerMid = trackInfo["singer"].asJsonArrayOrNull?.let {
it[0].asJsonObject["mid"].asStringOrNull
} ?: ""
val name = trackInfo["name"].asString val name = trackInfo["name"].asString
val title = trackInfo["title"].asString val title = trackInfo["title"].asString
val singerName = trackInfo["singer"].asJsonArray.first().asJsonObject["name"].asString val singerName = trackInfo["singer"].asJsonArray.first().asJsonObject["name"].asString
val vs = trackInfo["vs"].asJsonArrayOrNull?.let {
it[0].asStringOrNull
} ?: ""
val code = MD5.getMd5Hex("${mid}q;z(&l~sdf2!nK".toByteArray()).substring(0 .. 4).uppercase() val code = MD5.getMd5Hex("${mid}q;z(&l~sdf2!nK".toByteArray()).substring(0 .. 4).uppercase()
val playUrl = "http://c6.y.qq.com/rsc/fcgi-bin/fcg_pyq_play.fcg?songid=&songmid=$mid&songtype=1&fromtag=50&uin=&code=$code" val playUrl = "http://c6.y.qq.com/rsc/fcgi-bin/fcg_pyq_play.fcg?songid=&songmid=$mid&songtype=1&fromtag=50&uin=&code=$code"
val previewUrl = "http://y.gtimg.cn/music/photo_new/T002R180x180M000$previewMid.jpg" val previewUrl = if (vs.isNotEmpty()) {
"http://y.gtimg.cn/music/photo_new/T062R150x150M000$vs}.jpg"
} else if (previewMid.isNotEmpty()) {
"http://y.gtimg.cn/music/photo_new/T002R150x150M000$previewMid.jpg"
} else if (singerMid.isNotEmpty()){
"http://y.gtimg.cn/music/photo_new/T001R150x150M000$singerMid.jpg"
} else {
""
}
val jumpUrl = "https://i.y.qq.com/v8/playsong.html?platform=11&appshare=android_qq&appversion=10030010&hosteuin=oKnlNenz7i-s7c**&songmid=${mid}&type=0&appsongtype=1&_wv=1&source=qq&ADTAG=qfshare" val jumpUrl = "https://i.y.qq.com/v8/playsong.html?platform=11&appshare=android_qq&appversion=10030010&hosteuin=oKnlNenz7i-s7c**&songmid=${mid}&type=0&appsongtype=1&_wv=1&source=qq&ADTAG=qfshare"
ArkMsgSvc.tryShareMusic( ArkMsgSvc.tryShareMusic(
chatType, chatType,