From 4b63d34cf7f372d3792087f3c16a4a76a6ffc9c3 Mon Sep 17 00:00:00 2001 From: imndx Date: Thu, 16 Jan 2025 16:18:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E6=9F=90=E7=A7=8D=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E6=9C=AA=E6=AD=A3=E7=A1=AE=E9=85=8D=E7=BD=AE=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E6=AD=A3=E5=B8=B8=E5=88=9D=E5=A7=8B=E5=8C=96=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E6=89=93=E5=8D=B0=E6=97=A5=E5=BF=97=EF=BC=8C=E4=BD=86?= =?UTF-8?q?=E4=B8=8D=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../push/android/fcm/FCMPush.java | 6 ++++ .../push/android/getui/GetuiPush.java | 35 +++++++++++-------- .../push/android/meizu/MeiZuPush.java | 8 ++++- .../push/android/oppo/OppoPush.java | 1 + .../cn/wildfirechat/push/ios/ApnsServer.java | 13 ++----- 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/main/java/cn/wildfirechat/push/android/fcm/FCMPush.java b/src/main/java/cn/wildfirechat/push/android/fcm/FCMPush.java index 2bff666..3b0f320 100644 --- a/src/main/java/cn/wildfirechat/push/android/fcm/FCMPush.java +++ b/src/main/java/cn/wildfirechat/push/android/fcm/FCMPush.java @@ -25,12 +25,18 @@ public class FCMPush { @PostConstruct private void init() throws Exception { + try { + FileInputStream refreshToken = new FileInputStream(mConfig.getCredentialsPath()); FirebaseOptions options = FirebaseOptions.builder() .setCredentials(GoogleCredentials.fromStream(refreshToken)) .setDatabaseUrl("https://.firebaseio.com/") .build(); FirebaseApp.initializeApp(options); + } catch (Exception e) { + LOG.error("FCMPush init failed"); + e.printStackTrace(); + } } diff --git a/src/main/java/cn/wildfirechat/push/android/getui/GetuiPush.java b/src/main/java/cn/wildfirechat/push/android/getui/GetuiPush.java index 39bbb7b..68e5dfb 100644 --- a/src/main/java/cn/wildfirechat/push/android/getui/GetuiPush.java +++ b/src/main/java/cn/wildfirechat/push/android/getui/GetuiPush.java @@ -48,21 +48,26 @@ public class GetuiPush { @PostConstruct public void init() { - // 设置httpClient最大连接数,当并发较大时建议调大此参数。或者启动参数加上 -Dhttp.maxConnections=200 - System.setProperty("http.maxConnections", "200"); - GtApiConfiguration apiConfiguration = new GtApiConfiguration(); - //填写应用配置 - if(!StringUtils.isEmpty(mConfig.getAppId())) { - apiConfiguration.setAppId(mConfig.getAppId()); - apiConfiguration.setAppKey(mConfig.getAppKey()); - apiConfiguration.setMasterSecret(mConfig.getMasterSecret()); - // 接口调用前缀,请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId - apiConfiguration.setDomain("https://restapi.getui.com/v2/"); -// apiConfiguration.setDomain(mConfig.getDomain()); - // 实例化ApiHelper对象,用于创建接口对象 - ApiHelper apiHelper = ApiHelper.build(apiConfiguration); - // 创建对象,建议复用。目前有PushApi、StatisticApi、UserApi - this.pushApi = apiHelper.creatApi(PushApi.class); + try{ + // 设置httpClient最大连接数,当并发较大时建议调大此参数。或者启动参数加上 -Dhttp.maxConnections=200 + System.setProperty("http.maxConnections", "200"); + GtApiConfiguration apiConfiguration = new GtApiConfiguration(); + //填写应用配置 + if(!StringUtils.isEmpty(mConfig.getAppId())) { + apiConfiguration.setAppId(mConfig.getAppId()); + apiConfiguration.setAppKey(mConfig.getAppKey()); + apiConfiguration.setMasterSecret(mConfig.getMasterSecret()); + // 接口调用前缀,请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId + apiConfiguration.setDomain("https://restapi.getui.com/v2/"); + // apiConfiguration.setDomain(mConfig.getDomain()); + // 实例化ApiHelper对象,用于创建接口对象 + ApiHelper apiHelper = ApiHelper.build(apiConfiguration); + // 创建对象,建议复用。目前有PushApi、StatisticApi、UserApi + this.pushApi = apiHelper.creatApi(PushApi.class); + } + } catch (Exception e) { + LOG.error("GetuiPush init failed"); + e.printStackTrace(); } } diff --git a/src/main/java/cn/wildfirechat/push/android/meizu/MeiZuPush.java b/src/main/java/cn/wildfirechat/push/android/meizu/MeiZuPush.java index 00a8f9f..a48afca 100644 --- a/src/main/java/cn/wildfirechat/push/android/meizu/MeiZuPush.java +++ b/src/main/java/cn/wildfirechat/push/android/meizu/MeiZuPush.java @@ -25,7 +25,13 @@ public class MeiZuPush { @PostConstruct public void init() { - this.flymePush = new IFlymePush(mConfig.getAppSecret()); + try { + //初始化推送sdk + this.flymePush = new IFlymePush(mConfig.getAppSecret()); + } catch (Exception e) { + LOG.error("MeiZuPush init failed"); + e.printStackTrace(); + } } @Autowired diff --git a/src/main/java/cn/wildfirechat/push/android/oppo/OppoPush.java b/src/main/java/cn/wildfirechat/push/android/oppo/OppoPush.java index fd71475..51b233f 100644 --- a/src/main/java/cn/wildfirechat/push/android/oppo/OppoPush.java +++ b/src/main/java/cn/wildfirechat/push/android/oppo/OppoPush.java @@ -30,6 +30,7 @@ public class OppoPush { try { mSender = new Sender(mConfig.getAppKey(), mConfig.getAppSecret()); } catch (Exception e) { + LOG.error("OppoPush init failed"); e.printStackTrace(); } } diff --git a/src/main/java/cn/wildfirechat/push/ios/ApnsServer.java b/src/main/java/cn/wildfirechat/push/ios/ApnsServer.java index 5f359b9..a8da3ef 100644 --- a/src/main/java/cn/wildfirechat/push/ios/ApnsServer.java +++ b/src/main/java/cn/wildfirechat/push/ios/ApnsServer.java @@ -21,13 +21,8 @@ import org.springframework.util.StringUtils; import javax.annotation.PostConstruct; import java.io.File; -import java.io.IOException; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; import java.util.Calendar; -import static java.lang.System.exit; - @Component public class ApnsServer { private static final Logger LOG = LoggerFactory.getLogger(ApnsServer.class); @@ -110,13 +105,9 @@ public class ApnsServer { .build(); } } - } catch (IOException e) { + } catch (Exception e) { + LOG.error("ApnsServer init failed"); e.printStackTrace(); - exit(-1); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } catch (InvalidKeyException e) { - throw new RuntimeException(e); } }