Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
2687b55f
Commit
2687b55f
authored
Feb 08, 2020
by
ryoii
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'http-refactor'
parents
96554f2c
aad50921
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
171 additions
and
174 deletions
+171
-174
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/Exception.kt
...rc/main/kotlin/net/mamoe/mirai/api/http/data/Exception.kt
+38
-0
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/StateCode.kt
...rc/main/kotlin/net/mamoe/mirai/api/http/data/StateCode.kt
+21
-0
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/ContactDTO.kt
...kotlin/net/mamoe/mirai/api/http/data/common/ContactDTO.kt
+3
-2
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/DTO.kt
...c/main/kotlin/net/mamoe/mirai/api/http/data/common/DTO.kt
+18
-0
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/MessageDTO.kt
...kotlin/net/mamoe/mirai/api/http/data/common/MessageDTO.kt
+1
-1
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/AuthDTO.kt
...p/src/main/kotlin/net/mamoe/mirai/api/http/dto/AuthDTO.kt
+0
-6
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/VerifyDTO.kt
...src/main/kotlin/net/mamoe/mirai/api/http/dto/VerifyDTO.kt
+0
-97
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/AuthRouteModule.kt
.../kotlin/net/mamoe/mirai/api/http/route/AuthRouteModule.kt
+6
-1
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/BaseRoute.kt
...c/main/kotlin/net/mamoe/mirai/api/http/route/BaseRoute.kt
+5
-42
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/GroupManageRouteModule.kt
.../net/mamoe/mirai/api/http/route/GroupManageRouteModule.kt
+60
-8
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/InfoRouteModule.kt
.../kotlin/net/mamoe/mirai/api/http/route/InfoRouteModule.kt
+4
-4
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/SendMessageRouteModule.kt
.../net/mamoe/mirai/api/http/route/SendMessageRouteModule.kt
+12
-9
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/util/Json.kt
...ttp/src/main/kotlin/net/mamoe/mirai/api/http/util/Json.kt
+3
-4
No files found.
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/Exception.kt
0 → 100644
View file @
2687b55f
package
net.mamoe.mirai.api.http.data
/**
* 错误请求. 抛出这个异常后将会返回错误给一个请求
*/
@Suppress
(
"unused"
)
open
class
IllegalAccessException
:
Exception
{
override
val
message
:
String
get
()
=
super
.
message
!!
constructor
(
message
:
String
)
:
super
(
message
,
null
)
constructor
(
cause
:
Throwable
)
:
super
(
cause
.
toString
(),
cause
)
constructor
(
message
:
String
,
cause
:
Throwable
?)
:
super
(
message
,
cause
)
}
/**
* Session失效或不存在
*/
object
IllegalSessionException
:
IllegalAccessException
(
"Session失效或不存在"
)
/**
* Session未激活
*/
object
NotVerifiedSessionException
:
IllegalAccessException
(
"Session未激活"
)
/**
* 指定Bot不存在
*/
object
NoSuchBotException
:
IllegalAccessException
(
"指定Bot不存在"
)
/**
* 指定Bot不存在
*/
object
PermissionDeniedException
:
IllegalAccessException
(
"无操作限权"
)
/**
* 错误参数
*/
class
IllegalParamException
(
message
:
String
)
:
IllegalAccessException
(
message
)
\ No newline at end of file
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/StateCode.kt
0 → 100644
View file @
2687b55f
package
net.mamoe.mirai.api.http.data
import
kotlinx.serialization.Serializable
@Serializable
open
class
StateCode
(
val
code
:
Int
,
var
msg
:
String
)
{
object
Success
:
StateCode
(
0
,
"success"
)
// 成功
object
NoBot
:
StateCode
(
2
,
"指定Bot不存在"
)
object
IllegalSession
:
StateCode
(
3
,
"Session失效或不存在"
)
object
NotVerifySession
:
StateCode
(
4
,
"Session未认证"
)
object
NoElement
:
StateCode
(
5
,
"指定对象不存在"
)
object
PermissionDenied
:
StateCode
(
10
,
"无操作权限"
)
// KS bug: 主构造器中不能有非字段参数 https://github.com/Kotlin/kotlinx.serialization/issues/575
@Serializable
class
IllegalAccess
()
:
StateCode
(
400
,
""
)
{
// 非法访问
constructor
(
msg
:
String
)
:
this
()
{
this
.
msg
=
msg
}
}
}
\ No newline at end of file
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/d
to
/ContactDTO.kt
→
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/d
ata/common
/ContactDTO.kt
View file @
2687b55f
package
net.mamoe.mirai.api.http.d
to
package
net.mamoe.mirai.api.http.d
ata.common
import
kotlinx.serialization.Serializable
import
net.mamoe.mirai.contact.Group
...
...
@@ -30,7 +30,8 @@ data class MemberDTO(
val
group
:
GroupDTO
)
:
ContactDTO
()
{
constructor
(
member
:
Member
)
:
this
(
member
.
id
,
member
.
groupCard
,
member
.
permission
,
GroupDTO
(
member
.
group
)
member
.
id
,
member
.
groupCard
,
member
.
permission
,
GroupDTO
(
member
.
group
)
)
}
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/data/common/DTO.kt
0 → 100644
View file @
2687b55f
package
net.mamoe.mirai.api.http.data.common
import
kotlinx.serialization.*
import
kotlinx.serialization.json.Json
import
kotlinx.serialization.modules.SerializersModule
import
net.mamoe.mirai.api.http.AuthedSession
interface
DTO
@Serializable
data class
AuthDTO
(
val
authKey
:
String
)
:
DTO
@Serializable
abstract
class
VerifyDTO
:
DTO
{
abstract
val
sessionKey
:
String
@Transient
lateinit
var
session
:
AuthedSession
// 反序列化验证成功后传入
}
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/d
to
/MessageDTO.kt
→
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/d
ata/common
/MessageDTO.kt
View file @
2687b55f
package
net.mamoe.mirai.api.http.d
to
package
net.mamoe.mirai.api.http.d
ata.common
import
kotlinx.serialization.SerialName
import
kotlinx.serialization.Serializable
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/AuthDTO.kt
deleted
100644 → 0
View file @
96554f2c
package
net.mamoe.mirai.api.http.dto
import
kotlinx.serialization.Serializable
@Serializable
data class
AuthDTO
(
val
authKey
:
String
)
:
DTO
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/dto/VerifyDTO.kt
deleted
100644 → 0
View file @
96554f2c
package
net.mamoe.mirai.api.http.dto
import
kotlinx.serialization.Serializable
import
kotlinx.serialization.Transient
import
net.mamoe.mirai.api.http.AuthedSession
import
net.mamoe.mirai.contact.Group
import
net.mamoe.mirai.contact.Member
@Serializable
abstract
class
VerifyDTO
:
DTO
{
abstract
val
sessionKey
:
String
@Transient
lateinit
var
session
:
AuthedSession
// 反序列化验证后传入
}
@Serializable
data class
BindDTO
(
override
val
sessionKey
:
String
,
val
qq
:
Long
)
:
VerifyDTO
()
@Serializable
data class
SendDTO
(
override
val
sessionKey
:
String
,
val
target
:
Long
,
val
messageChain
:
MessageChainDTO
)
:
VerifyDTO
()
typealias
GroupTargetDTO
=
FriendTargetDTO
@Serializable
data class
FriendTargetDTO
(
override
val
sessionKey
:
String
,
val
target
:
Long
)
:
VerifyDTO
()
@Serializable
data class
MuteDTO
(
override
val
sessionKey
:
String
,
val
target
:
Long
,
val
member
:
Long
=
0
,
val
time
:
Int
=
0
)
:
VerifyDTO
()
@Serializable
data class
GroupConfigDTO
(
override
val
sessionKey
:
String
,
val
target
:
Long
,
val
config
:
GroupInfoDTO
)
:
VerifyDTO
()
@Serializable
data class
GroupInfoDTO
(
val
name
:
String
?
=
null
,
val
announcement
:
String
?
=
null
,
val
confessTalk
:
Boolean
?
=
null
,
val
allowMemberInvite
:
Boolean
?
=
null
,
val
autoApprove
:
Boolean
?
=
null
,
val
anonymousChat
:
Boolean
?
=
null
)
:
DTO
{
constructor
(
group
:
Group
)
:
this
(
group
.
name
,
group
.
announcement
,
group
.
confessTalk
,
group
.
allowMemberInvite
,
group
.
autoApprove
,
group
.
anonymousChat
)
}
@Serializable
data class
MemberConfigDTO
(
override
val
sessionKey
:
String
,
val
target
:
Long
,
val
memberId
:
Long
,
val
config
:
MemberInfoDTO
)
:
VerifyDTO
()
@Serializable
data class
MemberInfoDTO
(
val
name
:
String
?
=
null
,
val
specialTitle
:
String
?
=
null
)
:
DTO
{
constructor
(
member
:
Member
)
:
this
(
member
.
groupCard
,
member
.
specialTitle
)
}
@Serializable
open
class
StateCode
(
val
code
:
Int
,
var
msg
:
String
)
{
object
Success
:
StateCode
(
0
,
"success"
)
// 成功
object
NoBot
:
StateCode
(
2
,
"指定Bot不存在"
)
object
IllegalSession
:
StateCode
(
3
,
"Session失效或不存在"
)
object
NotVerifySession
:
StateCode
(
4
,
"Session未认证"
)
object
NoElement
:
StateCode
(
5
,
"指定对象不存在"
)
object
PermissionDenied
:
StateCode
(
10
,
"无操作权限"
)
// KS bug: 主构造器中不能有非字段参数 https://github.com/Kotlin/kotlinx.serialization/issues/575
@Serializable
class
IllegalAccess
()
:
StateCode
(
400
,
""
)
{
// 非法访问
constructor
(
msg
:
String
)
:
this
()
{
this
.
msg
=
msg
}
}
}
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/AuthRouteModule.kt
View file @
2687b55f
...
...
@@ -3,10 +3,12 @@ package net.mamoe.mirai.api.http.route
import
io.ktor.application.Application
import
io.ktor.application.call
import
io.ktor.routing.routing
import
kotlinx.serialization.Serializable
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.api.http.AuthedSession
import
net.mamoe.mirai.api.http.SessionManager
import
net.mamoe.mirai.api.http.dto.*
import
net.mamoe.mirai.api.http.data.*
import
net.mamoe.mirai.api.http.data.common.VerifyDTO
import
kotlin.coroutines.EmptyCoroutineContext
...
...
@@ -43,6 +45,9 @@ fun Application.authModule() {
}
}
@Serializable
private
data class
BindDTO
(
override
val
sessionKey
:
String
,
val
qq
:
Long
)
:
VerifyDTO
()
private
fun
getBotOrThrow
(
qq
:
Long
)
=
try
{
Bot
.
instanceWhose
(
qq
)
}
catch
(
e
:
NoSuchElementException
)
{
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/BaseRoute.kt
View file @
2687b55f
...
...
@@ -19,7 +19,10 @@ import io.ktor.util.pipeline.PipelineContext
import
net.mamoe.mirai.api.http.AuthedSession
import
net.mamoe.mirai.api.http.SessionManager
import
net.mamoe.mirai.api.http.TempSession
import
net.mamoe.mirai.api.http.dto.*
import
net.mamoe.mirai.api.http.data.*
import
net.mamoe.mirai.api.http.data.common.*
import
net.mamoe.mirai.api.http.util.jsonParseOrNull
import
net.mamoe.mirai.api.http.util.toJson
fun
Application
.
mirai
()
{
install
(
DefaultHeaders
)
...
...
@@ -136,14 +139,13 @@ internal suspend fun ApplicationCall.respondJson(json: String, status: HttpStatu
internal
suspend
inline
fun
<
reified
T
:
DTO
>
ApplicationCall
.
receiveDTO
():
T
?
=
receive
<
String
>().
jsonParseOrNull
()
fun
PipelineContext
<
Unit
,
ApplicationCall
>.
illegalParam
(
expectingType
:
String
?,
paramName
:
String
,
actualValue
:
String
?
=
call
.
parameters
[
paramName
]
):
Nothing
=
throw
IllegalParamException
(
"Illegal param. A $expectingType is required for `$paramName` while `$actualValue` is given"
)
@Suppress
(
"IMPLICIT_CAST_TO_ANY"
)
@UseExperimental
(
ExperimentalUnsignedTypes
::
class
)
internal
inline
fun
<
reified
R
>
PipelineContext
<
Unit
,
ApplicationCall
>.
paramOrNull
(
name
:
String
):
R
=
...
...
@@ -171,42 +173,3 @@ internal inline fun <reified R> PipelineContext<Unit, ApplicationCall>.paramOrNu
else
->
error
(
name
::
class
.
simpleName
+
" is not supported"
)
}
as
R
?:
illegalParam
(
R
::
class
.
simpleName
,
name
)
/**
* 错误请求. 抛出这个异常后将会返回错误给一个请求
*/
@Suppress
(
"unused"
)
open
class
IllegalAccessException
:
Exception
{
override
val
message
:
String
get
()
=
super
.
message
!!
constructor
(
message
:
String
)
:
super
(
message
,
null
)
constructor
(
cause
:
Throwable
)
:
super
(
cause
.
toString
(),
cause
)
constructor
(
message
:
String
,
cause
:
Throwable
?)
:
super
(
message
,
cause
)
}
/**
* Session失效或不存在
*/
object
IllegalSessionException
:
IllegalAccessException
(
"Session失效或不存在"
)
/**
* Session未激活
*/
object
NotVerifiedSessionException
:
IllegalAccessException
(
"Session未激活"
)
/**
* 指定Bot不存在
*/
object
NoSuchBotException
:
IllegalAccessException
(
"指定Bot不存在"
)
/**
* 指定Bot不存在
*/
object
PermissionDeniedException
:
IllegalAccessException
(
"无操作限权"
)
/**
* 错误参数
*/
class
IllegalParamException
(
message
:
String
)
:
IllegalAccessException
(
message
)
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/GroupManageModule.kt
→
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/GroupManage
Route
Module.kt
View file @
2687b55f
...
...
@@ -3,7 +3,12 @@ package net.mamoe.mirai.api.http.route
import
io.ktor.application.Application
import
io.ktor.application.call
import
io.ktor.routing.routing
import
net.mamoe.mirai.api.http.dto.*
import
kotlinx.serialization.Serializable
import
net.mamoe.mirai.api.http.data.*
import
net.mamoe.mirai.api.http.data.common.DTO
import
net.mamoe.mirai.api.http.data.common.VerifyDTO
import
net.mamoe.mirai.contact.Group
import
net.mamoe.mirai.contact.Member
fun
Application
.
groupManageModule
()
{
...
...
@@ -23,14 +28,14 @@ fun Application.groupManageModule() {
}
miraiVerify
<
MuteDTO
>(
"/mute"
)
{
when
(
it
.
session
.
bot
.
getGroup
(
it
.
target
)[
it
.
member
].
mute
(
it
.
time
))
{
when
(
it
.
session
.
bot
.
getGroup
(
it
.
target
)[
it
.
member
Id
].
mute
(
it
.
time
))
{
true
->
call
.
respondStateCode
(
StateCode
.
Success
)
else
->
throw
PermissionDeniedException
}
}
miraiVerify
<
MuteDTO
>(
"/unmute"
)
{
when
(
it
.
session
.
bot
.
getGroup
(
it
.
target
).
members
[
it
.
member
].
unmute
())
{
when
(
it
.
session
.
bot
.
getGroup
(
it
.
target
).
members
[
it
.
member
Id
].
unmute
())
{
true
->
call
.
respondStateCode
(
StateCode
.
Success
)
else
->
throw
PermissionDeniedException
}
...
...
@@ -41,7 +46,7 @@ fun Application.groupManageModule() {
*/
miraiGet
(
"/groupConfig"
)
{
val
group
=
it
.
bot
.
getGroup
(
paramOrNull
(
"target"
))
call
.
respondDTO
(
Group
Info
DTO
(
group
))
call
.
respondDTO
(
Group
Detail
DTO
(
group
))
}
miraiVerify
<
GroupConfigDTO
>(
"/groupConfig"
)
{
dto
->
...
...
@@ -62,13 +67,13 @@ fun Application.groupManageModule() {
* 群员信息管理(需要相关权限)
*/
miraiGet
(
"/memberInfo"
)
{
val
member
=
it
.
bot
.
getGroup
(
paramOrNull
(
"target"
))[
paramOrNull
(
"memberI
D
"
)]
call
.
respondDTO
(
Member
Info
DTO
(
member
))
val
member
=
it
.
bot
.
getGroup
(
paramOrNull
(
"target"
))[
paramOrNull
(
"memberI
d
"
)]
call
.
respondDTO
(
Member
Detail
DTO
(
member
))
}
miraiVerify
<
Member
Config
DTO
>(
"/memberInfo"
)
{
dto
->
miraiVerify
<
Member
Info
DTO
>(
"/memberInfo"
)
{
dto
->
val
member
=
dto
.
session
.
bot
.
getGroup
(
dto
.
target
)[
dto
.
memberId
]
with
(
dto
.
config
)
{
with
(
dto
.
info
)
{
name
?.
let
{
member
.
groupCard
=
it
}
specialTitle
?.
let
{
member
.
specialTitle
=
it
}
}
...
...
@@ -76,4 +81,51 @@ fun Application.groupManageModule() {
}
}
}
@Serializable
private
data class
MuteDTO
(
override
val
sessionKey
:
String
,
val
target
:
Long
,
val
memberId
:
Long
=
0
,
val
time
:
Int
=
0
)
:
VerifyDTO
()
@Serializable
private
data class
GroupConfigDTO
(
override
val
sessionKey
:
String
,
val
target
:
Long
,
val
config
:
GroupDetailDTO
)
:
VerifyDTO
()
@Serializable
private
data class
GroupDetailDTO
(
val
name
:
String
?
=
null
,
val
announcement
:
String
?
=
null
,
val
confessTalk
:
Boolean
?
=
null
,
val
allowMemberInvite
:
Boolean
?
=
null
,
val
autoApprove
:
Boolean
?
=
null
,
val
anonymousChat
:
Boolean
?
=
null
)
:
DTO
{
constructor
(
group
:
Group
)
:
this
(
group
.
name
,
group
.
announcement
,
group
.
confessTalk
,
group
.
allowMemberInvite
,
group
.
autoApprove
,
group
.
anonymousChat
)
}
@Serializable
private
data class
MemberInfoDTO
(
override
val
sessionKey
:
String
,
val
target
:
Long
,
val
memberId
:
Long
,
val
info
:
MemberDetailDTO
)
:
VerifyDTO
()
@Serializable
private
data class
MemberDetailDTO
(
val
name
:
String
?
=
null
,
val
specialTitle
:
String
?
=
null
)
:
DTO
{
constructor
(
member
:
Member
)
:
this
(
member
.
groupCard
,
member
.
specialTitle
)
}
\ No newline at end of file
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/InfoRouteModule.kt
View file @
2687b55f
...
...
@@ -3,10 +3,10 @@ package net.mamoe.mirai.api.http.route
import
io.ktor.application.Application
import
io.ktor.application.call
import
io.ktor.routing.routing
import
net.mamoe.mirai.api.http.d
to
.GroupDTO
import
net.mamoe.mirai.api.http.d
to
.MemberDTO
import
net.mamoe.mirai.api.http.d
to
.QQDTO
import
net.mamoe.mirai.api.http.
dto
.toJson
import
net.mamoe.mirai.api.http.d
ata.common
.GroupDTO
import
net.mamoe.mirai.api.http.d
ata.common
.MemberDTO
import
net.mamoe.mirai.api.http.d
ata.common
.QQDTO
import
net.mamoe.mirai.api.http.
util
.toJson
import
net.mamoe.mirai.contact.toMutableList
fun
Application
.
infoModule
()
{
...
...
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/MessageRouteModule.kt
→
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/route/
Send
MessageRouteModule.kt
View file @
2687b55f
...
...
@@ -3,7 +3,10 @@ package net.mamoe.mirai.api.http.route
import
io.ktor.application.Application
import
io.ktor.application.call
import
io.ktor.routing.routing
import
net.mamoe.mirai.api.http.dto.*
import
kotlinx.serialization.Serializable
import
net.mamoe.mirai.api.http.data.*
import
net.mamoe.mirai.api.http.data.common.*
import
net.mamoe.mirai.api.http.util.toJson
fun
Application
.
messageModule
()
{
routing
{
...
...
@@ -26,12 +29,12 @@ fun Application.messageModule() {
call
.
respondStateCode
(
StateCode
.
Success
)
}
miraiVerify
<
VerifyDTO
>(
"/event/message"
)
{
}
miraiVerify
<
VerifyDTO
>(
"/addFriend"
)
{
}
}
}
\ No newline at end of file
}
@Serializable
private
data class
SendDTO
(
override
val
sessionKey
:
String
,
val
target
:
Long
,
val
messageChain
:
MessageChainDTO
)
:
VerifyDTO
()
\ No newline at end of file
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/
dto/DTO
.kt
→
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/
util/Json
.kt
View file @
2687b55f
package
net.mamoe.mirai.api.http.
dto
package
net.mamoe.mirai.api.http.
util
import
kotlinx.serialization.*
import
kotlinx.serialization.json.Json
import
kotlinx.serialization.modules.SerializersModule
interface
DTO
import
net.mamoe.mirai.api.http.data.common.*
// 解析失败时直接返回null,由路由判断响应400状态
@UseExperimental
(
ImplicitReflectionSerializer
::
class
)
...
...
@@ -20,7 +19,7 @@ inline fun <reified T : Any> String.jsonParseOrNull(
inline
fun
<
reified
T
:
Any
>
T
.
toJson
(
serializer
:
SerializationStrategy
<
T
>?
=
null
):
String
=
if
(
serializer
==
null
)
MiraiJson
.
json
.
stringify
(
this
)
else
MiraiJson
.
json
.
stringify
(
serializer
,
this
)
else
MiraiJson
.
json
.
stringify
(
serializer
,
this
)
// 序列化列表时,stringify需要使用的泛型是T,而非List<T>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment