后台api成功推送消息
This commit is contained in:
298
api成功推送消息.txt
Normal file
298
api成功推送消息.txt
Normal file
@@ -0,0 +1,298 @@
|
||||
OPPO推送服务 - API成功推送消息文档
|
||||
==========================================
|
||||
|
||||
一、服务配置信息
|
||||
------------------------------------------
|
||||
包名: com.xunpaisoft.social
|
||||
AppId: 32150237
|
||||
AppKey: bb0819c889ae40cd8bde5a8ad4e670fe
|
||||
AppSecret: 9b5a0e6d560e406dbb70fbb4e0e38098
|
||||
AppServerSecret: 2d8b4e922d60453d987f0d09de6eb4a6
|
||||
|
||||
服务地址: http://localhost:8080/android/push
|
||||
请求方法: POST
|
||||
Content-Type: application/json;charset=UTF-8
|
||||
|
||||
|
||||
二、API接口说明
|
||||
------------------------------------------
|
||||
接口地址: http://localhost:8080/android/push
|
||||
请求方法: POST
|
||||
请求头: Content-Type: application/json;charset=UTF-8
|
||||
|
||||
|
||||
三、请求参数说明
|
||||
------------------------------------------
|
||||
所有参数都在HTTP body中以JSON格式传递:
|
||||
|
||||
参数名 类型 必填 说明
|
||||
------------------------------------------------------------------
|
||||
pushType int 是 推送类型,OPPO推送固定为 5
|
||||
pushMessageType int 是 消息类型,0表示普通消息
|
||||
packageName String 是 应用包名,固定为: com.xunpaisoft.social
|
||||
deviceToken String 是 OPPO设备的registration_id
|
||||
pushContent String 是 推送消息内容
|
||||
sender String 否 发送者ID
|
||||
senderName String 否 发送者名称(会作为推送标题显示)
|
||||
target String 否 目标ID
|
||||
targetName String 否 目标名称
|
||||
convType int 否 会话类型,0表示单聊
|
||||
line int 否 消息行,0表示普通消息
|
||||
cntType int 否 内容类型,1表示文本
|
||||
serverTime long 否 服务器时间戳(毫秒)
|
||||
unReceivedMsg int 否 未接收消息数
|
||||
mentionedType int 否 提及类型,0表示未提及
|
||||
isHiddenDetail boolean 否 是否隐藏详情,false表示显示详情
|
||||
language String 否 语言,zh表示中文
|
||||
messageId long 否 消息ID(建议使用时间戳)
|
||||
republish boolean 否 是否重新发布,false表示新消息
|
||||
existBadgeNumber int 否 已存在的角标数字
|
||||
|
||||
|
||||
四、成功推送示例
|
||||
------------------------------------------
|
||||
|
||||
示例1: 使用curl命令推送消息
|
||||
|
||||
curl -X POST http://localhost:8080/android/push \
|
||||
-H "Content-Type: application/json;charset=UTF-8" \
|
||||
-d '{
|
||||
"pushType": 5,
|
||||
"pushMessageType": 0,
|
||||
"packageName": "com.xunpaisoft.social",
|
||||
"deviceToken": "OPPO_CN_95ac9afc103d70bb26441ec0cbb06b97",
|
||||
"pushContent": "我是api",
|
||||
"sender": "api_user",
|
||||
"senderName": "知你",
|
||||
"target": "test_target",
|
||||
"targetName": "测试目标",
|
||||
"convType": 0,
|
||||
"line": 0,
|
||||
"cntType": 1,
|
||||
"serverTime": 1767146875000,
|
||||
"unReceivedMsg": 1,
|
||||
"mentionedType": 0,
|
||||
"isHiddenDetail": false,
|
||||
"language": "zh",
|
||||
"messageId": 1767146875,
|
||||
"republish": false,
|
||||
"existBadgeNumber": 0
|
||||
}'
|
||||
|
||||
|
||||
示例2: 使用测试脚本推送
|
||||
|
||||
cd /home/renjianbo/push/push_server
|
||||
./test_push_8080.sh OPPO_CN_95ac9afc103d70bb26441ec0cbb06b97
|
||||
|
||||
|
||||
示例3: 使用Python发送推送
|
||||
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
|
||||
url = "http://localhost:8080/android/push"
|
||||
headers = {
|
||||
"Content-Type": "application/json;charset=UTF-8"
|
||||
}
|
||||
|
||||
data = {
|
||||
"pushType": 5,
|
||||
"pushMessageType": 0,
|
||||
"packageName": "com.xunpaisoft.social",
|
||||
"deviceToken": "OPPO_CN_95ac9afc103d70bb26441ec0cbb06b97",
|
||||
"pushContent": "我是api",
|
||||
"sender": "api_user",
|
||||
"senderName": "知你",
|
||||
"target": "test_target",
|
||||
"targetName": "测试目标",
|
||||
"convType": 0,
|
||||
"line": 0,
|
||||
"cntType": 1,
|
||||
"serverTime": int(time.time() * 1000),
|
||||
"unReceivedMsg": 1,
|
||||
"mentionedType": 0,
|
||||
"isHiddenDetail": False,
|
||||
"language": "zh",
|
||||
"messageId": int(time.time()),
|
||||
"republish": False,
|
||||
"existBadgeNumber": 0
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
print(response.text)
|
||||
|
||||
|
||||
示例4: 使用Java发送推送
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.io.OutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import com.google.gson.Gson;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class OppoPushTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String url = "http://localhost:8080/android/push";
|
||||
URL obj = new URL(url);
|
||||
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||||
|
||||
con.setRequestMethod("POST");
|
||||
con.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
|
||||
con.setDoOutput(true);
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("pushType", 5);
|
||||
data.put("pushMessageType", 0);
|
||||
data.put("packageName", "com.xunpaisoft.social");
|
||||
data.put("deviceToken", "OPPO_CN_95ac9afc103d70bb26441ec0cbb06b97");
|
||||
data.put("pushContent", "我是api");
|
||||
data.put("sender", "api_user");
|
||||
data.put("senderName", "知你");
|
||||
data.put("target", "test_target");
|
||||
data.put("targetName", "测试目标");
|
||||
data.put("convType", 0);
|
||||
data.put("line", 0);
|
||||
data.put("cntType", 1);
|
||||
data.put("serverTime", System.currentTimeMillis());
|
||||
data.put("unReceivedMsg", 1);
|
||||
data.put("mentionedType", 0);
|
||||
data.put("isHiddenDetail", false);
|
||||
data.put("language", "zh");
|
||||
data.put("messageId", System.currentTimeMillis() / 1000);
|
||||
data.put("republish", false);
|
||||
data.put("existBadgeNumber", 0);
|
||||
|
||||
String json = new Gson().toJson(data);
|
||||
|
||||
try (OutputStream os = con.getOutputStream()) {
|
||||
byte[] input = json.getBytes("utf-8");
|
||||
os.write(input, 0, input.length);
|
||||
}
|
||||
|
||||
int responseCode = con.getResponseCode();
|
||||
System.out.println("Response Code: " + responseCode);
|
||||
|
||||
try (BufferedReader br = new BufferedReader(
|
||||
new InputStreamReader(con.getInputStream(), "utf-8"))) {
|
||||
StringBuilder response = new StringBuilder();
|
||||
String responseLine;
|
||||
while ((responseLine = br.readLine()) != null) {
|
||||
response.append(responseLine.trim());
|
||||
}
|
||||
System.out.println("Response: " + response.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
五、成功响应示例
|
||||
------------------------------------------
|
||||
HTTP状态码: 200
|
||||
|
||||
响应内容: ok
|
||||
|
||||
服务器日志示例:
|
||||
Server response: MessageId: 32150237-1-1-6954857b816b510175dc87a7
|
||||
ErrorCode: ReturnCode{code=0, message='Success'}
|
||||
Reason: OK
|
||||
|
||||
|
||||
六、重要参数说明
|
||||
------------------------------------------
|
||||
|
||||
1. pushType: 必须设置为 5,表示OPPO推送类型
|
||||
|
||||
2. deviceToken: OPPO设备的registration_id
|
||||
- 格式: OPPO_CN_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
- 需要从OPPO手机应用中获取
|
||||
- 每个设备有唯一的registration_id
|
||||
|
||||
3. senderName: 推送标题
|
||||
- 会显示在推送通知的标题位置
|
||||
- 例如: "知你"
|
||||
|
||||
4. pushContent: 推送内容
|
||||
- 会显示在推送通知的内容位置
|
||||
- 例如: "我是api"
|
||||
- 内容长度建议不超过200字符
|
||||
|
||||
5. packageName: 必须与配置的包名一致
|
||||
- 固定值: com.xunpaisoft.social
|
||||
|
||||
6. serverTime: 服务器时间戳(毫秒)
|
||||
- 可以使用: System.currentTimeMillis() (Java)
|
||||
- 或: int(time.time() * 1000) (Python)
|
||||
- 或: $(date +%s)000 (Shell)
|
||||
|
||||
7. messageId: 消息ID
|
||||
- 建议使用时间戳
|
||||
- 用于消息去重
|
||||
|
||||
|
||||
七、测试验证
|
||||
------------------------------------------
|
||||
|
||||
成功测试记录:
|
||||
- 测试时间: 2025-12-31 10:07:55
|
||||
- 推送标题: 知你
|
||||
- 推送内容: 我是api
|
||||
- MessageId: 32150237-1-1-6954857b816b510175dc87a7
|
||||
- 状态: Success (code=0)
|
||||
- 设备Token: OPPO_CN_95ac9afc103d70bb26441ec0cbb06b97
|
||||
- 手机接收: ✓ 已成功收到推送通知
|
||||
|
||||
|
||||
八、常见问题
|
||||
------------------------------------------
|
||||
|
||||
1. 推送失败,返回错误
|
||||
- 检查deviceToken是否正确
|
||||
- 检查packageName是否匹配
|
||||
- 检查服务是否正常运行在8080端口
|
||||
- 查看服务器日志: tail -f push.log
|
||||
|
||||
2. 手机未收到推送
|
||||
- 检查手机网络连接
|
||||
- 检查应用推送权限设置
|
||||
- 检查应用是否在后台运行
|
||||
- 检查OPPO手机的通知设置
|
||||
|
||||
3. 服务启动失败
|
||||
- 检查端口8080是否被占用
|
||||
- 检查config目录下的配置文件是否正确
|
||||
- 查看日志文件了解详细错误信息
|
||||
|
||||
|
||||
九、服务管理
|
||||
------------------------------------------
|
||||
|
||||
启动服务:
|
||||
cd /home/renjianbo/push/push_server
|
||||
nohup java -jar ../push_server-master/target/push-0.1.2.jar > push.log 2>&1 &
|
||||
|
||||
停止服务:
|
||||
pkill -f "push-0.1.2.jar"
|
||||
|
||||
查看日志:
|
||||
tail -f push.log
|
||||
|
||||
检查服务状态:
|
||||
netstat -tlnp | grep 8080
|
||||
|
||||
|
||||
十、配置文件位置
|
||||
------------------------------------------
|
||||
配置文件: /home/renjianbo/push/push_server/config/oppo.properties
|
||||
服务端口: /home/renjianbo/push/push_server/config/application.properties
|
||||
测试脚本: /home/renjianbo/push/push_server/test_push_8080.sh
|
||||
|
||||
|
||||
==========================================
|
||||
文档生成时间: 2025-12-31
|
||||
测试状态: ✓ 已成功验证推送功能
|
||||
|
||||
8
push.log
8
push.log
@@ -121,3 +121,11 @@ Caused by: java.security.InvalidKeyException: IOException : null
|
||||
2025-12-31 09:59:22.389 INFO 24833 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 21 ms
|
||||
2025-12-31 09:59:22.520 INFO 24833 --- [nio-8080-exec-1] c.w.push.android.AndroidPushServiceImpl : Android push {"sender":"test_user","senderName":"测试用户","convType":0,"target":"test_target","targetName":"测试目标","line":0,"cntType":1,"serverTime":1767146362000,"pushMessageType":0,"pushType":5,"pushContent":"这是一条测试推送消息 - 2025-12-31 09:59:22","unReceivedMsg":1,"mentionedType":0,"packageName":"com.xunpaisoft.social","deviceToken":"OPPO_CN_95ac9afc103d70bb26441ec0cbb06b97","isHiddenDetail":false,"language":"zh","messageId":1767146362,"callStartUid":0,"republish":false,"existBadgeNumber":0}
|
||||
2025-12-31 09:59:22.626 INFO 24833 --- [pool-2-thread-1] c.w.push.android.oppo.OppoPush : Server response: MessageId: 32150237-1-1-6954837a1acc0c0174ca3d27 ErrorCode: ReturnCode{code=0, message='Success'} Reason: OK
|
||||
2025-12-31 10:01:28.214 INFO 24833 --- [nio-8080-exec-2] c.w.push.android.AndroidPushServiceImpl : Android push {"sender":"test_user","senderName":"测试用户","convType":0,"target":"test_target","targetName":"测试目标","line":0,"cntType":1,"serverTime":1767146488000,"pushMessageType":0,"pushType":5,"pushContent":"这是一条测试推送消息 - 2025-12-31 10:01:28","unReceivedMsg":1,"mentionedType":0,"packageName":"com.xunpaisoft.social","deviceToken":"OPPO_CN_95ac9afc103d70bb26441ec0cbb06b97","isHiddenDetail":false,"language":"zh","messageId":1767146488,"callStartUid":0,"republish":false,"existBadgeNumber":0}
|
||||
2025-12-31 10:01:28.409 INFO 24833 --- [pool-2-thread-2] c.w.push.android.oppo.OppoPush : Server response: MessageId: 32150237-1-1-695483f82b1dd801763a31a4 ErrorCode: ReturnCode{code=0, message='Success'} Reason: OK
|
||||
2025-12-31 10:03:30.832 INFO 24833 --- [nio-8080-exec-4] c.w.push.android.AndroidPushServiceImpl : Android push {"sender":"test_user","senderName":"测试用户","convType":0,"target":"test_target","targetName":"测试目标","line":0,"cntType":1,"serverTime":1767146610000,"pushMessageType":0,"pushType":5,"pushContent":"这是一条测试推送消息 - 2025-12-31 10:03:30","unReceivedMsg":1,"mentionedType":0,"packageName":"com.xunpaisoft.social","deviceToken":"OPPO_CN_95ac9afc103d70bb26441ec0cbb06b97","isHiddenDetail":false,"language":"zh","messageId":1767146610,"callStartUid":0,"republish":false,"existBadgeNumber":0}
|
||||
2025-12-31 10:03:30.961 INFO 24833 --- [pool-2-thread-2] c.w.push.android.oppo.OppoPush : Server response: MessageId: 32150237-1-1-6954847239320c018f12aacb ErrorCode: ReturnCode{code=0, message='Success'} Reason: OK
|
||||
2025-12-31 10:07:06.868 INFO 24833 --- [nio-8080-exec-6] c.w.push.android.AndroidPushServiceImpl : Android push {"sender":"api_user","senderName":"知你","convType":0,"target":"test_target","targetName":"测试目标","line":0,"cntType":1,"serverTime":1767146826000,"pushMessageType":0,"pushType":5,"pushContent":"我是api","unReceivedMsg":1,"mentionedType":0,"packageName":"com.xunpaisoft.social","deviceToken":"OPPO_CN_95ac9afc103d70bb26441ec0cbb06b97","isHiddenDetail":false,"language":"zh","messageId":1767146826,"callStartUid":0,"republish":false,"existBadgeNumber":0}
|
||||
2025-12-31 10:07:07.002 INFO 24833 --- [pool-2-thread-2] c.w.push.android.oppo.OppoPush : Server response: MessageId: 32150237-1-1-6954854a35f9ec01757142d9 ErrorCode: ReturnCode{code=0, message='Success'} Reason: OK
|
||||
2025-12-31 10:07:55.122 INFO 24833 --- [nio-8080-exec-8] c.w.push.android.AndroidPushServiceImpl : Android push {"sender":"api_user","senderName":"知你","convType":0,"target":"test_target","targetName":"测试目标","line":0,"cntType":1,"serverTime":1767146875000,"pushMessageType":0,"pushType":5,"pushContent":"我是api","unReceivedMsg":1,"mentionedType":0,"packageName":"com.xunpaisoft.social","deviceToken":"OPPO_CN_95ac9afc103d70bb26441ec0cbb06b97","isHiddenDetail":false,"language":"zh","messageId":1767146875,"callStartUid":0,"republish":false,"existBadgeNumber":0}
|
||||
2025-12-31 10:07:55.249 INFO 24833 --- [pool-2-thread-2] c.w.push.android.oppo.OppoPush : Server response: MessageId: 32150237-1-1-6954857b816b510175dc87a7 ErrorCode: ReturnCode{code=0, message='Success'} Reason: OK
|
||||
|
||||
Reference in New Issue
Block a user