update
This commit is contained in:
@@ -13,12 +13,15 @@ import org.springframework.util.StringUtils;
|
|||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import static com.notnoop.apns.DeliveryError.INVALID_TOKEN;
|
import static com.notnoop.apns.DeliveryError.INVALID_TOKEN;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class ApnsServer implements ApnsDelegate {
|
public class ApnsServer implements ApnsDelegate {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ApnsServer.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ApnsServer.class);
|
||||||
|
private static ExecutorService mExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 5);
|
||||||
@Override
|
@Override
|
||||||
public void messageSent(ApnsNotification message, boolean resent) {
|
public void messageSent(ApnsNotification message, boolean resent) {
|
||||||
LOG.info("APNS push sent:{}", message.getDeviceToken());
|
LOG.info("APNS push sent:{}", message.getDeviceToken());
|
||||||
@@ -100,88 +103,96 @@ public class ApnsServer implements ApnsDelegate {
|
|||||||
|
|
||||||
|
|
||||||
public void pushMessage(PushMessage pushMessage) {
|
public void pushMessage(PushMessage pushMessage) {
|
||||||
|
final long start = System.currentTimeMillis();
|
||||||
ApnsService service = developSvc;
|
mExecutor.submit(()-> {
|
||||||
if (pushMessage.getPushType() == IOSPushType.IOS_PUSH_TYPE_DISTRIBUTION) {
|
long now = System.currentTimeMillis();
|
||||||
if (pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_NORMAL || StringUtils.isEmpty(pushMessage.getVoipDeviceToken())) {
|
if (now - start > 5000) {
|
||||||
service = productSvc;
|
LOG.error("等待太久,消息抛弃");
|
||||||
} else {
|
return;
|
||||||
service = voipSvc;
|
}
|
||||||
|
ApnsService service = developSvc;
|
||||||
|
if (pushMessage.getPushType() == IOSPushType.IOS_PUSH_TYPE_DISTRIBUTION) {
|
||||||
|
if (pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_NORMAL || StringUtils.isEmpty(pushMessage.getVoipDeviceToken())) {
|
||||||
|
service = productSvc;
|
||||||
|
} else {
|
||||||
|
service = voipSvc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (service == null) {
|
if (service == null) {
|
||||||
LOG.error("Service not exist!!!!");
|
LOG.error("Service not exist!!!!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String sound = mConfig.alert;
|
String sound = mConfig.alert;
|
||||||
|
|
||||||
String pushContent = pushMessage.getPushContent();
|
String pushContent = pushMessage.getPushContent();
|
||||||
if (pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_VOIP_INVITE) {
|
if (pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_VOIP_INVITE) {
|
||||||
pushContent = "通话邀请";
|
pushContent = "通话邀请";
|
||||||
sound = mConfig.voipAlert;
|
sound = mConfig.voipAlert;
|
||||||
} else if(pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_VOIP_BYE) {
|
} else if(pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_VOIP_BYE) {
|
||||||
pushContent = "通话结束";
|
pushContent = "通话结束";
|
||||||
sound = null;
|
sound = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int badge = pushMessage.getUnReceivedMsg();
|
int badge = pushMessage.getUnReceivedMsg();
|
||||||
if (badge <= 0) {
|
if (badge <= 0) {
|
||||||
badge = 1;
|
badge = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String title;
|
String title;
|
||||||
String body;
|
String body;
|
||||||
//todo 这里需要加上语言的处理,客户端会上报自己的语言,在DeviceInfo那个类中
|
//todo 这里需要加上语言的处理,客户端会上报自己的语言,在DeviceInfo那个类中
|
||||||
// if (pushMessage.language == "zh_CN") {
|
// if (pushMessage.language == "zh_CN") {
|
||||||
//
|
//
|
||||||
// } else if(pushMessage.language == "US_EN") {
|
// } else if(pushMessage.language == "US_EN") {
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
if (pushMessage.convType == 1) {
|
if (pushMessage.convType == 1) {
|
||||||
title = pushMessage.targetName;
|
title = pushMessage.targetName;
|
||||||
if (StringUtils.isEmpty(title)) {
|
if (StringUtils.isEmpty(title)) {
|
||||||
title = "群聊";
|
title = "群聊";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isEmpty(pushMessage.senderName)) {
|
if (StringUtils.isEmpty(pushMessage.senderName)) {
|
||||||
|
body = pushContent;
|
||||||
|
} else {
|
||||||
|
body = pushMessage.senderName + ":" + pushContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pushMessage.mentionedType == 1) {
|
||||||
|
if (StringUtils.isEmpty(pushMessage.senderName)) {
|
||||||
|
body = "有人在群里@了你";
|
||||||
|
} else {
|
||||||
|
body = pushMessage.senderName + "在群里@了你";
|
||||||
|
}
|
||||||
|
} else if(pushMessage.mentionedType == 2) {
|
||||||
|
if (StringUtils.isEmpty(pushMessage.senderName)) {
|
||||||
|
body = "有人在群里@了大家";
|
||||||
|
} else {
|
||||||
|
body = pushMessage.senderName + "在群里@了大家";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (StringUtils.isEmpty(pushMessage.senderName)) {
|
||||||
|
title = "消息";
|
||||||
|
} else {
|
||||||
|
title = pushMessage.senderName;
|
||||||
|
}
|
||||||
body = pushContent;
|
body = pushContent;
|
||||||
} else {
|
|
||||||
body = pushMessage.senderName + ":" + pushContent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pushMessage.mentionedType == 1) {
|
final String payload = APNS.newPayload().alertBody(body).badge(badge).alertTitle(title).sound(sound).build();
|
||||||
if (StringUtils.isEmpty(pushMessage.senderName)) {
|
final ApnsNotification goodMsg = service.push(service == voipSvc ? pushMessage.getVoipDeviceToken() : pushMessage.getDeviceToken(), payload, null);
|
||||||
body = "有人在群里@了你";
|
LOG.info("Message id: " + goodMsg.getIdentifier());
|
||||||
} else {
|
|
||||||
body = pushMessage.senderName + "在群里@了你";
|
|
||||||
}
|
//检查key到期日期
|
||||||
} else if(pushMessage.mentionedType == 2) {
|
final Map<String, Date> inactiveDevices = service.getInactiveDevices();
|
||||||
if (StringUtils.isEmpty(pushMessage.senderName)) {
|
for (final Map.Entry<String, Date> ent : inactiveDevices.entrySet()) {
|
||||||
body = "有人在群里@了大家";
|
LOG.info("Inactive " + ent.getKey() + " at date " + ent.getValue());
|
||||||
} else {
|
|
||||||
body = pushMessage.senderName + "在群里@了大家";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
});
|
||||||
if (StringUtils.isEmpty(pushMessage.senderName)) {
|
|
||||||
title = "消息";
|
|
||||||
} else {
|
|
||||||
title = pushMessage.senderName;
|
|
||||||
}
|
|
||||||
body = pushContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String payload = APNS.newPayload().alertBody(body).badge(badge).alertTitle(title).sound(sound).build();
|
|
||||||
final ApnsNotification goodMsg = service.push(service == voipSvc ? pushMessage.getVoipDeviceToken() : pushMessage.getDeviceToken(), payload, null);
|
|
||||||
LOG.info("Message id: " + goodMsg.getIdentifier());
|
|
||||||
|
|
||||||
|
|
||||||
//检查key到期日期
|
|
||||||
final Map<String, Date> inactiveDevices = service.getInactiveDevices();
|
|
||||||
for (final Map.Entry<String, Date> ent : inactiveDevices.entrySet()) {
|
|
||||||
LOG.info("Inactive " + ent.getKey() + " at date " + ent.getValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user