diff --git a/cim-boot-server/cim-boot-server.iml b/cim-boot-server/cim-boot-server.iml
deleted file mode 100644
index 41bd885..0000000
--- a/cim-boot-server/cim-boot-server.iml
+++ /dev/null
@@ -1,147 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/cim-boot-server/cim-boot-server.ipr b/cim-boot-server/cim-boot-server.ipr
deleted file mode 100644
index 0ee9871..0000000
--- a/cim-boot-server/cim-boot-server.ipr
+++ /dev/null
@@ -1,1235 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-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a/cim-boot-server/cim-boot-server.iws
+++ /dev/null
@@ -1,69 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1632398352014
-
-
- 1632398352014
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/cim-boot-server/libs/cim-server-sdk-netty-4.0.0.jar b/cim-boot-server/libs/cim-server-sdk-netty-4.0.0.jar
index f446a41..8591804 100644
Binary files a/cim-boot-server/libs/cim-server-sdk-netty-4.0.0.jar and b/cim-boot-server/libs/cim-server-sdk-netty-4.0.0.jar differ
diff --git a/cim-boot-server/pom.xml b/cim-boot-server/pom.xml
index c273733..26cdd37 100644
--- a/cim-boot-server/pom.xml
+++ b/cim-boot-server/pom.xml
@@ -127,15 +127,15 @@
- cn.teaey.apns4j
- apns4j
- 1.1.4
+ com.eatthepath
+ pushy
+ 0.15.0
commons-io
commons-io
- 2.6
+ 2.7
diff --git a/cim-boot-server/src/main/java/com/farsunset/cim/component/handler/ClosedHandler.java b/cim-boot-server/src/main/java/com/farsunset/cim/component/handler/ClosedHandler.java
index 9886409..cca0b24 100644
--- a/cim-boot-server/src/main/java/com/farsunset/cim/component/handler/ClosedHandler.java
+++ b/cim-boot-server/src/main/java/com/farsunset/cim/component/handler/ClosedHandler.java
@@ -58,6 +58,9 @@ public class ClosedHandler implements CIMRequestHandler {
sessionGroup.remove(channel);
+ /*
+ * ios开启了apns也需要显示在线,因此不删记录
+ */
if (!Objects.equals(channel.attr(ChannelAttr.CHANNEL).get(), Session.CHANNEL_IOS)){
sessionService.delete(uid,nid);
return;
diff --git a/cim-boot-server/src/main/java/com/farsunset/cim/config/properties/APNsProperties.java b/cim-boot-server/src/main/java/com/farsunset/cim/config/properties/APNsProperties.java
index 82edf5d..c7bdeac 100644
--- a/cim-boot-server/src/main/java/com/farsunset/cim/config/properties/APNsProperties.java
+++ b/cim-boot-server/src/main/java/com/farsunset/cim/config/properties/APNsProperties.java
@@ -28,6 +28,8 @@ public class APNsProperties {
private boolean debug;
+ private String appId;
+
private final P12 p12 = new P12();
public static class P12 {
@@ -67,6 +69,13 @@ public class APNsProperties {
return p12.file;
}
+ public String getAppId() {
+ return appId;
+ }
+
+ public void setAppId(String appId) {
+ this.appId = appId;
+ }
public String getP12Password() {
return p12.password;
diff --git a/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/APNsServiceImpl.java b/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/APNsServiceImpl.java
index 56ef1c7..6c017b0 100644
--- a/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/APNsServiceImpl.java
+++ b/cim-boot-server/src/main/java/com/farsunset/cim/service/impl/APNsServiceImpl.java
@@ -21,21 +21,23 @@
*/
package com.farsunset.cim.service.impl;
-import cn.teaey.apns4j.Apns4j;
-import cn.teaey.apns4j.network.ApnsChannel;
-import cn.teaey.apns4j.network.ApnsChannelFactory;
-import cn.teaey.apns4j.network.ApnsGateway;
-import cn.teaey.apns4j.protocol.ApnsPayload;
+import com.eatthepath.pushy.apns.ApnsClient;
+import com.eatthepath.pushy.apns.ApnsClientBuilder;
+import com.eatthepath.pushy.apns.ApnsPushNotification;
+import com.eatthepath.pushy.apns.util.ApnsPayloadBuilder;
+import com.eatthepath.pushy.apns.util.SimpleApnsPayloadBuilder;
+import com.eatthepath.pushy.apns.util.SimpleApnsPushNotification;
+import com.eatthepath.pushy.apns.util.TokenUtil;
import com.farsunset.cim.config.properties.APNsProperties;
import com.farsunset.cim.sdk.server.model.Message;
import com.farsunset.cim.service.APNsService;
-import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import java.io.IOException;
import java.io.InputStream;
@Service
@@ -43,15 +45,19 @@ public class APNsServiceImpl implements APNsService {
private static final Logger LOGGER = LoggerFactory.getLogger(APNsServiceImpl.class);
- private final ApnsChannelFactory apnsChannelFactory;
+ private final ApnsClient apnsClient;
+
+ private final APNsProperties properties;
@Autowired
- public APNsServiceImpl(APNsProperties properties){
+ public APNsServiceImpl(APNsProperties properties) throws IOException {
+ this.properties = properties;
+
InputStream stream = getClass().getResourceAsStream(properties.getP12File());
- apnsChannelFactory = Apns4j.newChannelFactoryBuilder()
- .keyStoreMeta(stream)
- .keyStorePwd(properties.getP12Password())
- .apnsGateway(properties.isDebug() ? ApnsGateway.DEVELOPMENT : ApnsGateway.PRODUCTION)
+
+ apnsClient = new ApnsClientBuilder()
+ .setApnsServer(properties.isDebug() ? ApnsClientBuilder.DEVELOPMENT_APNS_HOST : ApnsClientBuilder.PRODUCTION_APNS_HOST)
+ .setClientCredentials(stream, properties.getP12Password())
.build();
}
@@ -64,29 +70,33 @@ public class APNsServiceImpl implements APNsService {
return ;
}
- ApnsChannel apnsChannel = apnsChannelFactory.newChannel();
- ApnsPayload apnsPayload = new ApnsPayload();
+ ApnsPayloadBuilder payloadBuilder = new SimpleApnsPayloadBuilder();
- apnsPayload.alert("您有一条新的消息");
+ payloadBuilder.setAlertTitle("您有一条新的消息");
- apnsPayload.sound("default");
- apnsPayload.badge(1);
- apnsPayload.extend("id",message.getId());
- apnsPayload.extend("action",message.getAction());
- apnsPayload.extend("content",message.getContent());
- apnsPayload.extend("sender",message.getSender());
- apnsPayload.extend("receiver",message.getReceiver());
- apnsPayload.extend("format",message.getFormat());
- apnsPayload.extend("extra",message.getExtra());
- apnsPayload.extend("timestamp",message.getTimestamp());
+ payloadBuilder.setSound("default");
+ payloadBuilder.setBadgeNumber(1);
+ payloadBuilder.addCustomProperty("id",message.getId());
+ payloadBuilder.addCustomProperty("action",message.getAction());
+ payloadBuilder.addCustomProperty("content",message.getContent());
+ payloadBuilder.addCustomProperty("sender",message.getSender());
+ payloadBuilder.addCustomProperty("receiver",message.getReceiver());
+ payloadBuilder.addCustomProperty("format",message.getFormat());
+ payloadBuilder.addCustomProperty("extra",message.getExtra());
+ payloadBuilder.addCustomProperty("timestamp",message.getTimestamp());
- try {
- apnsChannel.send(deviceToken, apnsPayload);
- LOGGER.info("APNs push done.\ndeviceToken : {} \napnsPayload : {}",deviceToken,apnsPayload.toJsonString());
- }catch(Exception exception) {
- LOGGER.error("APNs push failed",exception);
- }finally {
- IOUtils.closeQuietly(apnsChannel);
- }
+ String token = TokenUtil.sanitizeTokenString(deviceToken);
+
+ String payload = payloadBuilder.build();
+
+ ApnsPushNotification notification = new SimpleApnsPushNotification(token, properties.getAppId(), payload);
+
+ apnsClient.sendNotification(notification).whenComplete((response, cause) -> {
+ if (response != null) {
+ LOGGER.info("APNs push done.\ndeviceToken : {} \napnsPayload : {}",deviceToken,payload);
+ } else {
+ LOGGER.error("APNs push failed",cause);
+ }
+ });
}
}
diff --git a/cim-boot-server/src/main/java/com/farsunset/cim/util/ApnsPayloadCompat.java b/cim-boot-server/src/main/java/com/farsunset/cim/util/ApnsPayloadCompat.java
deleted file mode 100644
index 67b9b7a..0000000
--- a/cim-boot-server/src/main/java/com/farsunset/cim/util/ApnsPayloadCompat.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright 2013-2019 Xia Jun(3979434@qq.com).
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ***************************************************************************************
- * *
- * Website : http://www.farsunset.com *
- * *
- ***************************************************************************************
- */
-package com.farsunset.cim.util;
-
-import cn.teaey.apns4j.protocol.ApnsPayload;
-
-public class ApnsPayloadCompat extends ApnsPayload {
-
- private static final String DATA_FORMAT = "{\"aps\": {\"message\": {\"action\":\"%s\",\"content\":\"%s\",\"sender\":\"%s\",\"receiver\":\"%s\",\"format\":\"%s\"},\"content-available\": 1}}";
-
- private String action;
- private String content;
- private String sender;
- private String format;
- private String receiver;
-
-
- public String getReceiver() {
- return receiver;
- }
-
- public void setReceiver(String receiver) {
- this.receiver = receiver;
- }
-
- public String getAction() {
- return action;
- }
-
- public void setAction(String action) {
- this.action = action;
- }
-
- public String getContent() {
- return content;
- }
-
- public void setContent(String content) {
- this.content = content;
- }
-
- public String getSender() {
- return sender;
- }
-
- public void setSender(String sender) {
- this.sender = sender;
- }
-
- public String getFormat() {
- return format;
- }
-
- public void setFormat(String format) {
- this.format = format;
- }
-
- @Override
- public String toJsonString() {
- return String.format(DATA_FORMAT, action, content, sender,receiver,format);
- }
-}
diff --git a/cim-boot-server/src/main/resources/application.properties b/cim-boot-server/src/main/resources/application.properties
index d30e95b..e96ed4d 100644
--- a/cim-boot-server/src/main/resources/application.properties
+++ b/cim-boot-server/src/main/resources/application.properties
@@ -63,7 +63,8 @@ spring.messages.basename=i18n/messages
cim.app.port=23456
cim.websocket.port=34567
-#please setting your p12 info.
+#please setting your p12 info and appId.
cim.apns.p12.file=/apns/app.p12
cim.apns.p12.password=123
cim.apns.debug=false
+cim.apns.app-id=com.xxx.xxx.ios
diff --git a/cim-server-sdk/src/main/java/com/farsunset/cim/sdk/server/group/SessionGroup.java b/cim-server-sdk/src/main/java/com/farsunset/cim/sdk/server/group/SessionGroup.java
index 70adcb6..da74249 100644
--- a/cim-server-sdk/src/main/java/com/farsunset/cim/sdk/server/group/SessionGroup.java
+++ b/cim-server-sdk/src/main/java/com/farsunset/cim/sdk/server/group/SessionGroup.java
@@ -76,6 +76,10 @@ public class SessionGroup extends ConcurrentHashMap>
find(key).stream().filter(matcher).forEach(channel -> channel.writeAndFlush(message));
}
+ public void write(String key, Message message, Collection excludedSet){
+ find(key).stream().filter(channel -> excludedSet == null || !excludedSet.contains(channel.attr(ChannelAttr.UID).get())).forEach(channel -> channel.writeAndFlush(message));
+ }
+
public void write(Message message){
this.write(message.getReceiver(),message);
}
diff --git a/cim-server-sdk/src/main/java/com/farsunset/cim/sdk/server/model/Message.java b/cim-server-sdk/src/main/java/com/farsunset/cim/sdk/server/model/Message.java
index 9036152..1dab599 100644
--- a/cim-server-sdk/src/main/java/com/farsunset/cim/sdk/server/model/Message.java
+++ b/cim-server-sdk/src/main/java/com/farsunset/cim/sdk/server/model/Message.java
@@ -29,7 +29,7 @@ import java.io.Serializable;
/**
* 消息对象
*/
-public class Message implements Serializable, Transportable {
+public class Message implements Serializable, Transportable,Cloneable {
private static final long serialVersionUID = 1L;
@@ -171,30 +171,52 @@ public class Message implements Serializable, Transportable {
return txt != null && txt.trim().length() != 0;
}
+ @Override
+ public Message clone(){
+ Message message = new Message();
+ message.id = id;
+ message.action = action;
+ message.title = title;
+ message.content = content;
+ message.sender = sender;
+ message.receiver = receiver;
+ message.extra = extra;
+ message.format = format;
+ message.timestamp = timestamp;
+ return message;
+ }
@Override
public byte[] getBody() {
MessageProto.Model.Builder builder = MessageProto.Model.newBuilder();
builder.setId(id);
builder.setAction(action);
builder.setSender(sender);
- builder.setReceiver(receiver);
builder.setTimestamp(timestamp);
- /**
+ /*
* 下面字段可能为空
*/
+
+ if (receiver != null){
+ builder.setReceiver(receiver);
+ }
+
if (content != null) {
builder.setContent(content);
}
+
if (title != null) {
builder.setTitle(title);
}
+
if (extra != null) {
builder.setExtra(extra);
}
+
if (format != null) {
builder.setFormat(format);
}
+
return builder.build().toByteArray();
}