first commit

This commit is contained in:
renjianbo
2025-12-29 15:20:51 +08:00
parent 4d40a14a51
commit bfe2af67c3
16 changed files with 1048 additions and 0 deletions

BIN
opush-server-sdk-1.1.0.jar Normal file

Binary file not shown.

85
pom.xml Normal file
View File

@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.oppo.push</groupId>
<artifactId>oppo-push-server</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>OPPO Push Server</name>
<description>OPPO推送服务测试后台</description>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-boot.version>2.7.0</spring-boot.version>
</properties>
<dependencies>
<!-- Spring Boot Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<!-- Spring Boot Configuration Processor -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring-boot.version}</version>
<optional>true</optional>
</dependency>
<!-- OPPO Push SDK -->
<dependency>
<groupId>com.oppo.push</groupId>
<artifactId>opush-server-sdk</artifactId>
<version>1.1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/opush-server-sdk-1.1.0.jar</systemPath>
</dependency>
<!-- HTTP Client -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
<!-- JSON处理 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>
<!-- Lombok (可选) -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,21 @@
package com.oppo.push;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* OPPO推送服务主应用
*/
@SpringBootApplication
public class OppoPushApplication {
public static void main(String[] args) {
SpringApplication.run(OppoPushApplication.class, args);
System.out.println("========================================");
System.out.println("OPPO推送服务已启动");
System.out.println("API地址: http://localhost:8080/api/push");
System.out.println("健康检查: http://localhost:8080/api/push/health");
System.out.println("========================================");
}
}

View File

@@ -0,0 +1,44 @@
package com.oppo.push.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* OPPO推送服务配置类
*/
@Data
@Configuration
@ConfigurationProperties(prefix = "oppo.push")
public class OppoPushConfig {
/**
* 应用Key
*/
private String appKey;
/**
* 应用密钥
*/
private String appSecret;
/**
* 主密钥
*/
private String masterSecret;
/**
* API地址
*/
private String apiUrl = "https://api.push.oppo.com";
/**
* 通讯与服务原私信频道ID
*/
private String channelIdIm = "previte_message";
/**
* 通讯与服务(原私信)频道名称
*/
private String channelNameIm = "消息推送";
}

View File

@@ -0,0 +1,75 @@
package com.oppo.push.controller;
import com.oppo.push.service.OppoPushService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
/**
* 推送测试控制器
*/
@Slf4j
@RestController
@RequestMapping("/api/push")
public class PushController {
@Autowired
private OppoPushService pushService;
/**
* 测试发送通讯与服务(原私信)类消息
*
* @param request 请求参数
* @return 推送结果
*/
@PostMapping("/send")
public Map<String, Object> sendMessage(@RequestBody Map<String, String> request) {
String targetValue = request.get("targetValue"); // registration_id或alias
String title = request.get("title");
String content = request.get("content");
String messageType = request.getOrDefault("messageType", "1"); // 1:通知栏消息, 2:透传消息
if (targetValue == null || title == null || content == null) {
Map<String, Object> error = new HashMap<>();
error.put("success", false);
error.put("message", "参数不完整需要targetValue、title、content");
return error;
}
return pushService.sendMessage(targetValue, title, content, Integer.parseInt(messageType));
}
/**
* 获取Access Token用于测试
*/
@GetMapping("/token")
public Map<String, Object> getToken() {
try {
String token = pushService.getAccessToken();
Map<String, Object> result = new HashMap<>();
result.put("success", true);
result.put("token", token);
return result;
} catch (Exception e) {
Map<String, Object> result = new HashMap<>();
result.put("success", false);
result.put("message", e.getMessage());
return result;
}
}
/**
* 健康检查
*/
@GetMapping("/health")
public Map<String, Object> health() {
Map<String, Object> result = new HashMap<>();
result.put("status", "ok");
result.put("service", "OPPO Push Server");
return result;
}
}

View File

