diff --git a/config/getui.properties b/config/getui.properties
new file mode 100644
index 0000000..cca3685
--- /dev/null
+++ b/config/getui.properties
@@ -0,0 +1,4 @@
+getui.appId=A0KDwq6KZ3Asy5EhnReEV6
+getui.appKey=7sybBkQYg87ZHyqlsWKrp9
+getui.masterSecret=CXkdSnTy4i5mAJQtLXDor7
+getui.domain=https://restapi.getui.com/v2/
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index bfdd294..87ecaab 100644
--- a/pom.xml
+++ b/pom.xml
@@ -91,6 +91,12 @@
+
+
+ com.getui.push
+ restful-sdk
+ 1.0.0.7
+
diff --git a/src/main/java/cn/wildfirechat/push/android/AndroidPushServiceImpl.java b/src/main/java/cn/wildfirechat/push/android/AndroidPushServiceImpl.java
index 9d0534d..7968e2e 100644
--- a/src/main/java/cn/wildfirechat/push/android/AndroidPushServiceImpl.java
+++ b/src/main/java/cn/wildfirechat/push/android/AndroidPushServiceImpl.java
@@ -4,6 +4,7 @@ import cn.wildfirechat.push.PushMessage;
import cn.wildfirechat.push.PushMessageType;
import cn.wildfirechat.push.Utility;
import cn.wildfirechat.push.android.fcm.FCMPush;
+import cn.wildfirechat.push.android.getui.GetuiPush;
import cn.wildfirechat.push.android.hms.HMSPush;
import cn.wildfirechat.push.android.meizu.MeiZuPush;
import cn.wildfirechat.push.android.oppo.OppoPush;
@@ -41,14 +42,17 @@ public class AndroidPushServiceImpl implements AndroidPushService {
@Autowired
private FCMPush fcmPush;
+ @Autowired
+ private GetuiPush getuiPush;
+
private ExecutorService executorService = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), Runtime.getRuntime().availableProcessors() * 100,
- 60L, TimeUnit.SECONDS,
- new SynchronousQueue());
+ 60L, TimeUnit.SECONDS,
+ new SynchronousQueue());
@Override
public Object push(PushMessage pushMessage) {
LOG.info("Android push {}", new Gson().toJson(pushMessage));
- if(Utility.filterPush(pushMessage)) {
+ if (Utility.filterPush(pushMessage)) {
LOG.info("canceled");
return "Canceled";
}
@@ -58,7 +62,7 @@ public class AndroidPushServiceImpl implements AndroidPushService {
}
final long start = System.currentTimeMillis();
- executorService.execute(()->{
+ executorService.execute(() -> {
long now = System.currentTimeMillis();
if (now - start > 15000) {
LOG.error("等待太久,消息抛弃");
@@ -84,6 +88,9 @@ public class AndroidPushServiceImpl implements AndroidPushService {
case AndroidPushType.ANDROID_PUSH_TYPE_FCM:
fcmPush.push(pushMessage);
break;
+ case AndroidPushType.ANDROID_PUSH_TYPE_GETUI:
+ getuiPush.push(pushMessage);
+ break;
default:
LOG.info("unknown push type");
break;
diff --git a/src/main/java/cn/wildfirechat/push/android/AndroidPushType.java b/src/main/java/cn/wildfirechat/push/android/AndroidPushType.java
index febff3f..e1e246c 100644
--- a/src/main/java/cn/wildfirechat/push/android/AndroidPushType.java
+++ b/src/main/java/cn/wildfirechat/push/android/AndroidPushType.java
@@ -7,4 +7,6 @@ public interface AndroidPushType {
int ANDROID_PUSH_TYPE_VIVO = 4;
int ANDROID_PUSH_TYPE_OPPO = 5;
int ANDROID_PUSH_TYPE_FCM = 6;
+
+ int ANDROID_PUSH_TYPE_GETUI = 7;
}
diff --git a/src/main/java/cn/wildfirechat/push/android/getui/GetuiConfig.java b/src/main/java/cn/wildfirechat/push/android/getui/GetuiConfig.java
new file mode 100644
index 0000000..7a4fc04
--- /dev/null
+++ b/src/main/java/cn/wildfirechat/push/android/getui/GetuiConfig.java
@@ -0,0 +1,47 @@
+package cn.wildfirechat.push.android.getui;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+
+@Configuration
+@ConfigurationProperties(prefix = "getui")
+@PropertySource(value = "file:config/getui.properties")
+public class GetuiConfig {
+ private String appId;
+ private String appKey;
+ private String masterSecret;
+ private String domain;
+
+ public String getAppId() {
+ return appId;
+ }
+
+ public void setAppId(String appId) {
+ this.appId = appId;
+ }
+
+ public String getAppKey() {
+ return appKey;
+ }
+
+ public void setAppKey(String appKey) {
+ this.appKey = appKey;
+ }
+
+ public String getMasterSecret() {
+ return masterSecret;
+ }
+
+ public void setMasterSecret(String masterSecret) {
+ this.masterSecret = masterSecret;
+ }
+
+ public String getDomain() {
+ return domain;
+ }
+
+ public void setDomain(String domain) {
+ this.domain = domain;
+ }
+}
diff --git a/src/main/java/cn/wildfirechat/push/android/getui/GetuiPush.java b/src/main/java/cn/wildfirechat/push/android/getui/GetuiPush.java
new file mode 100644
index 0000000..191da28
--- /dev/null
+++ b/src/main/java/cn/wildfirechat/push/android/getui/GetuiPush.java
@@ -0,0 +1,162 @@
+package cn.wildfirechat.push.android.getui;
+
+
+import cn.wildfirechat.push.PushMessage;
+import cn.wildfirechat.push.PushMessageType;
+import cn.wildfirechat.push.android.xiaomi.XiaomiConfig;
+import com.getui.push.v2.sdk.ApiHelper;
+import com.getui.push.v2.sdk.GtApiConfiguration;
+import com.getui.push.v2.sdk.api.PushApi;
+import com.getui.push.v2.sdk.common.ApiResult;
+import com.getui.push.v2.sdk.dto.req.Audience;
+import com.getui.push.v2.sdk.dto.req.message.PushChannel;
+import com.getui.push.v2.sdk.dto.req.message.PushDTO;
+import com.getui.push.v2.sdk.dto.req.message.android.AndroidDTO;
+import com.getui.push.v2.sdk.dto.req.message.android.GTNotification;
+import com.getui.push.v2.sdk.dto.req.message.android.ThirdNotification;
+import com.getui.push.v2.sdk.dto.req.message.android.Ups;
+import com.google.gson.Gson;
+import com.meizu.push.sdk.server.IFlymePush;
+import com.xiaomi.xmpush.server.Constants;
+import com.xiaomi.xmpush.server.Message;
+import com.xiaomi.xmpush.server.Result;
+import com.xiaomi.xmpush.server.Sender;
+import org.json.simple.parser.ParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import javax.annotation.PostConstruct;
+import java.io.IOException;
+import java.util.Map;
+
+import static com.xiaomi.xmpush.server.Message.NOTIFY_TYPE_ALL;
+
+@Component
+public class GetuiPush {
+ private static final Logger LOG = LoggerFactory.getLogger(GetuiPush.class);
+ @Autowired
+ private GetuiConfig mConfig;
+
+ private PushApi pushApi;
+
+ @PostConstruct
+ public void init() {
+ // 设置httpClient最大连接数,当并发较大时建议调大此参数。或者启动参数加上 -Dhttp.maxConnections=200
+ System.setProperty("http.maxConnections", "200");
+ GtApiConfiguration apiConfiguration = new GtApiConfiguration();
+ //填写应用配置
+ 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);
+
+ PushMessage pushMessage = new PushMessage();
+ pushMessage.deviceToken = "9f87b9ea12f5623ad482a468748d3845";
+ pushMessage.pushMessageType = PushMessageType.PUSH_MESSAGE_TYPE_FRIEND_REQUEST;
+ pushMessage.pushContent = "xxx 加你为好友";
+
+ this.push(pushMessage);
+ }
+
+ public void push(PushMessage pushMessage) {
+ if (pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_RECALLED || pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_DELETED) {
+ //Todo not implement
+ //撤回或者删除消息,需要更新远程通知,暂未实现
+ return;
+ }
+
+ if (pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_SECRET_CHAT) {
+ pushMessage.pushContent = "您收到一条密聊消息";
+ }
+
+ if (pushMessage.isHiddenDetail) {
+ pushMessage.pushContent = "您收到一条新消息";
+ }
+ String title;
+ if (pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_FRIEND_REQUEST) {
+ if (StringUtils.isEmpty(pushMessage.senderName)) {
+ title = "好友请求";
+ } else {
+ title = pushMessage.senderName + " 请求加您为好友";
+ }
+ } else {
+ if (StringUtils.isEmpty(pushMessage.senderName)) {
+ title = "新消息";
+ } else {
+ title = pushMessage.senderName;
+ }
+ }
+
+ //根据cid进行单推
+ PushDTO pushDTO = new PushDTO();
+ // 设置推送参数
+ pushDTO.setRequestId(System.currentTimeMillis() + "");
+ /**** 设置个推通道参数 *****/
+ com.getui.push.v2.sdk.dto.req.message.PushMessage pm = new com.getui.push.v2.sdk.dto.req.message.PushMessage();
+ pushDTO.setPushMessage(pm);
+ GTNotification notification = new GTNotification();
+ pm.setNotification(notification);
+ notification.setTitle(title);
+ notification.setBody(pushMessage.pushContent);
+ notification.setClickType("startapp");
+// notification.setUrl("https://www.getui.com");
+ /**** 设置个推通道参数,更多参数请查看文档或对象源码 *****/
+
+ /**** 设置厂商相关参数 ****/
+ PushChannel pushChannel = new PushChannel();
+ pushDTO.setPushChannel(pushChannel);
+ /*配置安卓厂商参数*/
+ AndroidDTO androidDTO = new AndroidDTO();
+ pushChannel.setAndroid(androidDTO);
+ Ups ups = new Ups();
+ androidDTO.setUps(ups);
+ ThirdNotification thirdNotification = new ThirdNotification();
+ ups.setNotification(thirdNotification);
+ thirdNotification.setTitle(title);
+ thirdNotification.setBody(pushMessage.pushContent);
+ thirdNotification.setClickType("startapp");
+// thirdNotification.setUrl("https://www.getui.com");
+ // 两条消息的notify_id相同,新的消息会覆盖老的消息,取值范围:0-2147483647
+ // thirdNotification.setNotifyId("11177");
+ /*配置安卓厂商参数结束,更多参数请查看文档或对象源码*/
+
+ /*设置ios厂商参数*/
+// IosDTO iosDTO = new IosDTO();
+// pushChannel.setIos(iosDTO);
+// // 相同的collapseId会覆盖之前的消息
+// iosDTO.setApnsCollapseId("xxx");
+// Aps aps = new Aps();
+// iosDTO.setAps(aps);
+// Alert alert = new Alert();
+// aps.setAlert(alert);
+// alert.setTitle("ios title");
+// alert.setBody("ios body");
+ /*设置ios厂商参数结束,更多参数请查看文档或对象源码*/
+
+ /*设置接收人信息*/
+ Audience audience = new Audience();
+ pushDTO.setAudience(audience);
+ audience.addCid(pushMessage.getDeviceToken());
+ /*设置接收人信息结束*/
+ /**** 设置厂商相关参数,更多参数请查看文档或对象源码 ****/
+
+ // 进行cid单推
+ ApiResult