|
|
@@ -13,6 +13,7 @@ import org.springframework.beans.factory.InitializingBean;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
|
+import com.goafanti.common.model.JtMessageProducer;
|
|
|
import com.goafanti.common.utils.LoggerUtils;
|
|
|
import com.goafanti.message.bo.MessageAdapter;
|
|
|
import com.goafanti.message.bo.MessageBo;
|
|
|
@@ -50,6 +51,7 @@ public class JGMessageHelper implements InitializingBean, DisposableBean{
|
|
|
private static final Logger logger = LoggerFactory.getLogger(JGMessageHelper.class);
|
|
|
private static final int MAX_TRYCOUNT = 3;
|
|
|
private static final String MESSAGE_ID = "message_id";//消息ID
|
|
|
+ private static final String MESSAGE_BODY = "message_body";//消息ID
|
|
|
private static final String RESOURCE_ID = "resource_id";//资源ID
|
|
|
private static final String RESOURCE_TYPE = "resource_type";//资源类型
|
|
|
public void send(MessageAdapter messageAdapter){
|
|
|
@@ -115,6 +117,32 @@ public class JGMessageHelper implements InitializingBean, DisposableBean{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void sendPushMessage(JtMessageProducer mp){
|
|
|
+ MessageAdapter ma = new MessageAdapter();
|
|
|
+ if(mp !=null&&StringUtils.isNotBlank(mp.getId())){
|
|
|
+ ma.pushPayload(PushPayload.newBuilder()
|
|
|
+ .setPlatform(Platform.android_ios())
|
|
|
+ .setAudience(Audience.all())
|
|
|
+ .setNotification(Notification.newBuilder()
|
|
|
+ .setAlert(mp.getTitle())
|
|
|
+ .addPlatformNotification(AndroidNotification.newBuilder()
|
|
|
+ .addExtra(MESSAGE_ID, mp.getId())
|
|
|
+ .addExtra(MESSAGE_BODY, mp.getBody())
|
|
|
+ .addExtra(RESOURCE_ID, mp.getResourceId() == null ? "" : mp.getResourceId())
|
|
|
+ .addExtra(RESOURCE_TYPE, mp.getResourceType() == null ? "":mp.getResourceType().toString()).build())
|
|
|
+ .addPlatformNotification(IosNotification.newBuilder()
|
|
|
+ .incrBadge(1)
|
|
|
+ .setContentAvailable(true)
|
|
|
+ .addExtra(MESSAGE_ID, mp.getId())
|
|
|
+ .addExtra(MESSAGE_BODY, mp.getBody())
|
|
|
+ .addExtra(RESOURCE_ID, mp.getResourceId() == null ? "" : mp.getResourceId())
|
|
|
+ .addExtra(RESOURCE_TYPE, mp.getResourceType()== null ? "": mp.getResourceType().toString()).build())
|
|
|
+ .build())
|
|
|
+ .build());
|
|
|
+ send(ma);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void sendSystemMessage(MessageBo... mb){
|
|
|
for(MessageBo bo : mb){
|
|
|
sendSystemMessage(bo);
|
|
|
@@ -142,10 +170,7 @@ public class JGMessageHelper implements InitializingBean, DisposableBean{
|
|
|
MessageAdapter ma = new MessageAdapter().pushPayload(
|
|
|
PushPayload.newBuilder()
|
|
|
.setPlatform(Platform.android_ios())
|
|
|
- .setAudience(Audience.newBuilder()
|
|
|
- .addAudienceTarget(
|
|
|
- AudienceTarget.registrationId("101d8559094270e0d78"))
|
|
|
- .build())
|
|
|
+ .setAudience(Audience.all())
|
|
|
.setNotification(Notification.newBuilder()
|
|
|
.setAlert("消息标题")
|
|
|
.addPlatformNotification(AndroidNotification.newBuilder()
|