refactor: DTO 字段去下划线 + SimApiBaseResponse 不再可继承 + 删除 SimApiJson/toJsonString

- 纯 POCO DTO 字段去下划线:AuthDto(id/name/applicationId/profileId/scene 等)、
  SimApiLoginItem(id/types/meta/extra)、AesBodyRequest(data)、
  SimApiBaseResponse 系列(code/message/data/list/page/count/total)
- SimApiBaseResponse 去 open(不再允许继承)+ 删 @SerializerParent(无子类继承)
- SimApiResponse<T> / SimApiDataResponse 改为组合(自带 code/message/data)
- 删除 toJsonString(无使用点,统一走 simapi_serialization)
- 删除 SimApiJson.cj:json() → SimApiUtil.json() 直接序列化;
  escapeJson() 迁入 SimApiUtil
- 同步更新所有字段引用(AuthCenter/AuthIam/HttpClient/ExceptionMiddleware 等)
- 保留 sqlsharp 实体 User/Bot 的 _ 前缀(soulsoft 宏依赖)
This commit is contained in:
2026-08-18 01:15:15 +08:00
parent ea31bd9b6a
commit c7099040fa
15 changed files with 175 additions and 217 deletions
+17 -17
View File
@@ -65,7 +65,7 @@ public class SimApiAuthCenter {
response.ensureSuccessStatusCode()
let json = response.content.readAsString()
let resp = JsonSerializer.Deserialize<SimApiBaseResponse>(json)
SimApiError.errorWhen(resp._code != 200, code: 400, message: "签名验证失败")
SimApiError.errorWhen(resp.code != 200, code: 400, message: "签名验证失败")
} finally {
response.close()
}
@@ -92,7 +92,7 @@ public class SimApiAuthCenter {
body["keyword"] = keyword
body["skip"] = skip
body["take"] = take
_client.signQuery<Array<AppAndProfileItem>>("/api/auth/group/search", body: SimApiJson.json(Some(body)))
_client.signQuery<Array<AppAndProfileItem>>("/api/auth/group/search", body: SimApiUtil.json(Some(body)))
}
/**
@@ -102,7 +102,7 @@ public class SimApiAuthCenter {
var body = HashMap<String, Any>()
body["profileId"] = profileId
body["groupId"] = groupId
_client.signQuery<GroupDetailTreeNode>("/api/auth/group/detail", body: SimApiJson.json(Some(body)))
_client.signQuery<GroupDetailTreeNode>("/api/auth/group/detail", body: SimApiUtil.json(Some(body)))
}
/**
@@ -113,7 +113,7 @@ public class SimApiAuthCenter {
body["groupId"] = groupId
body["profileId"] = profileId
_client.signQuery<Array<String>>("/api/auth/internal/group/related-group-ids",
body: SimApiJson.json(Some(body)))
body: SimApiUtil.json(Some(body)))
}
// ===== Profile 相关 =====
@@ -126,7 +126,7 @@ public class SimApiAuthCenter {
body["keyword"] = keyword
body["skip"] = skip
body["take"] = take
_client.signQuery<Array<AppAndProfileItem>>("/api/auth/profile/search", body: SimApiJson.json(Some(body)))
_client.signQuery<Array<AppAndProfileItem>>("/api/auth/profile/search", body: SimApiUtil.json(Some(body)))
}
/**
@@ -139,7 +139,7 @@ public class SimApiAuthCenter {
arr.add(id)
}
body["ids"] = arr.toArray()
_client.signQuery<Array<AppAndProfileItem>>("/api/auth/profile/list", body: SimApiJson.json(Some(body)))
_client.signQuery<Array<AppAndProfileItem>>("/api/auth/profile/list", body: SimApiUtil.json(Some(body)))
}
// ===== AuthGate 内部应用专用 =====
@@ -151,7 +151,7 @@ public class SimApiAuthCenter {
var body = HashMap<String, Any>()
body["ProfileId"] = profileId
body["AppId"] = applicationId
_client.signQuery<Bool>("/api/auth/internal/app/check-owner", body: SimApiJson.json(Some(body)))
_client.signQuery<Bool>("/api/auth/internal/app/check-owner", body: SimApiUtil.json(Some(body)))
}
/**
@@ -166,7 +166,7 @@ public class SimApiAuthCenter {
}
body["AllowedAppIds"] = arr.toArray()
_client.signQuery<Array<AppAndProfileItem>>("/api/auth/internal/app/related",
body: SimApiJson.json(Some(body)))
body: SimApiUtil.json(Some(body)))
}
// ===== 系统登录 =====
@@ -184,7 +184,7 @@ public class SimApiAuthCenter {
if (let Some(scene) <- scene) { body["scene"] = scene }
if (let Some(data) <- data) { body["data"] = data }
if (let Some(backUrl) <- backUrl) { body["backUrl"] = backUrl }
let code = _client.signQuery<String>("/api/auth/login/code", body: SimApiJson.json(Some(body)))
let code = _client.signQuery<String>("/api/auth/login/code", body: SimApiUtil.json(Some(body)))
let server = _client.server
GetCodeResponse(code, server, "${server}/auth?code=${code}")
}
@@ -195,10 +195,10 @@ public class SimApiAuthCenter {
public func getLoginInfo(code: String, scene!: ?String = None): LoginInfoResponse {
var body = HashMap<String, Any>()
body["code"] = code
// 说明:C# 的 ErrorWhenNull(resp, 400232, "登录信息获取失败") 对应 signQuery 内部 _data.getOrThrow() 的
// 说明:C# 的 ErrorWhenNull(resp, 400232, "登录信息获取失败") 对应 signQuery 内部 data.getOrThrow() 的
// None 分支;仓颉版 signQuery 返回非空 T(data 缺失即抛异常),故此处无需重复判空。
let resp = _client.signQuery<LoginInfoResponse>("/api/auth/login/get", body: SimApiJson.json(Some(body)))
SimApiError.errorWhen(resp._scene != scene, code: 403003, message: "登录场景不匹配")
let resp = _client.signQuery<LoginInfoResponse>("/api/auth/login/get", body: SimApiUtil.json(Some(body)))
SimApiError.errorWhen(resp.scene != scene, code: 403003, message: "登录场景不匹配")
resp
}
@@ -214,7 +214,7 @@ public class SimApiAuthCenter {
if (let Some(data) <- data) { body["data"] = data }
if (let Some(backUrl) <- backUrl) { body["backUrl"] = backUrl }
body["profileId"] = userId
let code = _client.signQuery<String>("/api/auth/confirm/code", body: SimApiJson.json(Some(body)))
let code = _client.signQuery<String>("/api/auth/confirm/code", body: SimApiUtil.json(Some(body)))
let server = _client.server
GetCodeResponse(code, server, "${server}/confirm?code=${code}")
}
@@ -225,14 +225,14 @@ public class SimApiAuthCenter {
public func confirm(code: String, scene: String, userId!: ?String = None): ConfirmResponse {
var body = HashMap<String, Any>()
body["code"] = code
let resp = _client.signQuery<ConfirmResponse>("/api/auth/confirm/get", body: SimApiJson.json(Some(body)))
SimApiError.errorWhen(userId != Some(resp._profileId), code: 403002, message: "安全确认身份不匹配")
SimApiError.errorWhen(resp._scene != scene, code: 403003, message: "安全确认场景不匹配")
let resp = _client.signQuery<ConfirmResponse>("/api/auth/confirm/get", body: SimApiUtil.json(Some(body)))
SimApiError.errorWhen(userId != Some(resp.profileId), code: 403002, message: "安全确认身份不匹配")
SimApiError.errorWhen(resp.scene != scene, code: 403003, message: "安全确认场景不匹配")
resp
}
/// 简单单字段请求体:{"field":"value"}
private static func simpleBody(field: String, value: String): String {
"{\"${field}\":\"${SimApiJson.escapeJson(value)}\"}"
"{\"${field}\":\"${SimApiUtil.escapeJson(value)}\"}"
}
}
+42 -42
View File
@@ -18,49 +18,49 @@ import std.collection.*
* 应用/Profile 通用项(对齐 C# AppAndProfileItem)。
*/
public class AppAndProfileItem {
public var _id: String = ""
public var _name: String = ""
public var _image: ?String = None
public var _description: ?String = None
public var id: String = ""
public var name: String = ""
public var image: ?String = None
public var description: ?String = None
}
/**
* 安全确认响应(对齐 C# ConfirmResponse)。
* _data 用 ?HashMap<String, Any> 对齐 C# Dictionary<string,object>?(任意 JSON 对象)。
* data 用 ?HashMap<String, Any> 对齐 C# Dictionary<string,object>?(任意 JSON 对象)。
*/
public class ConfirmResponse {
public var _applicationId: String = ""
public var _profileId: String = ""
public var _scene: ?String = None
public var _data: ?HashMap<String, Any> = None
public var applicationId: String = ""
public var profileId: String = ""
public var scene: ?String = None
public var data: ?HashMap<String, Any> = None
}
/**
* 登录信息响应(对齐 C# LoginInfoResponse)。
*/
public class LoginInfoResponse {
public var _scene: ?String = None
public var _data: ?HashMap<String, Any> = None
public var _profileId: String = ""
public var _name: String = ""
public var _image: ?String = None
public var _description: ?String = None
public var scene: ?String = None
public var data: ?HashMap<String, Any> = None
public var profileId: String = ""
public var name: String = ""
public var image: ?String = None
public var description: ?String = None
}
/**
* 获取授权码响应(对齐 C# GetCodeResponse)。
*/
public class GetCodeResponse {
public var _code: String = ""
public var _server: String = ""
public var _fullUrl: String = ""
public var code: String = ""
public var server: String = ""
public var fullUrl: String = ""
public init() {}
public init(code: String, server: String, fullUrl: String) {
this._code = code
this._server = server
this._fullUrl = fullUrl
this.code = code
this.server = server
this.fullUrl = fullUrl
}
}
@@ -68,42 +68,42 @@ public class GetCodeResponse {
* 群组关联项(对齐 C# GroupRelatedItem)。
*/
public class GroupRelatedItem {
public var _id: String = ""
public var _name: String = ""
public var _image: ?String = None
public var _description: ?String = None
public var _isOwner: Bool = false
public var _isAdmin: Bool = false
public var _isMember: Bool = false
public var id: String = ""
public var name: String = ""
public var image: ?String = None
public var description: ?String = None
public var isOwner: Bool = false
public var isAdmin: Bool = false
public var isMember: Bool = false
}
/**
* 群组详情树节点(对齐 C# GroupDetailTreeNodechildren 递归)。
*/
public class GroupDetailTreeNode {
public var _id: String = ""
public var _name: String = ""
public var _image: ?String = None
public var _description: ?String = None
public var _sort: Int64 = 0
public var _children: Array<GroupDetailTreeNode> = []
public var id: String = ""
public var name: String = ""
public var image: ?String = None
public var description: ?String = None
public var sort: Int64 = 0
public var children: Array<GroupDetailTreeNode> = []
}
/**
* 权限项(对齐 C# PermissionItem)。
*/
public class PermissionItem {
public var _identifier: String = ""
public var _name: String = ""
public var _group: String = ""
public var _description: String = ""
public var identifier: String = ""
public var name: String = ""
public var group: String = ""
public var description: String = ""
public init() {}
public init(identifier: String, name: String, group: String, description: String) {
this._identifier = identifier
this._name = name
this._group = group
this._description = description
this.identifier = identifier
this.name = name
this.group = group
this.description = description
}
}
+7 -7
View File
@@ -29,15 +29,15 @@ public class SimApiAuthIam {
var items = ArrayList<Any>()
for (p in permissions) {
var item = HashMap<String, Any>()
item["identifier"] = p._identifier
item["name"] = p._name
item["group"] = p._group
item["description"] = p._description
item["identifier"] = p.identifier
item["name"] = p.name
item["group"] = p.group
item["description"] = p.description
items.add(item)
}
var body = HashMap<String, Any>()
body["permissions"] = items.toArray()
_client.signQuery<String>("/api/iam/permission/register", body: SimApiJson.json(Some(body)))
_client.signQuery<String>("/api/iam/permission/register", body: SimApiUtil.json(Some(body)))
}
/**
@@ -49,7 +49,7 @@ public class SimApiAuthIam {
if (let Some(groupId) <- groupId) {
body["groupId"] = groupId
}
_client.signQuery<Array<String>>("/api/iam/permission/owned", body: SimApiJson.json(Some(body)))
_client.signQuery<Array<String>>("/api/iam/permission/owned", body: SimApiUtil.json(Some(body)))
}
/**
@@ -62,7 +62,7 @@ public class SimApiAuthIam {
if (let Some(groupId) <- groupId) {
body["groupId"] = groupId
}
let ok = _client.signQuery<Bool>("/api/iam/permission/check", body: SimApiJson.json(Some(body)))
let ok = _client.signQuery<Bool>("/api/iam/permission/check", body: SimApiUtil.json(Some(body)))
SimApiError.errorWhen(!ok, code: 403, message: "没有该权限")
}
}