Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pengyuantao committed May 26, 2017
0 parents commit 7cc67c4
Show file tree
Hide file tree
Showing 144 changed files with 5,769 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
@@ -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 added OnePushService/libs/MiPush_SDK_Server_2_2_18.jar
Binary file not shown.
Binary file not shown.
Binary file added OnePushService/libs/commons-codec-1.8.jar
Binary file not shown.
Binary file added OnePushService/libs/commons-io-2.4.jar
Binary file not shown.
Binary file added OnePushService/libs/commons-logging-1.1.3.jar
Binary file not shown.
Binary file added OnePushService/libs/fastjson-1.1.32.jar
Binary file not shown.
Binary file added OnePushService/libs/fluent-hc-4.3.3.jar
Binary file not shown.
Binary file added OnePushService/libs/httpclient-4.3.3.jar
Binary file not shown.
Binary file added OnePushService/libs/httpclient-cache-4.3.3.jar
Binary file not shown.
Binary file added OnePushService/libs/httpcore-4.3.2.jar
Binary file not shown.
Binary file added OnePushService/libs/httpmime-4.3.3.jar
Binary file not shown.
Binary file added OnePushService/libs/json-simple-1.1.1.jar
Binary file not shown.
Binary file added OnePushService/libs/logback-classic-1.0.13.jar
Binary file not shown.
Binary file added OnePushService/libs/logback-core-1.0.13.jar
Binary file not shown.
Binary file added OnePushService/libs/slf4j-api-1.7.5.jar
Binary file not shown.
Binary file added OnePushService/mykeystorebj.jks
Binary file not shown.
15 changes: 15 additions & 0 deletions OnePushService/src/com/peng/one/push/service/Constant.java
@@ -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==";

}
113 changes: 113 additions & 0 deletions OnePushService/src/com/peng/one/push/service/Main.java
@@ -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);
}


}
@@ -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);


}
@@ -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;
}

}

}

0 comments on commit 7cc67c4

Please sign in to comment.