@@ -0,0 +1,212 @@
package com.oppo.push.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.oppo.push.config.OppoPushConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
/**
* OPPO推送服务类
*/
@Slf4j
@Service
public class OppoPushService {
@Autowired
private OppoPushConfig config;
private String accessToken;
private long tokenExpireTime;
/**
* 获取Access Token
*/
public String getAccessToken() {
// 如果token未过期直接返回
if (accessToken != null && System.currentTimeMillis() < tokenExpireTime) {
return accessToken;
}
try {
String url = config.getApiUrl() + "/v1/auth";
long timestamp = System.currentTimeMillis();
Map<String, Object> params = new HashMap<>();
params.put("app_key", config.getAppKey());
params.put("timestamp", timestamp);
params.put("sign", generateSign(config.getAppKey(), timestamp, config.getMasterSecret()));
String response = sendPostRequest(url, JSON.toJSONString(params));
JSONObject jsonResponse = JSON.parseObject(response);
if (jsonResponse.getInteger("code") == 0) {
accessToken = jsonResponse.getString("data");
// token有效期通常为24小时这里设置为23小时提前刷新
tokenExpireTime = System.currentTimeMillis() + 23 * 60 * 60 * 1000;
log.info("获取Access Token成功: {}", accessToken);
return accessToken;
} else {
log.error("获取Access Token失败: {}", response);
throw new RuntimeException("获取Access Token失败: " + jsonResponse.getString("message"));
}
} catch (Exception e) {
log.error("获取Access Token异常", e);
throw new RuntimeException("获取Access Token异常", e);
}
}
/**
* 发送通讯与服务(原私信)类消息
*
* @param targetValue 目标值可以是token、registration_id等
* @param title 消息标题
* @param content 消息内容
* @param messageType 消息类型1:通知栏消息, 2:透传消息)
* @return 推送结果
*/
public Map<String, Object> sendMessage(String targetValue, String title, String content, int messageType) {
try {
String token = getAccessToken();
String url = config.getApiUrl() + "/v1/message/notification/single";
// 构建消息体
Map<String, Object> message = new HashMap<>();
message.put("target_type", 1); // 1:registration_id, 2:alias, 3:tag
message.put("target_value", targetValue);
// 通知栏消息参数
Map<String, Object> notification = new HashMap<>();
notification.put("title", title);
notification.put("content", content);
notification.put("click_action_type", 1); // 1:打开应用首页, 2:打开应用内页, 3:打开网页, 4:打开应用内页(Intent)
notification.put("click_action_type_value", "");
// 通讯与服务(原私信)类消息特殊参数
// 根据OPPO官方文档通讯与服务类消息需要设置channel_id和channel_name
notification.put("channel_id", config.getChannelIdIm()); // 通讯与服务频道ID: previte_message
notification.put("channel_name", config.getChannelNameIm()); // 频道名称: 消息推送
// extra参数可选用于传递额外信息
Map<String, Object> extra = new HashMap<>();
extra.put("message_type", "chat"); // 标识为私信类消息
notification.put("extra", extra);
message.put("notification", notification);
// 请求头
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json;charset=UTF-8");
headers.put("auth_token", token);
String response = sendPostRequestWithHeaders(url, JSON.toJSONString(message), headers);
JSONObject jsonResponse = JSON.parseObject(response);
Map<String, Object> result = new HashMap<>();
result.put("success", jsonResponse.getInteger("code") == 0);
result.put("code", jsonResponse.getInteger("code"));
result.put("message", jsonResponse.getString("message"));
result.put("data", jsonResponse.get("data"));
log.info("发送消息结果: {}", result);
return result;
} catch (Exception e) {
log.error("发送消息异常", e);
Map<String, Object> result = new HashMap<>();
result.put("success", false);
result.put("message", "发送消息异常: " + e.getMessage());
return result;
}
}
/**
* 发送单点推送使用SDK方式
*/
public Map<String, Object> sendSinglePush(String registrationId, String title, String content) {
try {
// 这里使用OPPO SDK的方式发送
// 注意需要根据实际的SDK API进行调整
return sendMessage(registrationId, title, content, 1);
} catch (Exception e) {
log.error("发送单点推送异常", e);
Map<String, Object> result = new HashMap<>();
result.put("success", false);
result.put("message", "发送单点推送异常: " + e.getMessage());
return result;
}
}
/**
* 生成签名
* 签名算法MD5(app_key + timestamp + master_secret)
*/
private String generateSign(String appKey, long timestamp, String masterSecret) {
try {
String signStr = appKey + timestamp + masterSecret;
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
byte[] bytes = md.digest(signStr.getBytes(StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
sb.append(String.format("%02x", b));
}
return sb.toString();
} catch (Exception e) {
throw new RuntimeException("生成签名失败", e);
}
}
/**
* 发送POST请求
*/
private String sendPostRequest(String url, String jsonBody) throws Exception {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
httpPost.setEntity(new StringEntity(jsonBody, StandardCharsets.UTF_8));
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
HttpEntity entity = response.getEntity();
return EntityUtils.toString(entity, StandardCharsets.UTF_8);
} finally {
httpClient.close();
}
}
/**
* 发送带自定义请求头的POST请求
*/
private String sendPostRequestWithHeaders(String url, String jsonBody, Map<String, String> headers) throws Exception {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
// 设置默认请求头
httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
// 设置自定义请求头
if (headers != null) {
headers.forEach(httpPost::setHeader);
}
httpPost.setEntity(new StringEntity(jsonBody, StandardCharsets.UTF_8));
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
HttpEntity entity = response.getEntity();
return EntityUtils.toString(entity, StandardCharsets.UTF_8);
} finally {
httpClient.close();
}
}
}

