Files
oppo_push_server/README.md
2025-12-29 15:20:00 +08:00

150 lines
3.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# OPPO推送服务测试后台
这是一个用于测试OPPO推送服务特别是"通讯与服务(原私信)"类消息的后台服务。
## 功能特性
- ✅ 获取OPPO推送服务的Access Token
- ✅ 发送单点推送消息
- ✅ 支持发送通讯与服务(原私信)类消息
- ✅ 提供RESTful API接口方便测试和调试
## 环境要求
- JDK 1.8+
- Maven 3.6+
## 配置说明
**配置已完成** - 已在 `src/main/resources/application.properties` 中配置:
```properties
oppo.push.appKey=bb0819c889ae40cd8bde5a8ad4e670fe
oppo.push.appSecret=9b5a0e6d560e406dbb70fbb4e0e38098
oppo.push.channel.id.im=previte_message
oppo.push.channel.name.im=消息推送
```
**注意**:如果您的 MasterSecret 与 AppSecret 不同,请更新配置文件中的 `oppo.push.masterSecret` 值。
## 运行方式
### 方式一使用Maven运行
```bash
mvn spring-boot:run
```
### 方式二:打包后运行
```bash
# 打包
mvn clean package
# 运行
java -jar target/oppo-push-server-1.0.0.jar
```
## API接口
### 1. 健康检查
```
GET http://localhost:8080/api/push/health
```
### 2. 获取Access Token
```
GET http://localhost:8080/api/push/token
```
### 3. 发送通讯与服务(原私信)类消息
```
POST http://localhost:8080/api/push/send
Content-Type: application/json
{
"targetValue": "registration_id或alias",
"title": "消息标题",
"content": "消息内容",
"messageType": "1"
}
```
**参数说明:**
- `targetValue`: 目标值可以是registration_id、alias或tag
- `title`: 消息标题
- `content`: 消息内容
- `messageType`: 消息类型1:通知栏消息, 2:透传消息默认为1
## 快速测试
### 1. 启动服务
```bash
mvn spring-boot:run
```
### 2. 使用curl测试
```bash
# 1. 健康检查
curl http://localhost:8080/api/push/health
# 2. 获取Token测试认证是否成功
curl http://localhost:8080/api/push/token
# 3. 发送通讯与服务(原私信)类消息
curl -X POST http://localhost:8080/api/push/send \
-H "Content-Type: application/json" \
-d @test-request.json
```
**注意**:发送消息前,请先修改 `test-request.json` 文件中的 `targetValue` 为实际的 registration_id。
### 使用Postman测试
1. 创建新的POST请求
2. URL: `http://localhost:8080/api/push/send`
3. Headers: `Content-Type: application/json`
4. Body (raw JSON):
```json
{
"targetValue": "your_registration_id",
"title": "测试标题",
"content": "这是一条测试消息",
"messageType": "1"
}
```
## 通讯与服务(原私信)类消息说明
根据OPPO推送服务文档通讯与服务类消息需要设置特殊的参数
- `message_type`: 设置为 "chat" 标识为私信类消息
- `channel_id`: 私信频道ID已配置为 `previte_message`
- `channel_name`: 频道名称,已配置为 `消息推送`
这些参数已经在 `OppoPushService` 中自动设置使用配置文件中定义的频道ID和名称。
## 相关文档
- [OPPO推送服务文档](https://open.oppomobile.com/documentation/page/info?id=11233)
- [OPPO开放平台](https://open.oppomobile.com)
## 注意事项
1. 确保在OPPO开放平台已开通推送服务
2. 确保AppKey、AppSecret和MasterSecret配置正确
3. 确保目标设备的registration_id或alias有效
4. Access Token会自动缓存有效期约24小时
## 故障排查
1. **获取Token失败**检查AppKey和MasterSecret是否正确
2. **发送消息失败**检查targetValue是否有效以及网络连接是否正常
3. **消息未收到**检查设备是否在线以及应用是否已正确集成OPPO推送SDK