From b06dab478b1d23a8961facbefed4d4ad88276c67 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期四, 26 二月 2026 19:30:37 +0800
Subject: [PATCH] 阿里云消息推送
---
xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/utils/AliPushUtil.java | 35 ++++++++++++++++++++++++++++-------
1 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/utils/AliPushUtil.java b/xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/utils/AliPushUtil.java
index 1c62886..8374017 100644
--- a/xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/utils/AliPushUtil.java
+++ b/xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/utils/AliPushUtil.java
@@ -1,27 +1,32 @@
package com.xiaopeng.pushMessage.utils;
+import com.alibaba.fastjson2.JSONObject;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.service.push20160801.models.*;
import com.aliyun.sdk.service.push20160801.*;
import com.google.gson.Gson;
import darabonba.core.client.ClientOverrideConfiguration;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
//import javax.net.ssl.KeyManager;
//import javax.net.ssl.X509TrustManager;
import java.util.concurrent.CompletableFuture;
+@Slf4j
public class AliPushUtil {
@Value("${ali.push.accessKeyId}")
private String accessKeyId;
@Value("${ali.push.accessKeySecret}")
private String accessKeySecret;
- @Value("${ali.push.appKey}")
- private Long appKey;
@Value("${ali.push.regionId}")
private String regionId;
+ @Value("${ali.push.appKey}")
+ private Long appKey;
+ @Value("${ali.push.iosAppKey}")
+ private Long iosAppKey;
/**
* 消息类型 MESSAGE 消息 NOTICE 通知
*/
@@ -51,7 +56,7 @@
* @param body 消息内容
* @throws Exception
*/
- public void push(String account, String title, String body) throws Exception {
+ public String pushMessage(Integer deviceType,String account, String title, String body) throws Exception {
StaticCredentialProvider credentialProvider = StaticCredentialProvider.create(
Credential.builder()
@@ -70,9 +75,14 @@
)
.build()) {
- // Parameter settings for API request
+ // 判断账号类型
+ Long appKeys = appKey;
+ if(deviceType == 2){
+ appKeys = iosAppKey;
+ }
+
PushRequest pushRequest = PushRequest.builder()
- .appKey(appKey)
+ .appKey(appKeys)
.pushType(PUSH_TYPE)
.deviceType(DEVICE_TYPE_ALL)
.target(TARGET)
@@ -82,10 +92,21 @@
.build();
CompletableFuture<PushResponse> response = client.push(pushRequest);
PushResponse resp = response.get();
- System.out.println(new Gson().toJson(resp));
+ String json = new Gson().toJson(resp);
+ log.info("运维APP-消息推送:{}",json);
+ JSONObject jsonObject = JSONObject.parseObject(json);
+
+ Integer statusCode = jsonObject.getInteger("statusCode");
+ if(statusCode == 200){
+ log.info("运维APP-消息推送成功");
+ JSONObject resultBody = jsonObject.getJSONObject("body");
+ return resultBody.getString("messageId");
+ }else{
+ log.info("运维APP-消息推送失败");
+ return null;
+ }
}
-
}
public static void main(String[] args) throws Exception {
--
Gitblit v1.7.1