From 778391521e1818408b8c3bdaa9a20ee231ed2880 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期五, 27 二月 2026 10:12:01 +0800
Subject: [PATCH] 阿里云消息推送远程

---
 xp-robotaxi-push-message-boot/src/main/java/com/xiaopeng/pushMessage/utils/AliPushUtil.java |  102 +++++++++++++++++++++++++++-----------------------
 1 files changed, 55 insertions(+), 47 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 8374017..1d3f6d6 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
@@ -9,12 +9,14 @@
 import darabonba.core.client.ClientOverrideConfiguration;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
 
 //import javax.net.ssl.KeyManager;
 //import javax.net.ssl.X509TrustManager;
 import java.util.concurrent.CompletableFuture;
 
 @Slf4j
+@Component
 public class AliPushUtil {
 
     @Value("${ali.push.accessKeyId}")
@@ -50,62 +52,68 @@
 
 
     /**
-     *
+     *  消息推送方法
      * @param account 运维手机号
      * @param title 标题
      * @param body 消息内容
      * @throws Exception
      */
-    public String pushMessage(Integer deviceType,String account, String title, String body) throws Exception {
+    public String pushMessage(Integer deviceType,String account, String title, String body){
 
-        StaticCredentialProvider credentialProvider = StaticCredentialProvider.create(
-                Credential.builder()
-                        .accessKeyId(accessKeyId)
-                        .accessKeySecret(accessKeySecret)
-                        .build()
-        );
+        try {
+            StaticCredentialProvider credentialProvider = StaticCredentialProvider.create(
+                    Credential.builder()
+                            .accessKeyId(accessKeyId)
+                            .accessKeySecret(accessKeySecret)
+                            .build()
+            );
 
-        // Configure the Client
-        try (AsyncClient client = AsyncClient.builder()
-                .region(regionId) // Region ID
-                .credentialsProvider(credentialProvider)
-                .overrideConfiguration(
-                    ClientOverrideConfiguration.create()
-                    .setEndpointOverride("cloudpush.aliyuncs.com")
-                )
-                .build()) {
+            // Configure the Client
+            try (AsyncClient client = AsyncClient.builder()
+                    .region(regionId) // Region ID
+                    .credentialsProvider(credentialProvider)
+                    .overrideConfiguration(
+                            ClientOverrideConfiguration.create()
+                                    .setEndpointOverride("cloudpush.aliyuncs.com")
+                    )
+                    .build()) {
 
-            // 判断账号类型
-            Long appKeys = appKey;
-            if(deviceType == 2){
-                appKeys = iosAppKey;
+                // 判断账号类型
+                Long appKeys = appKey;
+                if(deviceType == 2){
+                    appKeys = iosAppKey;
+                }
+
+                PushRequest pushRequest = PushRequest.builder()
+                        .appKey(appKeys)
+                        .pushType(PUSH_TYPE)
+                        .deviceType(DEVICE_TYPE_ALL)
+                        .target(TARGET)
+                        .targetValue(account)
+                        .title(title)
+                        .body(body)
+                        .build();
+                CompletableFuture<PushResponse> response = client.push(pushRequest);
+                PushResponse resp = response.get();
+                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;
+                }
             }
-
-            PushRequest pushRequest = PushRequest.builder()
-                    .appKey(appKeys)
-                    .pushType(PUSH_TYPE)
-                    .deviceType(DEVICE_TYPE_ALL)
-                    .target(TARGET)
-                    .targetValue(account)
-                    .title(title)
-                    .body(body)
-                    .build();
-            CompletableFuture<PushResponse> response = client.push(pushRequest);
-            PushResponse resp = response.get();
-            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;
-            }
+        } catch (Exception e) {
+            log.info("运维APP-消息推送失败-异常");
+            e.printStackTrace();
+            return null;
         }
     }
 

--
Gitblit v1.7.1