View File

@@ -0,0 +1,16 @@
# OPPO推送服务配置
# 请在OPPO开放平台获取以下信息https://open.oppomobile.com
oppo.push.appKey=bb0819c889ae40cd8bde5a8ad4e670fe
oppo.push.appSecret=9b5a0e6d560e406dbb70fbb4e0e38098
oppo.push.masterSecret=9b5a0e6d560e406dbb70fbb4e0e38098
# 通讯与服务(原私信)频道配置
oppo.push.channel.id.im=previte_message
oppo.push.channel.name.im=消息推送
# 推送服务地址
oppo.push.api.url=https://api.push.oppo.com
# 服务器端口
server.port=8080

View File

@@ -0,0 +1,48 @@
{
"groups": [
{
"name": "oppo.push",
"type": "com.oppo.push.config.OppoPushConfig",
"sourceType": "com.oppo.push.config.OppoPushConfig"
}
],
"properties": [
{
"name": "oppo.push.api-url",
"type": "java.lang.String",
"description": "API地址",
"sourceType": "com.oppo.push.config.OppoPushConfig"
},
{
"name": "oppo.push.app-key",
"type": "java.lang.String",
"description": "应用Key",
"sourceType": "com.oppo.push.config.OppoPushConfig"
},
{
"name": "oppo.push.app-secret",
"type": "java.lang.String",
"description": "应用密钥",
"sourceType": "com.oppo.push.config.OppoPushConfig"
},
{
"name": "oppo.push.channel-id-im",
"type": "java.lang.String",
"description": "通讯与服务原私信频道ID",
"sourceType": "com.oppo.push.config.OppoPushConfig"
},
{
"name": "oppo.push.channel-name-im",
"type": "java.lang.String",
"description": "通讯与服务(原私信)频道名称",
"sourceType": "com.oppo.push.config.OppoPushConfig"
},
{
"name": "oppo.push.master-secret",
"type": "java.lang.String",
"description": "主密钥",
"sourceType": "com.oppo.push.config.OppoPushConfig"
}
],
"hints": []
}

View File

@@ -0,0 +1,16 @@
# OPPO推送服务配置
# 请在OPPO开放平台获取以下信息https://open.oppomobile.com
oppo.push.appKey=bb0819c889ae40cd8bde5a8ad4e670fe
oppo.push.appSecret=9b5a0e6d560e406dbb70fbb4e0e38098
oppo.push.masterSecret=9b5a0e6d560e406dbb70fbb4e0e38098
# 通讯与服务(原私信)频道配置
oppo.push.channel.id.im=previte_message
oppo.push.channel.name.im=消息推送
# 推送服务地址
oppo.push.api.url=https://api.push.oppo.com
# 服务器端口
server.port=8080

Binary file not shown.

7
test-request.json Normal file
View File

@@ -0,0 +1,7 @@
{
"targetValue": "your_registration_id_here",
"title": "测试私信消息",
"content": "这是一条通讯与服务(原私信)类消息的测试内容",
"messageType": "1"
}

388
调测使用说明.txt Normal file
View File

