mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-30 02:30:12 +08:00
fix #360
This commit is contained in:
parent
83ee69ccc6
commit
fab0378078
@ -11,7 +11,6 @@
|
||||
|
||||
package net.mamoe.mirai.qqandroid
|
||||
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.request.forms.MultiPartFormDataContent
|
||||
import io.ktor.client.request.forms.formData
|
||||
@ -42,10 +41,10 @@ import net.mamoe.mirai.qqandroid.message.*
|
||||
import net.mamoe.mirai.qqandroid.network.QQAndroidBotNetworkHandler
|
||||
import net.mamoe.mirai.qqandroid.network.QQAndroidClient
|
||||
import net.mamoe.mirai.qqandroid.network.highway.HighwayHelper
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.data.proto.Cmd0x388
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.data.proto.ImMsgBody
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.data.proto.LongMsg
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.*
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.voice.PttStore
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.list.FriendList
|
||||
import net.mamoe.mirai.qqandroid.utils.MiraiPlatformUtils
|
||||
import net.mamoe.mirai.qqandroid.utils.encodeToString
|
||||
@ -57,6 +56,7 @@ import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.jvm.JvmField
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
import kotlin.math.absoluteValue
|
||||
import kotlin.math.log
|
||||
import kotlin.random.Random
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.data.jce.FriendInfo as JceFriendInfo
|
||||
|
||||
@ -561,7 +561,7 @@ internal abstract class QQAndroidBotBase constructor(
|
||||
@MiraiExperimentalAPI
|
||||
override suspend fun _lowLevelGetAnnouncement(groupId: Long, fid: String): GroupAnnouncement {
|
||||
val data = network.async {
|
||||
HttpClient().post<String> {
|
||||
MiraiPlatformUtils.Http.post<String> {
|
||||
url("https://web.qun.qq.com/cgi-bin/announce/get_feed")
|
||||
body = MultiPartFormDataContent(formData {
|
||||
append("qid", groupId)
|
||||
@ -588,7 +588,7 @@ internal abstract class QQAndroidBotBase constructor(
|
||||
@MiraiExperimentalAPI
|
||||
override suspend fun _lowLevelGetGroupActiveData(groupId: Long, page: Int): GroupActiveData {
|
||||
val data = network.async {
|
||||
HttpClient().get<String> {
|
||||
MiraiPlatformUtils.Http.get<String> {
|
||||
url("https://qqweb.qq.com/c/activedata/get_mygroup_data")
|
||||
parameter("bkn", bkn)
|
||||
parameter("gc", groupId)
|
||||
@ -793,6 +793,21 @@ internal abstract class QQAndroidBotBase constructor(
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
@MiraiExperimentalAPI
|
||||
@LowLevelAPI
|
||||
override suspend fun _lowLevelQueryGroupVoiceDownloadUrl(
|
||||
md5: ByteArray,
|
||||
groupId: Long,
|
||||
dstUin: Long
|
||||
): String {
|
||||
network.run {
|
||||
val response: PttStore.GroupPttDown.Response.DownLoadInfo =
|
||||
PttStore.GroupPttDown(client, groupId, dstUin,md5).sendAndExpect()
|
||||
return "http://${response.strDomain}${response.downPara.encodeToString()}"
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION", "OverridingDeprecatedMember")
|
||||
override suspend fun queryImageUrl(image: Image): String = when (image) {
|
||||
is ConstOriginUrlAware -> image.originUrl
|
||||
|
@ -141,6 +141,7 @@ internal object KnownPacketFactories {
|
||||
FriendList.GetTroopMemberList,
|
||||
ImgStore.GroupPicUp,
|
||||
PttStore.GroupPttUp,
|
||||
PttStore.GroupPttDown,
|
||||
LongConn.OffPicUp,
|
||||
LongConn.OffPicDown,
|
||||
TroopManagement.EditSpecialTitle,
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.mamoe.mirai.qqandroid.network.protocol.packet.chat.voice
|
||||
|
||||
import kotlinx.io.core.ByteReadPacket
|
||||
import net.mamoe.mirai.qqandroid.EMPTY_BYTE_ARRAY
|
||||
import net.mamoe.mirai.qqandroid.QQAndroidBot
|
||||
import net.mamoe.mirai.qqandroid.network.Packet
|
||||
import net.mamoe.mirai.qqandroid.network.QQAndroidClient
|
||||
@ -27,7 +28,7 @@ internal class PttStore {
|
||||
val uploadIpList: List<Int>,
|
||||
val uploadPortList: List<Int>,
|
||||
val fileKey: ByteArray
|
||||
) : Response() {
|
||||
) : GroupPttUp.Response() {
|
||||
override fun toString(): String {
|
||||
return "RequireUpload(fileId=$fileId, uKey=${uKey.contentToString()})"
|
||||
}
|
||||
@ -93,4 +94,67 @@ internal class PttStore {
|
||||
|
||||
}
|
||||
|
||||
object GroupPttDown : OutgoingPacketFactory<GroupPttDown.Response>("PttStore.GroupPttDown") {
|
||||
|
||||
sealed class Response() : Packet {
|
||||
class DownLoadInfo(
|
||||
val downDomain: ByteArray,
|
||||
val downPara:ByteArray,
|
||||
val strDomain:String,
|
||||
val uint32DownIp:List<Int>,
|
||||
val uint32DownPort:List<Int>
|
||||
) : GroupPttDown.Response() {
|
||||
override fun toString(): String {
|
||||
return "GroupPttDown(downPara=${downPara.encodeToString()},strDomain=$strDomain})"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
operator fun invoke(
|
||||
client: QQAndroidClient,
|
||||
groupCode: Long,
|
||||
dstUin:Long,
|
||||
md5: ByteArray
|
||||
|
||||
): OutgoingPacket = buildOutgoingUniPacket(client) {
|
||||
writeProtoBuf(
|
||||
Cmd0x388.ReqBody.serializer(), Cmd0x388.ReqBody(
|
||||
netType = 3, // wifi
|
||||
subcmd = 4,
|
||||
msgGetpttUrlReq = listOf(
|
||||
Cmd0x388.GetPttUrlReq(
|
||||
groupCode = groupCode,
|
||||
fileMd5 = md5,
|
||||
dstUin = dstUin,
|
||||
buType = 4,
|
||||
innerIp = 0,
|
||||
buildVer = "6.5.5.663".encodeToByteArray(),
|
||||
codec = 0,
|
||||
reqTerm = 5,
|
||||
reqPlatformType = 9
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Response {
|
||||
val resp0 = readProtoBuf(Cmd0x388.RspBody.serializer())
|
||||
resp0.msgGetpttUrlRsp ?: error("cannot find `msgGetpttUrlRsp` from `Cmd0x388.RspBody`")
|
||||
val resp = resp0.msgGetpttUrlRsp.first()
|
||||
if (!resp.failMsg.contentEquals(EMPTY_BYTE_ARRAY)){
|
||||
throw IllegalStateException(resp.failMsg.encodeToString())
|
||||
}
|
||||
return Response.DownLoadInfo(
|
||||
downDomain = resp.downDomain,
|
||||
downPara = resp.downPara,
|
||||
uint32DownIp = resp.uint32DownIp!!,
|
||||
uint32DownPort = resp.uint32DownPort!!,
|
||||
strDomain = resp.strDomain
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import net.mamoe.mirai.data.*
|
||||
import net.mamoe.mirai.event.events.BotInvitedJoinGroupRequestEvent
|
||||
import net.mamoe.mirai.event.events.MemberJoinRequestEvent
|
||||
import net.mamoe.mirai.event.events.NewFriendRequestEvent
|
||||
import net.mamoe.mirai.message.data.Voice
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
import net.mamoe.mirai.utils.WeakRef
|
||||
|
||||
@ -159,4 +160,13 @@ interface LowLevelBotAPIAccessor {
|
||||
blackList: Boolean,
|
||||
message: String = ""
|
||||
)
|
||||
|
||||
/**
|
||||
* 查询语音的下载连接
|
||||
*
|
||||
* */
|
||||
|
||||
@LowLevelAPI
|
||||
@MiraiExperimentalAPI
|
||||
suspend fun _lowLevelQueryGroupVoiceDownloadUrl(md5: ByteArray, groupId: Long, dstUin: Long): String
|
||||
}
|
||||
|
@ -35,13 +35,13 @@ class Voice(
|
||||
get() = "Voice"
|
||||
}
|
||||
|
||||
val url: String
|
||||
val url: String?
|
||||
get() = if (_url.startsWith("http")) _url
|
||||
else "http://grouptalk.c2c.qq.com$_url"
|
||||
else null
|
||||
|
||||
private var _stringValue: String? = null
|
||||
get() = field ?: kotlin.run {
|
||||
field = "[mirai:voice:$fileName,url:$url]"
|
||||
field = "[mirai:voice:$fileName]"
|
||||
field
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user