Appearance
应用通知接口
用于获取指定应用的通知信息,返回数据为通知列表数组,包含每条通知的ID、标题、内容及创建时间,支持根据配置启用用户令牌校验。
请求地址 GET / POST
http
https://nobase.cn/api/app/notify请求参数
| 参数名 | 类型 | 必需 | 说明 |
|---|---|---|---|
| appid | string | ✅ 是 | 应用唯一标识,从后台获取的应用ID |
| signature | string | ✅ 是 | 应用签名,从后台直接获取 |
| token | string | ❌ 否 | 用户令牌,需在后台“应用配置”中启用后才需传递 |
返回示例
成功响应(有通知)
json
{
"code": 200,
"msg": "success",
"data": [
{
"ID": 19,
"appid": "3950767904",
"title": "测试通知",
"content": "测试",
"times": "2024-09-11 14:11:54"
},
{
"ID": 20,
"appid": "3950767904",
"title": "测试1",
"content": "测试",
"times": "2024-09-11 14:12:07"
}
]
}成功响应(无通知)
json
{
"code": 404,
"msg": "fail",
"data": "暂无通知"
}返回数据结构
| 参数名 | 类型 | 说明 |
|---|---|---|
| code | number | 状态码:200=有通知,404=无通知,其他为错误码 |
| msg | string | 状态描述:success=成功,fail=无通知/失败 |
| data | array/string | 通知数据:code=200时为数组,code=404时为"暂无通知"字符串 |
| data[].ID | string | 通知唯一ID(仅code=200时返回) |
| data[].appid | string | 应用ID(仅code=200时返回) |
| data[].title | string | 通知标题(仅code=200时返回) |
| data[].content | string | 通知内容(仅code=200时返回) |
| data[].times | string | 创建时间(仅code=200时返回) |
代码示例
javascript
// 配置参数(signature从后台获取,域名固定为nobase.cn)
const appid = "your_app_id";
const signature = "your_signature_from_backend";
const token = "your_user_token"; // 未启用可删除
// 拼接GET请求参数
const params = new URLSearchParams({ appid, signature });
if (token) params.append('token', token);
// 发起GET请求
const requestUrl = `https://nobase.cn/api/app/notify?${params.toString()}`;
fetch(requestUrl)
.then(response => {
if (!response.ok) throw new Error(`HTTP错误:${response.status}`);
return response.json();
})
.then(res => {
if (res.code === 200) {
// 有通知时处理列表
console.log("通知总数:", res.data.length);
res.data.forEach(notice => {
console.log(`通知ID:${notice.ID}`);
console.log(`标题:${notice.title}`);
console.log(`内容:${notice.content}`);
console.log(`创建时间:${notice.times}\n`);
});
} else if (res.code === 404) {
// 无通知时处理提示
console.log("通知状态:", res.data); // 输出"暂无通知"
} else {
// 其他错误(如签名错误、权限不足等)
console.error("接口错误:", res.msg);
}
})
.catch(error => console.error("请求失败:", error));python
import requests
# 配置参数
appid = "your_app_id"
signature = "your_signature_from_backend"
token = "your_user_token" # 未启用可设为None
# 构造GET请求参数
params = {
"appid": appid,
"signature": signature
}
if token:
params["token"] = token
# 发起GET请求
url = "https://nobase.cn/api/app/notify"
try:
response = requests.get(url, params=params, timeout=5)
response.raise_for_status() # 抛出HTTP错误
res_data = response.json()
if res_data["code"] == 200:
# 有通知时处理列表
print(f"通知总数:{len(res_data['data'])}")
for notice in res_data["data"]:
print(f"\n通知ID:{notice['ID']}")
print(f"标题:{notice['title']}")
print(f"内容:{notice['content']}")
print(f"创建时间:{notice['times']}")
elif res_data["code"] == 404:
# 无通知时处理提示
print(f"通知状态:{res_data['data']}") # 输出"暂无通知"
else:
# 其他错误
print(f"接口错误:{res_data['msg']}")
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 java.nio.charset.StandardCharsets;
import com.google.gson.JsonObject;
import com.google.gson.JsonArray;
import com.google.gson.JsonParser;
public class AppNotifyApiDemo {
public static void main(String[] args) {
// 配置参数
String appid = "your_app_id";
String signature = "your_signature_from_backend";
String token = "your_user_token"; // 未启用可设为null
try {
// 拼接GET请求参数
StringBuilder params = new StringBuilder();
params.append("appid=").append(URLEncoder.encode(appid, "UTF-8"))
.append("&signature=").append(URLEncoder.encode(signature, "UTF-8"));
if (token != null && !token.isEmpty()) {
params.append("&token=").append(URLEncoder.encode(token, "UTF-8"));
}
// 发起GET请求
URL url = new URL("https://nobase.cn/api/app/notify?" + params);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
// 读取响应
BufferedReader in = new BufferedReader(
new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)
);
StringBuilder response = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
response.append(line);
}
in.close();
conn.disconnect();
// 解析响应
JsonObject resJson = JsonParser.parseString(response.toString()).getAsJsonObject();
int code = resJson.get("code").getAsInt();
if (code == 200) {
// 有通知时处理列表
JsonArray dataArray = resJson.getAsJsonArray("data");
System.out.println("通知总数:" + dataArray.size());
for (int i = 0; i < dataArray.size(); i++) {
JsonObject notice = dataArray.get(i).getAsJsonObject();
System.out.println("\n通知ID:" + notice.get("ID").getAsString());
System.out.println("标题:" + notice.get("title").getAsString());
System.out.println("内容:" + notice.get("content").getAsString());
System.out.println("创建时间:" + notice.get("times").getAsString());
}
} else if (code == 404) {
// 无通知时处理提示
System.out.println("通知状态:" + resJson.get("data").getAsString()); // 输出"暂无通知"
} 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_from_backend";
$token = "your_user_token"; // 未启用可设为null
// 构造GET请求参数
$params = [
"appid" => $appid,
"signature" => $signature
];
if ($token !== null && $token !== "") {
$params["token"] = $token;
}
// 拼接URL并发起请求
$url = "https://nobase.cn/api/app/notify?" . http_build_query($params);
$response = @file_get_contents($url);
if ($response === false) {
die("请求失败:无法获取通知数据");
}
// 解析响应
$data = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
die("请求失败:接口返回无效JSON");
}
// 处理响应
if ($data["code"] == 200) {
// 有通知时处理列表
echo "通知总数:" . count($data["data"]) . "<br><br>";
foreach ($data["data"] as $notice) {
echo "通知ID:" . htmlspecialchars($notice["ID"]) . "<br>";
echo "标题:" . htmlspecialchars($notice["title"]) . "<br>";
echo "内容:" . htmlspecialchars($notice["content"]) . "<br>";
echo "创建时间:" . htmlspecialchars($notice["times"]) . "<br><br>";
}
} elseif ($data["code"] == 404) {
// 无通知时处理提示
echo "通知状态:" . htmlspecialchars($data["data"]); // 输出"暂无通知"
} else {
// 其他错误
echo "接口错误:" . htmlspecialchars($data["msg"]);
}
?>注意事项
- 状态码处理:需特别处理
code=404场景(返回“暂无通知”字符串),避免将其当作错误处理,与其他错误码(如签名错误)区分开。 - 数据类型兼容:
data字段在code=200时为数组,code=404时为字符串,客户端需根据状态码判断数据类型,避免类型转换错误。 - 参数位置:GET请求参数必须拼在URL后,确保
appid、signature等必填参数完整,缺失会返回对应错误信息。 - 空数据场景:
code=404是正常业务状态(无通知),而非接口错误,无需触发错误提示,建议前端展示“暂无通知”友好提示。