@@ -0,0 +1,388 @@
================================================================================
OPPO推送服务 - 调测使用说明
================================================================================
一、环境准备
================================================================================
1. 系统要求
- JDK 1.8 或更高版本
- Maven 3.6 或更高版本
- Windows/Linux/Mac 操作系统
2. 验证环境
- 打开命令行执行java -version
- 打开命令行执行mvn -version
- 确保两个命令都能正常显示版本信息
3. 项目文件检查
确保以下文件存在:
- pom.xmlMaven配置文件
- opush-server-sdk-1.1.0.jarOPPO推送SDK
- src/main/resources/application.properties配置文件
- src/main/java/com/oppo/push/(源代码目录)
二、配置说明
================================================================================
1. 配置文件位置
src/main/resources/application.properties
2. 已配置的参数
- AppKey: bb0819c889ae40cd8bde5a8ad4e670fe
- AppSecret: 9b5a0e6d560e406dbb70fbb4e0e38098
- MasterSecret: 9b5a0e6d560e406dbb70fbb4e0e38098默认与AppSecret相同
- 频道ID: previte_message
- 频道名称: 消息推送
- 服务端口: 8080
3. 配置修改(如需要)
如果您的MasterSecret与AppSecret不同请修改配置文件中的
oppo.push.masterSecret=您的实际MasterSecret值
三、启动服务
================================================================================
方式一使用Maven直接运行推荐
----------------------------------------
1. 打开命令行CMD或PowerShell
2. 进入项目目录cd d:\oppo_push_server
3. 执行启动命令mvn spring-boot:run
4. 等待启动完成,看到以下信息表示启动成功:
========================================
OPPO推送服务已启动
API地址: http://localhost:8080/api/push
健康检查: http://localhost:8080/api/push/health
========================================
方式二:打包后运行
----------------------------------------
1. 打包项目mvn clean package
2. 运行jar包java -jar target/oppo-push-server-1.0.0.jar
3. 启动成功后同上
四、API接口说明
================================================================================
1. 健康检查接口
- 请求方式GET
- 请求地址http://localhost:8080/api/push/health
- 功能说明:检查服务是否正常运行
- 返回示例:
{
"status": "ok",
"service": "OPPO Push Server"
}
2. 获取Access Token接口
- 请求方式GET
- 请求地址http://localhost:8080/api/push/token
- 功能说明获取OPPO推送服务的访问令牌
- 返回示例(成功):
{
"success": true,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
- 返回示例(失败):
{
"success": false,
"message": "获取Access Token失败: 错误信息"
}
3. 发送通讯与服务(原私信)类消息接口
- 请求方式POST
- 请求地址http://localhost:8080/api/push/send
- 请求头Content-Type: application/json
- 请求体JSON格式
{
"targetValue": "设备的registration_id或alias",
"title": "消息标题",
"content": "消息内容",
"messageType": "1"
}
- 参数说明:
* targetValue必填目标设备的标识
- 可以是registration_id设备注册ID
- 可以是alias别名
- 可以是tag标签
* title必填消息标题
* content必填消息内容
* messageType可选消息类型
- "1":通知栏消息(默认)
- "2":透传消息
- 返回示例(成功):
{
"success": true,
"code": 0,
"message": "success",
"data": {
"messageId": "xxx",
"taskId": "xxx"
}
}
- 返回示例(失败):
{
"success": false,
"code": 1001,
"message": "错误信息",
"data": null
}
五、测试步骤
================================================================================
步骤1启动服务
----------------------------------------
执行mvn spring-boot:run
等待服务启动完成
步骤2健康检查
----------------------------------------
打开浏览器访问http://localhost:8080/api/push/health
或使用curl命令
curl http://localhost:8080/api/push/health
预期结果:返回 {"status":"ok","service":"OPPO Push Server"}
步骤3获取Token测试认证
----------------------------------------
使用curl命令
curl http://localhost:8080/api/push/token
或使用浏览器访问http://localhost:8080/api/push/token
预期结果返回包含token的JSONsuccess为true
步骤4准备测试数据
----------------------------------------
1. 获取目标设备的registration_id
- 在您的移动应用中集成OPPO推送SDK
- 应用启动后SDK会返回registration_id
- 记录下这个registration_id用于测试
2. 修改test-request.json文件
将文件中的 "your_registration_id_here" 替换为实际的registration_id
步骤5发送测试消息
----------------------------------------
使用curl命令Windows PowerShell
curl -X POST http://localhost:8080/api/push/send `
-H "Content-Type: application/json" `
-d @test-request.json
使用curl命令Linux/Mac
curl -X POST http://localhost:8080/api/push/send \
-H "Content-Type: application/json" \
-d @test-request.json
或使用Postman
1. 创建POST请求
2. URL: http://localhost:8080/api/push/send
3. Headers: Content-Type = application/json
4. Body选择raw格式选择JSON
5. 输入以下内容:
{
"targetValue": "您的registration_id",
"title": "测试私信消息",
"content": "这是一条通讯与服务(原私信)类消息的测试内容",
"messageType": "1"
}
6. 点击Send发送
预期结果:
- 返回success为true
- 移动设备收到推送通知
- 通知显示在"消息推送"频道中
六、使用Postman测试推荐
================================================================================
1. 导入请求集合
- 打开Postman
- 创建新的CollectionOPPO推送测试
- 添加以下三个请求:
2. 健康检查请求
- 方法GET
- URLhttp://localhost:8080/api/push/health
- 点击Send应该返回成功状态
3. 获取Token请求
- 方法GET
- URLhttp://localhost:8080/api/push/token
- 点击Send应该返回token
4. 发送消息请求
- 方法POST
- URLhttp://localhost:8080/api/push/send
- Headers
Key: Content-Type
Value: application/json
- Body选择raw格式JSON
{
"targetValue": "替换为实际的registration_id",
"title": "测试标题",
"content": "测试内容",
"messageType": "1"
}
- 点击Send发送
七、常见问题排查
================================================================================
问题1服务启动失败
----------------------------------------
可能原因:
- 端口8080被占用
- JDK版本不兼容
- Maven依赖下载失败
解决方法:
1. 检查端口占用netstat -ano | findstr :8080
2. 修改端口在application.properties中修改server.port=8081
3. 检查JDK版本java -version需要1.8+
4. 清理Maven缓存mvn clean
问题2获取Token失败
----------------------------------------
可能原因:
- AppKey或MasterSecret配置错误
- 网络连接问题
- OPPO服务端异常
解决方法:
1. 检查配置文件中的AppKey和MasterSecret是否正确
2. 检查网络连接是否正常
3. 查看控制台日志,确认具体错误信息
4. 确认在OPPO开放平台已开通推送服务
问题3发送消息失败
----------------------------------------
可能原因:
- Token过期或无效
- targetValueregistration_id无效
- 消息格式错误
- 设备未在线
解决方法:
1. 重新获取Token访问 /api/push/token 接口
2. 确认registration_id是否正确
3. 检查请求体JSON格式是否正确
4. 确认目标设备已连接网络且应用在运行
5. 查看控制台日志获取详细错误信息
问题4设备收不到推送
----------------------------------------
可能原因:
- 设备未正确集成OPPO推送SDK
- 应用未获得通知权限
- 设备网络问题
- 频道配置不正确
解决方法:
1. 确认移动应用已正确集成OPPO推送SDK
2. 检查应用的通知权限是否开启
3. 确认设备网络连接正常
4. 检查频道ID配置是否为"previte_message"
5. 在OPPO开放平台查看推送统计确认消息是否已发送
问题5编译错误
----------------------------------------
可能原因:
- 缺少依赖
- 代码语法错误
解决方法:
1. 执行mvn clean install
2. 检查IDE是否显示错误
3. 确认opush-server-sdk-1.1.0.jar文件存在
八、日志查看
================================================================================
1. 控制台日志
服务启动后,所有日志会输出到控制台,包括:
- 服务启动信息
- Token获取日志
- 消息发送日志
- 错误信息
2. 关键日志信息
- "获取Access Token成功":表示认证成功
- "发送消息结果":显示消息发送的详细结果
- "获取Access Token失败":表示认证失败,需要检查配置
- "发送消息异常":表示发送失败,查看具体错误信息
九、调试技巧
================================================================================
1. 使用健康检查接口确认服务正常运行
2. 先测试获取Token确认认证配置正确
3. 使用Postman等工具可以更方便地测试和查看响应
4. 查看控制台日志,了解详细的执行过程
5. 如果发送失败,先检查:
- Token是否有效
- registration_id是否正确
- 请求格式是否正确
6. 建议测试流程:
健康检查 → 获取Token → 发送消息
十、注意事项
================================================================================
1. Token会自动缓存有效期约24小时无需频繁获取
2. 确保在OPPO开放平台已正确配置应用信息
3. registration_id需要从移动应用端获取不能随意填写
4. 通讯与服务类消息会自动使用配置的频道IDprevite_message
5. 测试时建议使用真实的设备registration_id
6. 如果MasterSecret与AppSecret不同务必更新配置文件
7. 生产环境建议将敏感信息AppKey、Secret等配置为环境变量
8. 通讯与服务类消息说明:
- 根据OPPO官方文档https://open.oppomobile.com/documentation/page/info?id=13189
- 必须设置 channel_id 为 "previte_message"
- 必须设置 channel_name 为 "消息推送"
- 这些参数已在代码中自动配置,无需手动设置
- 消息会显示在OPPO手机的"消息推送"频道中
十一、技术支持
================================================================================
1. OPPO推送服务文档
- 通讯与服务类消息文档https://open.oppomobile.com/documentation/page/info?id=13189
- 推送服务总文档https://open.oppomobile.com/documentation/page/info?id=11233
2. 查看项目文档
- README.md项目总体说明
- 通讯与服务类消息说明.md通讯与服务类消息详细说明
3. 查看控制台日志获取详细错误信息
4. 检查OPPO开放平台的推送统计确认消息发送状态
================================================================================
祝您测试顺利!
================================================================================

View File

@@ -0,0 +1,136 @@
# 通讯与服务类消息发送说明
## 概述
本文档说明如何使用本后台服务发送**通讯与服务(原私信)类消息**。
根据 [OPPO推送服务官方文档](https://open.oppomobile.com/documentation/page/info?id=13189),通讯与服务类消息需要特殊的参数配置。
## 关键配置参数
### 1. 频道IDchannel_id
- **值**: `previte_message`
- **位置**: `src/main/resources/application.properties`
- **配置项**: `oppo.push.channel.id.im=previte_message`
### 2. 频道名称channel_name
- **值**: `消息推送`
- **位置**: `src/main/resources/application.properties`
- **配置项**: `oppo.push.channel.name.im=消息推送`
## 代码实现
`OppoPushService.java` 中,发送消息时会自动设置以下参数:
```java
// 通讯与服务(原私信)类消息特殊参数
notification.put("channel_id", config.getChannelIdIm()); // previte_message
notification.put("channel_name", config.getChannelNameIm()); // 消息推送
// extra参数可选
Map<String, Object> extra = new HashMap<>();
extra.put("message_type", "chat"); // 标识为私信类消息
notification.put("extra", extra);
```
## 消息体结构
发送通讯与服务类消息时,完整的消息体结构如下:
```json
{
"target_type": 1,
"target_value": "设备的registration_id",
"notification": {
"title": "消息标题",
"content": "消息内容",
"click_action_type": 1,
"click_action_type_value": "",
"channel_id": "previte_message",
"channel_name": "消息推送",
"extra": {
"message_type": "chat"
}
}
}
```
## 测试步骤
### 1. 确保配置正确
检查 `application.properties` 文件:
```properties
oppo.push.channel.id.im=previte_message
oppo.push.channel.name.im=消息推送
```
### 2. 启动服务
```bash
mvn spring-boot:run
```
### 3. 发送测试消息
使用 curl 命令:
```bash
curl -X POST http://localhost:8080/api/push/send \
-H "Content-Type: application/json" \
-d '{
"targetValue": "您的registration_id",
"title": "测试私信",
"content": "这是一条通讯与服务类消息",
"messageType": "1"
}'
```
### 4. 验证结果
- 检查API返回`success` 应为 `true`
- 检查设备消息应出现在OPPO手机的"消息推送"频道中
- 检查日志:查看控制台输出的详细日志
## 注意事项
1. **频道ID必须正确**`channel_id` 必须设置为 `previte_message`,否则消息不会被识别为普通通知
2. **频道名称**`channel_name` 设置为 `消息推送`这是OPPO系统识别的标准名称
3. **设备端配置**确保移动应用已正确集成OPPO推送SDK并且应用已获得通知权限
4. **registration_id**必须使用真实的设备registration_id不能随意填写
5. **消息分类**:通过设置 `channel_id``previte_message`消息会被OPPO系统自动分类为"通讯与服务"类消息
## 常见问题
### Q1: 消息发送成功但设备收不到?
**A**: 检查以下几点:
- 设备是否在线
- 应用是否已获得通知权限
- registration_id是否正确
- 应用是否已正确集成OPPO推送SDK
### Q2: 消息收到了但不是通讯与服务类?
**A**: 检查:
- `channel_id` 是否正确设置为 `previte_message`
- 查看日志确认消息体中的参数是否正确
### Q3: 如何确认消息类型?
**A**:
- 在OPPO手机上通讯与服务类消息会显示在"消息推送"频道中
- 可以通过OPPO开放平台的推送统计查看消息分类
## 相关文档
- [OPPO推送服务文档 - 通讯与服务类消息](https://open.oppomobile.com/documentation/page/info?id=13189)
- [OPPO开放平台](https://open.oppomobile.com)
## 技术支持
如有问题,请:
1. 查看控制台日志获取详细错误信息
2. 检查OPPO开放平台的推送统计
3. 参考OPPO官方文档