Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
黄志磊
committed
Feb 17, 2016
1 parent
376c831
commit 501506c
Showing
11 changed files
with
378 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
mpush-api/src/main/java/com/shinemo/mpush/api/payload/BasePayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,64 @@ | |||
package com.shinemo.mpush.api.payload; | |||
|
|||
|
|||
/** | |||
* msgId、msgType 必填 | |||
* msgType=1 :nofication,提醒。 | |||
* 必填:title,content。没有title,则为应用名称。 | |||
* 非必填。nid 通知id,主要用于聚合通知。 | |||
* content 为push message。附加的一些业务属性,都在里边。json格式 | |||
* msgType=2 :非通知消息。不在通知栏展示。 | |||
* 必填:content。 | |||
* msgType=3 :消息+提醒 | |||
* 作为一个push消息过去。和jpush不一样。jpush的消息和提醒是分开发送的。 | |||
* | |||
* | |||
*/ | |||
@SuppressWarnings("unchecked") | |||
public class BasePayload<T> implements Payload{ | |||
|
|||
private static final long serialVersionUID = 2367820805720853376L; | |||
/*****以下非必填**/ | |||
private Long nid; //主要用于聚合通知,非必填 | |||
private Byte flags; //特性字段。 0x01:声音 0x02:震动 0x03:闪灯 | |||
private String largeIcon; // 大图标 | |||
private String ticker; //和title一样 | |||
private Integer number; // | |||
public Long getNid() { | |||
return nid; | |||
} | |||
public T setNid(Long nid) { | |||
this.nid = nid; | |||
return (T)this; | |||
} | |||
public Byte getFlags() { | |||
return flags; | |||
} | |||
public T setFlags(Byte flags) { | |||
this.flags = flags; | |||
return (T)this; | |||
} | |||
public String getLargeIcon() { | |||
return largeIcon; | |||
} | |||
public T setLargeIcon(String largeIcon) { | |||
this.largeIcon = largeIcon; | |||
return (T)this; | |||
} | |||
public String getTicker() { | |||
return ticker; | |||
} | |||
public T setTicker(String ticker) { | |||
this.ticker = ticker; | |||
return (T)this; | |||
} | |||
public Integer getNumber() { | |||
return number; | |||
} | |||
public T setNumber(Integer number) { | |||
this.number = number; | |||
return (T)this; | |||
} | |||
|
|||
} | |||
|
26 changes: 26 additions & 0 deletions
26
mpush-api/src/main/java/com/shinemo/mpush/api/payload/CustomPushPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,26 @@ | |||
package com.shinemo.mpush.api.payload; | |||
|
|||
import java.util.HashMap; | |||
|
|||
|
|||
/** | |||
* msgId、msgType 必填 | |||
* msgType=1 :nofication,提醒。 | |||
* 必填:title,content。没有title,则为应用名称。 | |||
* 非必填。nid 通知id,主要用于聚合通知。 | |||
* content 为push message。附加的一些业务属性,都在里边。json格式 | |||
* msgType=2 :非通知消息。不在通知栏展示。 | |||
* 必填:content。 | |||
* msgType=3 :消息+提醒 | |||
* 作为一个push消息过去。和jpush不一样。jpush的消息和提醒是分开发送的。 | |||
* | |||
* | |||
*/ | |||
public class CustomPushPayload extends HashMap<String, String> implements Payload { | |||
|
|||
private static final long serialVersionUID = 6076731078625705602L; | |||
|
|||
|
|||
|
|||
} | |||
|
40 changes: 40 additions & 0 deletions
40
mpush-api/src/main/java/com/shinemo/mpush/api/payload/NotificationPushPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,40 @@ | |||
package com.shinemo.mpush.api.payload; | |||
|
|||
|
|||
/** | |||
* msgId、msgType 必填 | |||
* msgType=1 :nofication,提醒。 | |||
* 必填:title,content。没有title,则为应用名称。 | |||
* 非必填。nid 通知id,主要用于聚合通知。 | |||
* content 为push message。附加的一些业务属性,都在里边。json格式 | |||
* msgType=2 :非通知消息。不在通知栏展示。 | |||
* 必填:content。 | |||
* msgType=3 :消息+提醒 | |||
* 作为一个push消息过去。和jpush不一样。jpush的消息和提醒是分开发送的。 | |||
* | |||
* | |||
*/ | |||
public class NotificationPushPayload extends BasePayload<NotificationPushPayload> implements Payload{ | |||
|
|||
private static final long serialVersionUID = 4363667286689742483L; | |||
private String title; | |||
private String content; | |||
public String getTitle() { | |||
return title; | |||
} | |||
public NotificationPushPayload setTitle(String title) { | |||
this.title = title; | |||
return this; | |||
} | |||
public String getContent() { | |||
return content; | |||
} | |||
public NotificationPushPayload setContent(String content) { | |||
this.content = content; | |||
return this; | |||
} | |||
|
|||
|
|||
|
|||
} | |||
|
7 changes: 7 additions & 0 deletions
7
mpush-api/src/main/java/com/shinemo/mpush/api/payload/Payload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
package com.shinemo.mpush.api.payload; | |||
|
|||
import java.io.Serializable; | |||
|
|||
public interface Payload extends Serializable{ | |||
|
|||
} |
39 changes: 39 additions & 0 deletions
39
mpush-api/src/main/java/com/shinemo/mpush/api/payload/PayloadFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,39 @@ | |||
package com.shinemo.mpush.api.payload; | |||
|
|||
|
|||
/** | |||
* msgId、msgType 必填 | |||
* msgType=1 :nofication,提醒。 | |||
* 必填:title,content。没有title,则为应用名称。 | |||
* 非必填。nid 通知id,主要用于聚合通知。 | |||
* content 为push message。附加的一些业务属性,都在里边。json格式 | |||
* msgType=2 :非通知消息。不在通知栏展示。 | |||
* 必填:content。 | |||
* msgType=3 :消息+提醒 | |||
* 作为一个push消息过去。和jpush不一样。jpush的消息和提醒是分开发送的。 | |||
* | |||
* | |||
*/ | |||
@SuppressWarnings("unchecked") | |||
public class PayloadFactory{ | |||
|
|||
public static <T> T create(MessageType messageType){ | |||
|
|||
Payload payload = null; | |||
if(messageType.equals(MessageType.NOTIFICATION)){ | |||
payload = new NotificationPushPayload(); | |||
}else if(messageType.equals(MessageType.CUSTOM)){ | |||
payload = new CustomPushPayload(); | |||
} | |||
if(payload!=null){ | |||
return (T)payload; | |||
} | |||
return null; | |||
} | |||
|
|||
public enum MessageType{ | |||
NOTIFICATION,CUSTOM; | |||
} | |||
|
|||
} | |||
|
67 changes: 67 additions & 0 deletions
67
mpush-api/src/main/java/com/shinemo/mpush/api/payload/PushContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,67 @@ | |||
//package com.shinemo.mpush.api; | |||
// | |||
//import java.io.Serializable; | |||
// | |||
///** | |||
// * msgId、msgType 必填 | |||
// * msgType=1 :nofication,提醒。 | |||
// * 必填:title,content。没有title,则为应用名称。 | |||
// * 非必填。nid 通知id,主要用于聚合通知。 | |||
// * content 为push message。附加的一些业务属性,都在里边。json格式 | |||
// * msgType=2 :非通知消息。不在通知栏展示。 | |||
// * 必填:content。 | |||
// * msgType=3 :消息+提醒 | |||
// * 作为一个push消息过去。和jpush不一样。jpush的消息和提醒是分开发送的。 | |||
// * | |||
// * | |||
// */ | |||
//public final class PushContent implements Serializable{ | |||
// private static final long serialVersionUID = -1805329333995385960L; | |||
// private String msgId; //返回使用 | |||
// private String title; //没有title,则为应用名称。 | |||
// private String content; //content | |||
// private int msgType; //type | |||
// | |||
// | |||
// | |||
// public PushContent(int msgType) { | |||
// this.msgType = msgType; | |||
// } | |||
// | |||
// public static PushContent build(int msgType){ | |||
// PushContent pushContent = new PushContent(msgType); | |||
// return pushContent; | |||
// } | |||
// | |||
// public String getMsgId() { | |||
// return msgId; | |||
// } | |||
// | |||
// public String getTitle() { | |||
// return title; | |||
// } | |||
// | |||
// public String getContent() { | |||
// return content; | |||
// } | |||
// | |||
// public int getMsgType() { | |||
// return msgType; | |||
// } | |||
// | |||
// public PushContent setTitle(String title) { | |||
// this.title = title; | |||
// return this; | |||
// } | |||
// | |||
// public PushContent setContent(String content) { | |||
// this.content = content; | |||
// return this; | |||
// } | |||
// | |||
// public void setMsgId(String msgId) { | |||
// this.msgId = msgId; | |||
// } | |||
// | |||
// | |||
//} |
63 changes: 63 additions & 0 deletions
63
mpush-test/src/test/java/com/shinemo/mpush/test/gson/GsonTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,63 @@ | |||
package com.shinemo.mpush.test.gson; | |||
|
|||
import java.util.Map; | |||
|
|||
import org.junit.Test; | |||
import com.google.common.collect.Maps; | |||
import com.google.gson.JsonObject; | |||
import com.shinemo.mpush.api.PushContent; | |||
import com.shinemo.mpush.tools.Jsons; | |||
|
|||
public class GsonTest { | |||
|
|||
@Test | |||
public void test(){ | |||
Map<String,String> map = Maps.newHashMap(); | |||
map.put("key1", 1121+""); | |||
map.put("key2", "value2"); | |||
|
|||
PushContent content = PushContent.build(1,Jsons.toJson(map)); | |||
|
|||
|
|||
System.out.println(Jsons.toJson(content)); | |||
|
|||
} | |||
|
|||
@Test | |||
public void test2(){ | |||
ValueMap map = new ValueMap("1122", "value2"); | |||
|
|||
PushContent content = PushContent.build(1,Jsons.toJson(map)); | |||
|
|||
|
|||
System.out.println(Jsons.toJson(content)); | |||
|
|||
PushContent newContetn = Jsons.fromJson(Jsons.toJson(content), PushContent.class); | |||
|
|||
System.out.println(newContetn.getContent()); | |||
|
|||
|
|||
} | |||
|
|||
private static class ValueMap{ | |||
|
|||
private String key1; | |||
private String key2; | |||
|
|||
public ValueMap(String key1, String key2) { | |||
this.key1 = key1; | |||
this.key2 = key2; | |||
} | |||
|
|||
public String getKey1() { | |||
return key1; | |||
} | |||
|
|||
public String getKey2() { | |||
return key2; | |||
} | |||
|
|||
|
|||
} | |||
|
|||
} |
Oops, something went wrong.