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
0 parents
commit 7cc67c4
Showing
144 changed files
with
5,769 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
gradle.properties | ||
/gradlew | ||
/gradlew.bat | ||
/release.keystore |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
OnePushService/src/com/peng/one/push/service/Constant.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.peng.one.push.service; | ||
|
||
/** | ||
* 常量区 | ||
* Created by Administrator on 2017/5/17. | ||
*/ | ||
public interface Constant { | ||
|
||
//TODO: 请自己修改对应的推送ID | ||
String HAWEI_APP_ID = "000000000000000000000"; | ||
String HUAWEI_APP_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"; | ||
|
||
String XIAOMI_APP_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxx=="; | ||
|
||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package com.peng.one.push.service; | ||
|
||
import com.peng.one.push.service.core.IPushService; | ||
import com.peng.one.push.service.core.entity.MessageEntity; | ||
import com.peng.one.push.service.core.entity.NotificationEntity; | ||
import com.peng.one.push.service.huawei.HuaweiService; | ||
import com.peng.one.push.service.huawei.intent.HWPushIntent; | ||
import com.peng.one.push.service.xiaomi.XiaomiService; | ||
|
||
import java.util.HashMap; | ||
|
||
/** | ||
* Created by Administrator on 2017/5/17. | ||
*/ | ||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
NotificationEntity.Builder notificationBuilder = new NotificationEntity.Builder(); | ||
NotificationEntity notificationEntity = notificationBuilder | ||
// .tokens("oiDmX2DFrSkuU5DQ7RVE3JD6CB6N5ZJ/uRoPMPIONTk=") | ||
.doing(NotificationEntity.DOING_CLIENT_CUSTOM) | ||
.extra("[{\"orderId\":\"9385-0094-4432-2432-5554-3424\"}]") | ||
.title("OnePush通知标题") | ||
.content("通知-->你只需要这一个推送SDK----OnePush") | ||
.tags("test") | ||
// .aliases("test") | ||
.keyValue("key_1", "value_1") | ||
.keyValue("key_2", "value_2") | ||
.build(); | ||
|
||
MessageEntity.Builder MessageBuilder = new MessageEntity.Builder(); | ||
MessageEntity messageEntity = MessageBuilder | ||
// .tokens("oiDmX2DFrSkuU5DQ7RVE3JD6CB6N5ZJ/uRoPMPIONTk=") | ||
.extra("[{\"orderId\":\"9385-0094-4432-2432-5554-3424\"}]") | ||
.tags("test") | ||
// .aliases("test") | ||
.msg("透传-->你只需要这一个推送SDK----OnePush") | ||
.keyValue("key_1", "value_1") | ||
.keyValue("key_2", "value_2") | ||
.build(); | ||
|
||
IPushService huaweiService = new HuaweiService(); | ||
IPushService xiaomiService = new XiaomiService(); | ||
|
||
HWPushIntent.Builder builder = new HWPushIntent.Builder(); | ||
|
||
HashMap<String, String> keyValueMap = new HashMap<>(); | ||
keyValueMap.put("key1", "value1"); | ||
keyValueMap.put("key2", "value2"); | ||
keyValueMap.put("key3", "value3"); | ||
String s = builder.title("标题").content("通知内容").extraMsg("额外信息") | ||
.keyValue(keyValueMap).build().toString(); | ||
System.out.println(s); | ||
|
||
try { | ||
//发送通知-->小米 | ||
sendNotification(notificationEntity, xiaomiService); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
try { | ||
//发送透传-->小米 | ||
sendMessage(messageEntity, xiaomiService); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
try { | ||
//发送通知-->华为 | ||
sendNotification(notificationEntity, huaweiService); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
try { | ||
//发送透传-->华为(由于华为PUSH_SDK透传的特殊性,必须制定token) | ||
sendMessage(new MessageEntity.Builder() | ||
.tokens("0a000005984ecae0300000463600CN01") | ||
.extra("[{\"orderId\":\"9385-0094-4432-2432-5554-3424\"}]") | ||
.msg("透传-->你只需要这一个推送SDK----OnePush") | ||
.keyValue("key_1", "value_1") | ||
.keyValue("key_2", "value_2") | ||
.build(), huaweiService); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
|
||
} | ||
|
||
/** | ||
* 发送通知 | ||
* | ||
* @param notificationEntity | ||
* @param pushService | ||
*/ | ||
public static void sendNotification(NotificationEntity notificationEntity, IPushService pushService) { | ||
pushService.sendNotification(notificationEntity); | ||
} | ||
|
||
/** | ||
* 发送消息 | ||
* | ||
* @param messageEntity | ||
* @param pushService | ||
*/ | ||
public static void sendMessage(MessageEntity messageEntity, IPushService pushService) { | ||
pushService.sendMessage(messageEntity); | ||
} | ||
|
||
|
||
} |
28 changes: 28 additions & 0 deletions
28
OnePushService/src/com/peng/one/push/service/core/IPushService.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.peng.one.push.service.core; | ||
|
||
import com.peng.one.push.service.core.entity.MessageEntity; | ||
import com.peng.one.push.service.core.entity.NotificationEntity; | ||
import com.peng.one.push.service.core.entity.OneResponse; | ||
|
||
/** | ||
* 推送服务的统一的接口 | ||
* Created by Administrator on 2017/5/16. | ||
*/ | ||
public interface IPushService { | ||
|
||
/** | ||
* 发送通知栏消息 | ||
* @param notificationEntity | ||
* @return | ||
*/ | ||
OneResponse sendNotification(NotificationEntity notificationEntity); | ||
|
||
/** | ||
* 发送透传消息 | ||
* @param messageEntity | ||
* @return | ||
*/ | ||
OneResponse sendMessage(MessageEntity messageEntity); | ||
|
||
|
||
} |
152 changes: 152 additions & 0 deletions
152
OnePushService/src/com/peng/one/push/service/core/entity/MessageEntity.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package com.peng.one.push.service.core.entity; | ||
|
||
import org.apache.http.util.TextUtils; | ||
|
||
/** | ||
* 透传消息实体类 | ||
* Created by Administrator on 2017/5/17. | ||
*/ | ||
public class MessageEntity { | ||
|
||
private String msg; | ||
|
||
private String extra; | ||
|
||
private Map<String, String> keyValue; | ||
|
||
private List<String> tokens; | ||
|
||
private List<String> aliases; | ||
|
||
private List<String> tags; | ||
|
||
public String getMsg() { | ||
return msg; | ||
} | ||
|
||
public void setMsg(String msg) { | ||
this.msg = msg; | ||
} | ||
|
||
public String getExtra() { | ||
return extra; | ||
} | ||
|
||
public void setExtra(String extra) { | ||
this.extra = extra; | ||
} | ||
|
||
public Map<String, String> getKeyValue() { | ||
return keyValue; | ||
} | ||
|
||
public void setKeyValue(Map<String, String> keyValue) { | ||
this.keyValue = keyValue; | ||
} | ||
|
||
public List<String> getTokens() { | ||
return tokens; | ||
} | ||
|
||
public void setTokens(List<String> tokens) { | ||
this.tokens = tokens; | ||
} | ||
|
||
public List<String> getAliases() { | ||
return aliases; | ||
} | ||
|
||
public void setAliases(List<String> aliases) { | ||
this.aliases = aliases; | ||
} | ||
|
||
public List<String> getTags() { | ||
return tags; | ||
} | ||
|
||
public void setTags(List<String> tags) { | ||
this.tags = tags; | ||
} | ||
|
||
public static class Builder{ | ||
|
||
private String msg; | ||
|
||
private String extra; | ||
|
||
private Map<String, String> keyValue; | ||
|
||
private List<String> tokens; | ||
|
||
private List<String> aliases; | ||
|
||
private List<String> tags; | ||
|
||
public Builder msg(String msg) { | ||
if (TextUtils.isEmpty(msg)) { | ||
throw new IllegalArgumentException("you through message param msg is null!" ); | ||
} | ||
this.msg = msg; | ||
return this; | ||
} | ||
|
||
public Builder extra(String extra) { | ||
this.extra = extra; | ||
return this; | ||
} | ||
|
||
public Builder tokens(String... tokens) { | ||
if (tokens.length == 0) { | ||
throw new IllegalArgumentException("you tokens is null"); | ||
} | ||
if (this.tokens == null || this.tokens.isEmpty()) { | ||
this.tokens = new ArrayList<String>(); | ||
} | ||
this.tokens.addAll(Arrays.asList(tokens)); | ||
return this; | ||
} | ||
|
||
public Builder aliases(String... aliases) { | ||
if (aliases.length == 0) { | ||
throw new IllegalArgumentException("you aliases is null"); | ||
} | ||
if (this.aliases == null || this.aliases.isEmpty()) { | ||
this.aliases = new ArrayList<String>(); | ||
} | ||
this.aliases.addAll(Arrays.asList(aliases)); | ||
return this; | ||
} | ||
|
||
public Builder tags(String... tags) { | ||
if (tags.length == 0) { | ||
throw new IllegalArgumentException("you tags is null"); | ||
} | ||
if (this.tags == null || this.tags.isEmpty()) { | ||
this.tags = new ArrayList<String>(); | ||
} | ||
this.tags.addAll(Arrays.asList(tags)); | ||
return this; | ||
} | ||
|
||
public Builder keyValue(String key, String value) { | ||
if (this.keyValue == null) { | ||
this.keyValue = new HashMap<>(); | ||
} | ||
this.keyValue.put(key, value); | ||
return this; | ||
} | ||
|
||
public MessageEntity build(){ | ||
MessageEntity messageEntity = new MessageEntity(); | ||
messageEntity.msg = this.msg; | ||
messageEntity.extra = this.extra; | ||
messageEntity.tokens = this.tokens; | ||
messageEntity.aliases = this.aliases; | ||
messageEntity.tags = this.tags; | ||
messageEntity.keyValue = this.keyValue; | ||
return messageEntity; | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.