docs: add autman plugin development rules

This commit is contained in:
2026-05-15 21:32:38 +08:00
parent f284a47a0e
commit 5024f17e9c
4 changed files with 629 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
//[open_source: true]
//[create_at: 2026-01-01 12:00:00]
//[title: 路由插件模板]
//[author: Hermes]
//[service: BOSS]
//[class: 工具类]
//[version: 1.0.0]
//[platform: web,qq,wx,tg,tb]
//[public: false]
//[price: 0]
//[disable: false]
//[description: Autman 微服务路由插件模板,支持 GET/POST、token 鉴权、JSON 返回。]
//[router: /example/api]
//[method: get]
//[method: post]
//[param: {"required":true,"key":"otto.example_token","bool":false,"placeholder":"访问Token","name":"接口鉴权Token","desc":"外部请求必须携带 access_token 或 token"}]
function replyJSON(obj) {
if (typeof response === "function") {
response(obj)
} else if (typeof sender !== "undefined" && sender.reply) {
sender.reply(obj)
} else {
sendText(JSON.stringify(obj))
}
}
function fail(code, msg) {
replyJSON({ ok: false, status: "fail", retcode: code, msg: msg })
}
function ok(data, msg) {
replyJSON({ ok: true, status: "ok", retcode: 0, msg: msg || "success", data: data || {} })
}
var method = (typeof getMethod === "function" ? getMethod() : (typeof getRouterMethod === "function" ? getRouterMethod() : "get"))
var params = typeof getRouterParams === "function" ? (getRouterParams() || {}) : {}
var body = {}
if (String(method).toLowerCase() === "post") {
var raw = typeof getRouterData === "function" ? getRouterData() : (typeof getRouterBody === "function" ? getRouterBody() : "")
if (raw) {
try {
body = JSON.parse(raw)
} catch (e) {
fail(-2, "POST JSON解析失败: " + e.message)
return
}
}
}
var accessToken = body.access_token || body.token || params.access_token || params.token || ""
var configuredToken = get("example_token") || ""
if (configuredToken && configuredToken !== accessToken) {
fail(-1, "token错误")
return
}
ok({ method: method, params: params, body: body }, "接口已启用")