获取用户收到的站内信通知
| 接口名 | GET: /login-register/open-api/messages/station/received | |||
| 入参:(Param传值) | Param传值 | |||
| 是否必传 | 默认值 | 描述 | 备注 | |
| size | 否 | 10 | 每页个数 | |
| current | 否 | 1 | 当前页码 | |
| 入参:(Header传值) | ||||
| Authorization | 是 | - | 传递AccessToken | 格式:Bearer {AccessToken} |
| 入参示例:(Param传值) | ||||
| GET: /login-register/open-api/messages/station/received?size=10¤t=1 | ||||
| 回参示例:(application/json) | ||||
|
{
"code": 0,
"msg": null,
"data": {
"records": [
{
"messageId": "2079447xxx51091457",
"title": "邀请成员", // 标题
"content": "测试一加入企业,一起协作吧!", // 内容
"category": "1", // 分类:0公告;1站内信
"categoryType": "1", // 消息类型:1普通通知;2文件分享通知;3申请权限通知
"processFlag": "0",
"processedFlag": "0",
"readFlag": "0", // 是否已读:0-未读,1-已读
"createTime": "2026-07-21 14:02:57",
"createBy": "admin"
},
{
......
}
],
"total": 27,
"size": 10,
"current": 1,
"pages": 3
},
"ok": true
}
|
||||
package com.hoteam.sview.demo;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.ContentType;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpStatus;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
/**
* 分页获取用户站内信列表调用 Demo
* <p>
* 接口:GET /login-register/open-api/messages/station/received
* 鉴权:Header Authorization: Bearer {AccessToken}
*/
@Slf4j
public class StationMessageListDemo {
/** 业务网关地址,部署时替换为实际 gateway 地址 */
private static final String STATION_MESSAGE_URL = "http://your-host/login-register/open-api/messages/station/received";
/**
* 分页获取当前用户收到的站内信列表
*
* @param accessToken 通过 OAuth2TokenDemo / OAuth2TokenIntegrationDemo 获取的 access_token
* @param current 当前页码(必填,默认 1)
* @param size 每页条数(必填,默认 10)
* @return 分页数据 JSONObject;查询失败返回 null
*/
public static JSONObject getStationMessageList(String accessToken, Integer current, Integer size) {
if (StrUtil.isBlank(accessToken)) {
log.warn("accessToken 不能为空");
return null;
}
if (current == null || current < 1) {
log.warn("页码 current 不能小于 1: [{}]", current);
return null;
}
if (size == null || size < 1) {
log.warn("每页条数 size 不能小于 1: [{}]", size);
return null;
}
if (size > 100) {
log.warn("每页条数 size 不能超过 100: [{}]", size);
return null;
}
// 拼接 URL 与分页参数
String url = STATION_MESSAGE_URL
+ "?current=" + current
+ "&size=" + size;
HttpRequest request = HttpRequest.get(url)
.header(Header.AUTHORIZATION, "Bearer " + accessToken)
.header(Header.CONTENT_TYPE, ContentType.JSON.getValue())
.timeout(10_000);
// 添加公共 Header(tenant-id、deviceId、deviceModel、deviceType、lang 等)
CommonHeaderUtil.withCommonHeaders(request);
try (HttpResponse response = request.execute()) {
int status = response.getStatus();
String respBody = response.body();
log.info("查询站内信列表响应: status=[{}], body=[{}]", status, respBody);
if (status == HttpStatus.HTTP_UNAUTHORIZED) {
log.warn("认证失败,请检查 AccessToken 是否有效或已过期, body=[{}]", respBody);
return null;
}
if (!response.isOk() || StrUtil.isBlank(respBody)) {
log.warn("查询站内信列表响应异常: status=[{}], body=[{}]", status, respBody);
return null;
}
JSONObject json = JSONUtil.parseObj(respBody);
// 仅以 code=0 判定业务成功
Integer code = json.getInt("code");
if (code == null || code != 0) {
log.warn("查询站内信列表业务失败: code=[{}], msg=[{}], body=[{}]",
code, json.getStr("msg"), respBody);
return null;
}
JSONObject pageData = json.getJSONObject("data");
if (pageData == null) {
log.warn("响应中未提取到分页数据, body=[{}]", respBody);
return null;
}
log.info("查询站内信列表成功: current=[{}], size=[{}], total=[{}]",
current, size, pageData.getLong("total"));
return pageData;
} catch (Exception e) {
log.error("查询站内信列表接口异常", e);
return null;
}
}
/**
* 调用入口示例
*/
public static void main(String[] args) {
// 1) 先获取 AccessToken(任选一种登录方式)
String accessToken = OAuth2TokenIntegrationDemo
.getAccessTokenByIntegration("18377xxxxxxx69049");
// 2) 分页查询站内信列表(第1页,每页10条)
JSONObject pageData = getStationMessageList(accessToken, 1, 10);
if (pageData != null) {
log.info("站内信总条数: {}", pageData.getLong("total"));
log.info("当前页数据: {}", pageData.getJSONArray("records"));
}
}
}