diff --git a/pom.xml b/pom.xml
index 3efab121..d581c063 100644
--- a/pom.xml
+++ b/pom.xml
@@ -42,7 +42,7 @@
cn.jpush.api
jiguang-common
- 1.0.8
+ 1.0.9
org.apache.httpcomponents
diff --git a/src/main/java/cn/jpush/api/JPushConfig.java b/src/main/java/cn/jpush/api/JPushConfig.java
new file mode 100644
index 00000000..930e1e72
--- /dev/null
+++ b/src/main/java/cn/jpush/api/JPushConfig.java
@@ -0,0 +1,39 @@
+package cn.jpush.api;
+
+import cn.jiguang.common.ClientConfig;
+
+public class JPushConfig {
+
+ private static ClientConfig clientConfig = ClientConfig.getInstance();
+
+ private static JPushConfig instance = new JPushConfig();
+
+ public static final String ADMIN_HOST_NAME = "api.admin.host.name";
+ public static final String V1_APP_PATH = "jpush.v1.app.path";
+
+ private JPushConfig() {
+ clientConfig.put(ADMIN_HOST_NAME, "https://admin.jpush.cn");
+ clientConfig.put(V1_APP_PATH, "/v1/app");
+ }
+
+ public static JPushConfig getInstance() {
+ return instance;
+ }
+
+ public ClientConfig getClientConfig() {
+ return clientConfig;
+ }
+
+ public JPushConfig setAdminHostName(String hostName) {
+ clientConfig.put(ADMIN_HOST_NAME, hostName);
+ return this;
+ }
+
+ public void put(String key, Object value) {
+ clientConfig.put(key, value);
+ }
+
+ public Object get(String key) {
+ return clientConfig.get(key);
+ }
+}
diff --git a/src/main/java/cn/jpush/api/admin/AdminClient.java b/src/main/java/cn/jpush/api/admin/AdminClient.java
new file mode 100644
index 00000000..76bdbebd
--- /dev/null
+++ b/src/main/java/cn/jpush/api/admin/AdminClient.java
@@ -0,0 +1,92 @@
+package cn.jpush.api.admin;
+
+import cn.jiguang.common.ServiceHelper;
+import cn.jiguang.common.connection.HttpProxy;
+import cn.jiguang.common.connection.IHttpClient;
+import cn.jiguang.common.connection.NativeHttpClient;
+import cn.jiguang.common.resp.APIConnectionException;
+import cn.jiguang.common.resp.APIRequestException;
+import cn.jiguang.common.resp.DefaultResult;
+import cn.jiguang.common.resp.ResponseWrapper;
+import cn.jiguang.common.utils.Preconditions;
+import cn.jpush.api.JPushConfig;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+
+/**
+ * Admin APIs
+ * https://docs.jiguang.cn/jpush/server/push/rest_api_admin_api_v1/
+ */
+public class AdminClient {
+
+ private IHttpClient mHttpClient;
+ private String mBasePath;
+ private String mV1AppPath;
+ private Gson mGson = new Gson();
+
+ /**
+ * Create a Push Client.
+ *
+ * @param appKey The KEY of one application on JPush.
+ * @param masterSecret API access secret of the appKey.
+ */
+ public AdminClient(String appKey, String masterSecret) {
+ this(appKey, masterSecret, null, JPushConfig.getInstance());
+ }
+
+ public AdminClient(String appKey, String masterSecret, HttpProxy proxy) {
+ this(appKey, masterSecret, proxy, JPushConfig.getInstance());
+ }
+
+
+ public AdminClient(String appKey, String masterSecret, HttpProxy proxy, JPushConfig conf) {
+ ServiceHelper.checkBasic(appKey, masterSecret);
+ mBasePath = (String) conf.get(JPushConfig.ADMIN_HOST_NAME);
+ mV1AppPath = (String) conf.get(JPushConfig.V1_APP_PATH);
+ String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret);
+ this.mHttpClient = new NativeHttpClient(authCode, proxy, conf.getClientConfig());
+ }
+
+ public void setHttpClient(IHttpClient client) {
+ this.mHttpClient = client;
+ }
+
+ /**
+ * Create an app under developer account
+ * @param appName app name
+ * @param packageName android package name
+ * @param groupName developer app group name
+ * @return {@link CreateAppResult}
+ * @throws APIConnectionException connect exception
+ * @throws APIRequestException request exception
+ */
+ public CreateAppResult createApp(String appName, String packageName, String groupName)
+ throws APIConnectionException, APIRequestException {
+ Preconditions.checkArgument(null != appName, "app name should not be null");
+ Preconditions.checkArgument(null != packageName, "package name should not be null");
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("app_name", appName);
+ jsonObject.addProperty("android_package", packageName);
+ if (null != groupName) {
+ jsonObject.addProperty("group_name", groupName);
+ }
+ ResponseWrapper responseWrapper = mHttpClient.sendPost(mBasePath + mV1AppPath, mGson.toJson(jsonObject));
+ return CreateAppResult.fromResponse(responseWrapper, CreateAppResult.class);
+ }
+
+ /**
+ * Delete app by app key
+ * @param appKey app key
+ * @return {@link AppResult}
+ * @throws APIConnectionException connect exception
+ * @throws APIRequestException request exception
+ */
+ public AppResult deleteApp(String appKey) throws APIConnectionException, APIRequestException {
+ ResponseWrapper responseWrapper = mHttpClient.sendDelete(mBasePath + mV1AppPath + "/" + appKey + "/delete");
+ return DefaultResult.fromResponse(responseWrapper, AppResult.class);
+ }
+
+// public AppResult uploadCertificate(String appKey) throws APIConnectionException, APIRequestException {
+//
+// }
+}
diff --git a/src/main/java/cn/jpush/api/admin/AppResult.java b/src/main/java/cn/jpush/api/admin/AppResult.java
new file mode 100644
index 00000000..8b22e585
--- /dev/null
+++ b/src/main/java/cn/jpush/api/admin/AppResult.java
@@ -0,0 +1,13 @@
+package cn.jpush.api.admin;
+
+import cn.jiguang.common.resp.BaseResult;
+import com.google.gson.annotations.Expose;
+
+public class AppResult extends BaseResult {
+
+ @Expose private String success;
+
+ public String getSuccess() {
+ return success;
+ }
+}
diff --git a/src/main/java/cn/jpush/api/admin/CreateAppResult.java b/src/main/java/cn/jpush/api/admin/CreateAppResult.java
new file mode 100644
index 00000000..64846452
--- /dev/null
+++ b/src/main/java/cn/jpush/api/admin/CreateAppResult.java
@@ -0,0 +1,22 @@
+package cn.jpush.api.admin;
+
+import cn.jiguang.common.resp.BaseResult;
+import com.google.gson.annotations.Expose;
+
+public class CreateAppResult extends BaseResult {
+ @Expose private String app_key;
+ @Expose private boolean is_new_created;
+ @Expose private String android_package;
+
+ public String getApp_key() {
+ return app_key;
+ }
+
+ public boolean is_new_created() {
+ return is_new_created;
+ }
+
+ public String getAndroid_package() {
+ return android_package;
+ }
+}
diff --git a/src/main/java/cn/jpush/api/report/MessagesResult.java b/src/main/java/cn/jpush/api/report/MessagesResult.java
index 2a2a2b98..e21a910e 100644
--- a/src/main/java/cn/jpush/api/report/MessagesResult.java
+++ b/src/main/java/cn/jpush/api/report/MessagesResult.java
@@ -19,7 +19,7 @@ public class MessagesResult extends BaseResult {
public static class Message {
@Expose
- public long msg_id;
+ public String msg_id;
@Expose
public Android android;
@Expose
@@ -47,13 +47,13 @@ public static class Ios {
@Expose
public int apns_target;
@Expose
+ public int apns_received;
+ @Expose
public int click;
@Expose
public int target;
@Expose
public int received;
- @Expose
- public int msg_click;
}
public static class Winphone {
diff --git a/src/main/java/cn/jpush/api/report/ReceivedsResult.java b/src/main/java/cn/jpush/api/report/ReceivedsResult.java
index 757ae984..a6745ecd 100644
--- a/src/main/java/cn/jpush/api/report/ReceivedsResult.java
+++ b/src/main/java/cn/jpush/api/report/ReceivedsResult.java
@@ -26,6 +26,8 @@ public static class Received {
@Expose
public int ios_apns_sent;
@Expose
+ public int ios_apns_received;
+ @Expose
public int ios_msg_received;
@Expose
public int wp_mpns_sent;
diff --git a/src/test/java/cn/jpush/api/BaseTest.java b/src/test/java/cn/jpush/api/BaseTest.java
index 17d65dda..14aebb88 100644
--- a/src/test/java/cn/jpush/api/BaseTest.java
+++ b/src/test/java/cn/jpush/api/BaseTest.java
@@ -5,7 +5,7 @@
public abstract class BaseTest {
protected static final String APP_KEY = "d4ee2375846bc30fa51334f5";
- protected static final String MASTER_SECRET = "cfb11ca45888cdd6388483f5";
+ protected static final String MASTER_SECRET = "3f045fd404d09a8a1f38d791";
protected static final String GROUP_MASTER_SECRET = "b11314807507e2bcfdeebe2e";
protected static final String GROUP_PUSH_KEY = "2c88a01e073a0fe4fc7b167c";
diff --git a/src/test/java/cn/jpush/api/device/DeviceNormalRemoteTest.java b/src/test/java/cn/jpush/api/device/DeviceNormalRemoteTest.java
index 17d9e501..d21bf09c 100644
--- a/src/test/java/cn/jpush/api/device/DeviceNormalRemoteTest.java
+++ b/src/test/java/cn/jpush/api/device/DeviceNormalRemoteTest.java
@@ -31,16 +31,16 @@ public void testUpdateDeviceTagAlias_add_remove_tags() throws APIConnectionExcep
tagsToAdd.add("tag1");
tagsToAdd.add("tag2");
Set tagsToRemove = new HashSet();
- tagsToRemove.add("tag3");
- tagsToRemove.add("tag4");
- DefaultResult result = jpushClient.updateDeviceTagAlias(REGISTRATION_ID1, "alias1", tagsToAdd, tagsToRemove);
+ tagsToRemove.add("tag1");
+ tagsToRemove.add("tag2");
+ DefaultResult result = jpushClient.updateDeviceTagAlias(REGISTRATION_ID3, "alias1", tagsToAdd, tagsToRemove);
assertTrue(result.isResultOK());
}
@Test
@TestOrder(order = 110)
public void testGetDeviceTagAlias_1() throws Exception {
- TagAliasResult result = jpushClient.getDeviceTagAlias(REGISTRATION_ID1);
+ TagAliasResult result = jpushClient.getDeviceTagAlias(REGISTRATION_ID3);
assertTrue(result.isResultOK());
assertEquals("alias not equals", "alias1", result.alias);
@@ -92,10 +92,8 @@ public void testAddRemoveDevicesFromTag() throws APIConnectionException, APIRequ
@Test
@TestOrder(order = 210)
public void testIsDeviceInTag() throws APIConnectionException, APIRequestException {
- BooleanResult result = jpushClient.isDeviceInTag("tag3", REGISTRATION_ID1);
+ BooleanResult result = jpushClient.isDeviceInTag("tag2", REGISTRATION_ID3);
assertTrue("", result.result);
- result = jpushClient.isDeviceInTag("tag3", REGISTRATION_ID2);
- assertFalse("", result.result);
}
@Test