diff --git a/mirai-core/src/commonMain/kotlin/MiraiImpl.kt b/mirai-core/src/commonMain/kotlin/MiraiImpl.kt index 27b76e3b8..895f9a812 100644 --- a/mirai-core/src/commonMain/kotlin/MiraiImpl.kt +++ b/mirai-core/src/commonMain/kotlin/MiraiImpl.kt @@ -16,7 +16,6 @@ import io.ktor.client.request.* import io.ktor.client.request.forms.* import io.ktor.http.* import io.ktor.utils.io.core.* -import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.currentCoroutineContext import kotlinx.io.core.discardExact import kotlinx.io.core.readBytes @@ -577,7 +576,7 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor { val rep = network.run { Mirai.Http.get { url("https://qqweb.qq.com/c/activedata/get_mygroup_data") - parameter("bkn", bkn) + parameter("bkn", client.wLoginSigInfo.bkn) parameter("gc", groupId) if (page != -1) { parameter("page", page) @@ -795,7 +794,7 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor { append("group_code", groupId) append("seconds", seconds) append("anony_nick", anonymousNick) - append("bkn", bot.bkn) + append("bkn", bot.client.wLoginSigInfo.bkn) }) headers { append( diff --git a/mirai-core/src/commonMain/kotlin/QQAndroidBot.kt b/mirai-core/src/commonMain/kotlin/QQAndroidBot.kt index 65f1defce..eeb8f2feb 100644 --- a/mirai-core/src/commonMain/kotlin/QQAndroidBot.kt +++ b/mirai-core/src/commonMain/kotlin/QQAndroidBot.kt @@ -37,9 +37,9 @@ import net.mamoe.mirai.internal.network.handler.state.StateObserver import net.mamoe.mirai.internal.network.handler.state.safe import net.mamoe.mirai.internal.network.impl.netty.ForceOfflineException import net.mamoe.mirai.internal.network.impl.netty.NettyNetworkHandlerFactory -import net.mamoe.mirai.internal.network.protocol.packet.login.StatSvc import net.mamoe.mirai.internal.network.notice.* import net.mamoe.mirai.internal.network.notice.decoders.MsgInfoDecoder +import net.mamoe.mirai.internal.network.protocol.packet.login.StatSvc import net.mamoe.mirai.internal.utils.subLogger import net.mamoe.mirai.utils.BotConfiguration import net.mamoe.mirai.utils.MiraiLogger @@ -240,14 +240,6 @@ internal open class QQAndroidBot constructor( }, ) // We can move the factory to configuration but this is not necessary for now. } - - /** - * 获取 获取群公告 所需的 bkn 参数 - * */ // TODO: 2021/4/26 extract it after #1141 merged - val bkn: Int - get() = client.wLoginSigInfo.sKey.data - .fold(5381) { acc: Int, b: Byte -> acc + acc.shl(5) + b.toInt() } - .and(Int.MAX_VALUE) } internal fun QQAndroidBot.getGroupByUinOrFail(uin: Long) = diff --git a/mirai-core/src/commonMain/kotlin/contact/announcement/AnnouncementsImpl.kt b/mirai-core/src/commonMain/kotlin/contact/announcement/AnnouncementsImpl.kt index 323f9817a..6a1ec7ef3 100644 --- a/mirai-core/src/commonMain/kotlin/contact/announcement/AnnouncementsImpl.kt +++ b/mirai-core/src/commonMain/kotlin/contact/announcement/AnnouncementsImpl.kt @@ -28,10 +28,6 @@ import net.mamoe.mirai.internal.QQAndroidBot import net.mamoe.mirai.internal.asQQAndroidBot import net.mamoe.mirai.internal.contact.GroupImpl import net.mamoe.mirai.internal.contact.OnlineAnnouncementImpl -import net.mamoe.mirai.internal.contact.announcement.AnnouncementProtocol.deleteGroupAnnouncement -import net.mamoe.mirai.internal.contact.announcement.AnnouncementProtocol.getGroupAnnouncement -import net.mamoe.mirai.internal.contact.announcement.AnnouncementProtocol.getRawGroupAnnouncements -import net.mamoe.mirai.internal.contact.announcement.AnnouncementProtocol.sendGroupAnnouncement import net.mamoe.mirai.internal.contact.announcement.AnnouncementProtocol.toAnnouncement import net.mamoe.mirai.internal.contact.announcement.AnnouncementProtocol.toGroupAnnouncement import net.mamoe.mirai.internal.network.highway.ChannelKind @@ -41,8 +37,6 @@ import net.mamoe.mirai.internal.network.psKey import net.mamoe.mirai.internal.network.sKey import net.mamoe.mirai.internal.utils.io.writeResource import net.mamoe.mirai.utils.* -import net.mamoe.mirai.utils.Either.Companion.onLeft -import net.mamoe.mirai.utils.Either.Companion.rightOrNull import java.util.stream.Stream internal class AnnouncementsImpl( @@ -169,7 +163,7 @@ internal object AnnouncementProtocol { val resp = Mirai.Http.post { url("https://web.qun.qq.com/cgi-bin/announce/upload_img") body = MultiPartFormDataContent(formData { - append("\"bkn\"", bkn) + append("\"bkn\"", client.wLoginSigInfo.bkn) append("\"source\"", "troopNotice") append("m", "0") append( @@ -212,7 +206,7 @@ internal object AnnouncementProtocol { ) body = MultiPartFormDataContent(formData { append("qid", groupId) - this.append("bkn", bkn) + append("bkn", client.wLoginSigInfo.bkn) append("text", announcement.msg.text) append("pinned", announcement.pinned) image?.let { @@ -243,7 +237,7 @@ internal object AnnouncementProtocol { url("https://web.qun.qq.com/cgi-bin/announce/list_announce") body = MultiPartFormDataContent(formData { append("qid", groupId) - append("bkn", bkn) + append("bkn", client.wLoginSigInfo.bkn) append("ft", 23) //好像是一个用来识别应用的参数 append("s", if (page == 1) 0 else -(page * amount + 1)) // 第一页这里的参数应该是-1 append("n", amount) @@ -288,7 +282,7 @@ internal object AnnouncementProtocol { fid: String ) = MultiPartFormDataContent(formData { append("qid", groupId) - append("bkn", bkn) + append("bkn", client.wLoginSigInfo.bkn) append("fid", fid) append("format", "json") }) diff --git a/mirai-core/src/commonMain/kotlin/network/keys.kt b/mirai-core/src/commonMain/kotlin/network/keys.kt index 8ca5a7808..24acd7f7d 100644 --- a/mirai-core/src/commonMain/kotlin/network/keys.kt +++ b/mirai-core/src/commonMain/kotlin/network/keys.kt @@ -127,6 +127,14 @@ internal data class WLoginSigInfo( var encryptedDownloadSession: EncryptedDownloadSession? = null, ) { + /** + * 获取 获取群公告 所需的 bkn 参数 + * */ + val bkn: Int + get() = sKey.data + .fold(5381) { acc: Int, b: Byte -> acc + acc.shl(5) + b.toInt() } + .and(Int.MAX_VALUE) + //图片加密下载 //是否加密从bigdatachannel处得知 @Serializable