Commit aa61e944 authored by luo123's avatar luo123

get GroupAnnouncementList is working now

parent 220d293b
...@@ -72,11 +72,6 @@ kotlin { ...@@ -72,11 +72,6 @@ kotlin {
api(kotlinx("io", kotlinXIoVersion)) api(kotlinx("io", kotlinXIoVersion))
api(kotlinx("coroutines-io", coroutinesIoVersion)) api(kotlinx("coroutines-io", coroutinesIoVersion))
api(kotlinx("coroutines-core", coroutinesVersion)) api(kotlinx("coroutines-core", coroutinesVersion))
api(ktor("client-core", ktorVersion))
implementation(ktor("client-json",ktorVersion))
implementation(ktor("client-serialization",ktorVersion))
} }
} }
commonMain { commonMain {
......
...@@ -10,14 +10,17 @@ ...@@ -10,14 +10,17 @@
package net.mamoe.mirai.qqandroid package net.mamoe.mirai.qqandroid
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.features.json.JsonFeature
import io.ktor.client.features.json.serializer.KotlinxSerializer
import io.ktor.client.request.* import io.ktor.client.request.*
import io.ktor.client.request.forms.MultiPartFormDataContent
import io.ktor.client.request.forms.formData import io.ktor.client.request.forms.formData
import kotlinx.coroutines.async import kotlinx.coroutines.async
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withTimeoutOrNull import kotlinx.coroutines.withTimeoutOrNull
import kotlinx.io.core.Closeable import kotlinx.io.core.Closeable
import kotlinx.serialization.MissingFieldException
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
import kotlinx.serialization.json.int
import net.mamoe.mirai.LowLevelAPI import net.mamoe.mirai.LowLevelAPI
import net.mamoe.mirai.contact.* import net.mamoe.mirai.contact.*
import net.mamoe.mirai.data.* import net.mamoe.mirai.data.*
...@@ -567,25 +570,33 @@ internal class GroupImpl( ...@@ -567,25 +570,33 @@ internal class GroupImpl(
} }
@MiraiExperimentalAPI @MiraiExperimentalAPI
override suspend fun getAnnouncements(page: Int, amount: Int): GroupAnnouncementList { override suspend fun getAnnouncements(page: Int, amount: Int): GroupAnnouncementList? {
val json = Json(JsonConfiguration(ignoreUnknownKeys = true))
val data = bot.network.async { val data = bot.network.async {
HttpClient { install(JsonFeature) { serializer = KotlinxSerializer() } }.post<GroupAnnouncementList> { HttpClient().post<String> {
url("https://web.qun.qq.com/cgi-bin/announce/list_announce") url("https://web.qun.qq.com/cgi-bin/announce/list_announce")
formData { body = MultiPartFormDataContent(formData {
append("qid", id) append("qid", id)
append("bkn", getBkn()) append("bkn", getBkn())
append("ft", 23) //好像是一个用来识别应用的参数 append("ft", 23) //好像是一个用来识别应用的参数
append("s", -page) // 第一页这里的参数应该是-1 append("s", if (page ==1) 0 else -(page*amount+1)) // 第一页这里的参数应该是-1
append("n", amount) append("n", amount)
append("ni",if (page ==1) 1 else 0)
append("format", "json") append("format", "json")
})
headers {
append(
"cookie",
"uin=o${bot.selfQQ.id}; skey=${bot.client.wLoginSigInfo.sKey.data.encodeToString()}; p_uin=o${bot.selfQQ.id};"
)
} }
header(
"cookie",
"uin=o${bot.selfQQ.id}; skey=${bot.client.wLoginSigInfo.sKey.data.encodeToString()}; p_uin=o${bot.selfQQ.id};"
)
} }
} }
return data.await()
val rep = data.await()
bot.network.logger.error(rep)
return json.parse(GroupAnnouncementList.serializer(), rep)
} }
......
...@@ -157,7 +157,7 @@ expect abstract class Group() : Contact, CoroutineScope { ...@@ -157,7 +157,7 @@ expect abstract class Group() : Contact, CoroutineScope {
* *
* */ * */
@MiraiExperimentalAPI @MiraiExperimentalAPI
abstract suspend fun getAnnouncements(page: Int = 1, amount: Int = 10):GroupAnnouncementList abstract suspend fun getAnnouncements(page: Int = 1, amount: Int = 10):GroupAnnouncementList?
/** /**
* 让机器人退出这个群. 机器人必须为非群主才能退出. 否则将会失败 * 让机器人退出这个群. 机器人必须为非群主才能退出. 否则将会失败
......
...@@ -5,12 +5,16 @@ import kotlinx.serialization.Serializable ...@@ -5,12 +5,16 @@ import kotlinx.serialization.Serializable
/** /**
* 群公告数据类 * 群公告数据类
* getGroupAnnouncementList时,如果page=1,那么你可以在inst里拿到一些置顶公告
* *
* *
*/ */
@Serializable @Serializable
data class GroupAnnouncementList( data class GroupAnnouncementList(
val feeds: List<GroupAnnouncement> val ec: Int, //状态码 0 是正常的
@SerialName("em") val msg:String, //信息
val feeds: List<GroupAnnouncement>?, //群公告列表
val inst: List<GroupAnnouncement>? //置顶列表?
) )
@Serializable @Serializable
......
...@@ -153,7 +153,7 @@ actual abstract class Group : Contact(), CoroutineScope { ...@@ -153,7 +153,7 @@ actual abstract class Group : Contact(), CoroutineScope {
* *
* */ * */
@MiraiExperimentalAPI @MiraiExperimentalAPI
actual suspend abstract fun getAnnouncements(page: Int, amount: Int ):GroupAnnouncementList actual suspend abstract fun getAnnouncements(page: Int, amount: Int ):GroupAnnouncementList?
/** /**
* 检查此 id 的群成员是否存在 * 检查此 id 的群成员是否存在
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment