Appearance
应用公告接口
用于获取指定应用的公告信息,支持两种请求方式,返回数据包含公告标题、内容及显示状态。
请求地址 GET / POST
http
https://nobase.cn/api/app/notice请求参数
| 参数名 | 类型 | 必需 | 说明 |
|---|---|---|---|
| appid | string | ✅ 是 | 应用唯一标识,从开发者平台获取 |
| signature | string | ✅ 是 | 应用签名,从开发者平台获取 |
响应参数
| 参数名 | 类型 | 说明 |
|---|---|---|
| code | number | 状态码:200=成功,其他为错误码 |
| msg | string | 状态描述,错误时返回具体原因 |
| data | object | 公告数据(仅code=200时返回) |
| data.title | string | 公告标题 |
| data.content | string | 公告正文,支持简单HTML标签 |
| data.show | number | 显示控制:1=显示,0=隐藏 |
成功响应示例
json
{
"code": 200,
"msg": "success",
"data": {
"title": "系统维护通知",
"content": "尊敬的用户,本系统将进行维护,期间可能无法正常使用,敬请谅解。",
"show": 1
}
}代码示例
javascript
// 替换为你的实际应用信息
const appid = "your_app_id";
const signature = "your_signature";
// 拼接请求参数(处理token可选逻辑)
const params = new URLSearchParams({
appid,
signature
});
// 发起请求并处理响应
const requestUrl = `https://nobase.cn/api/app/notice?${params.toString()}`;
fetch(requestUrl)
.then(response => {
if (!response.ok) throw new Error(`HTTP错误:${response.status}`);
return response.json();
})
.then(res => {
// 仅当状态码200且show=1时处理公告
if (res.code === 200 && res.data?.show === 1) {
console.log("公告标题:", res.data.title);
console.log("公告内容:", res.data.content);
} else {
console.log("暂无可用公告或权限不足");
}
})
.catch(error => console.error("请求失败:", error));python
import requests
# 配置参数
appid = "your_app_id"
signature = "your_signature"
url = "https://nobase.cn/api/app/notice"
# 构造请求参数(处理token可选逻辑)
params = {
"appid": appid,
"signature": signature
}
# 发起GET请求
try:
response = requests.get(
url=url,
params=params,
timeout=5 # 设置5秒超时
)
response.raise_for_status() # 自动抛出HTTP错误
res_data = response.json()
if res_data["code"] == 200 and res_data["data"]["show"] == 1:
print(f"公告标题:{res_data['data']['title']}")
print(f"公告内容:{res_data['data']['content']}")
else:
print("暂无可用公告或权限不足")
except requests.exceptions.RequestException as e:
print(f"请求失败:{str(e)}")java
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class NoticeApiDemo {
public static void main(String[] args) {
// 替换为实际参数
String appid = "your_app_id";
String signature = "your_signature";
try {
// 拼接请求参数(处理token可选逻辑)
StringBuilder params = new StringBuilder();
params.append("appid=").append(URLEncoder.encode(appid, "UTF-8"))
.append("&signature=").append(URLEncoder.encode(signature, "UTF-8"));
String urlStr = "https://nobase.cn/api/app/notice?" + params;
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000); // 连接超时
conn.setReadTimeout(5000); // 读取超时
// 读取响应内容
BufferedReader in = new BufferedReader(
new InputStreamReader(conn.getInputStream(), "UTF-8")
);
StringBuilder response = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
response.append(line);
}
in.close();
conn.disconnect();
// 解析JSON并处理
JsonObject resJson = JsonParser.parseString(response.toString()).getAsJsonObject();
if (resJson.get("code").getAsInt() == 200) {
JsonObject data = resJson.getAsJsonObject("data");
if (data.get("show").getAsInt() == 1) {
System.out.println("公告标题:" + data.get("title").getAsString());
System.out.println("公告内容:" + data.get("content").getAsString());
} else {
System.out.println("暂无可用公告");
}
} else {
System.out.println("接口错误:" + resJson.get("msg").getAsString());
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("请求失败:" + e.getMessage());
}
}
}php
<?php
// 配置参数
$appid = "your_app_id";
$signature = "your_signature";
// 拼接请求参数(处理token可选逻辑)
$params = [
"appid" => $appid,
"signature" => $signature
];
// 拼接URL并转义特殊字符
$url = "https://nobase.cn/api/app/notice?" . http_build_query($params);
// 发起请求(生产环境建议用cURL)
$response = @file_get_contents($url);
if ($response === false) {
die("请求失败:无法获取接口数据");
}
// 解析JSON
$data = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
die("请求失败:接口返回无效JSON");
}
// 处理响应
if ($data["code"] == 200 && $data["data"]["show"] == 1) {
echo "公告标题:" . htmlspecialchars($data["data"]["title"]) . "<br>";
echo "公告内容:" . htmlspecialchars($data["data"]["content"]);
} else {
echo "暂无可用公告或权限不足";
}
?>注意事项
- 参数校验:
appid和signature必须与开发者平台配置一致,否则会返回错误。 - 显示逻辑:仅当
data.show = 1时渲染公告,避免展示已下架内容。 - 性能优化:建议在客户端缓存公告数据(如localStorage),设置10-30分钟过期时间,减少重复请求。
- 错误处理:生产环境需处理网络异常、JSON解析失败、HTTP错误码(如500、404)等场景。

