An open API service indexing awesome lists of open source software.

https://github.com/jpush/jmessage-api-java-client

JiGuang's officially supported Java client library for accessing JMessage APIs. 极光官方支持的 Java 版本服务器端 SDK。
https://github.com/jpush/jmessage-api-java-client

Last synced: 9 months ago
JSON representation

JiGuang's officially supported Java client library for accessing JMessage APIs. 极光官方支持的 Java 版本服务器端 SDK。

Awesome Lists containing this project

README

          

[![GitHub version](https://badge.fury.io/gh/jpush%2Fjmessage-api-java-client.svg)](https://badge.fury.io/gh/jpush%2Fjmessage-api-java-client)

# JMessage API Java Library

## 概述

这是 JMessage REST API 的 Java 版本封装开发包,是由极光推送官方提供的,一般支持最新的 API 功能。

对应的 REST API 文档:

版本更新:[Release页面](https://github.com/jpush/jmessage-api-java-client/releases)。下载更新请到这里。

> 非常欢迎各位开发者提交代码,贡献一份力量,review过有效的代码将会合入本项目。

## 安装

### maven 方式
将下边的依赖条件放到你项目的 maven pom.xml 文件里。
> 其中 slf4j 可以与 logback, log4j, commons-logging 等日志框架一起工作,可根据你的需要配置使用。

```Java

cn.jpush.api
jmessage-client
1.1.9

cn.jpush.api
jiguang-common
1.1.3

com.google.code.gson
gson
2.3

org.slf4j
slf4j-api
1.7.7

org.slf4j
slf4j-log4j12
1.7.7

log4j
log4j
1.2.17

```
### jar 包方式

请到 [Release页面](https://github.com/jpush/jmessage-api-java-client/releases)下载相应版本的发布包。

### 依赖包
* [slf4j](http://www.slf4j.org/) / log4j (Logger)
* [gson](https://code.google.com/p/google-gson/) (Google JSON Utils)
* [jiguang-common](https://github.com/jpush/jiguang-java-client-common)

> 其中 slf4j 可以与 logback, log4j, commons-logging 等日志框架一起工作,可根据你的需要配置使用。

> jiguang-common 的 jar 包下载。[请点击](https://github.com/jpush/jmessage-api-java-client/releases)

## 编译源码

> 如果开发者想基于本项目做一些扩展的开发,或者想了解本项目源码,可以参考此章,否则可略过此章。

### 导入本项目

* 可以采用 `git clone https://github.com/jpush/jmessage-api-java-client.git jmessage-api-src` 命令下载源码
* 如果不使用git,请到[Release页面](https://github.com/jpush/jmessage-api-java-client/releases)下载源码包并解压
* 采用eclipse导入下载的源码工程,推荐采用maven的方式,方便依赖包的管理
* 假如采用导入普通项目的方式,项目报错,检查Build Path,Libraries
* 依赖jar包都在libs目录下可以找到,没有加入的请添加到Build Path,Libraries
* jpush-client jar包可以[点击下载](https://github.com/jpush/jpush-api-java-client/releases)
* 默认采用了log4j做日志框架,开发者可根据自己需求替换logback、commons-logging等日志框架
* 极个别情况下,如果test目录报错,请手动添加test的依赖jar包mockwebserver-2.0.0.jar、okhttp-2.0.0.jar、okio-1.0.0.jar
* 开发者需要注意,将本项目的编码格式设置为UTF-8

### 构建本项目

可以用 Eclipse 类 IDE 导出 jar 包。建议直接使用 maven,执行命令:

maven package

### 自动化测试

在项目目录下执行命令:

mvn test

## 使用样例

> 以下片断来自项目代码里的文件:example / cn.jmessage.api.examples.UserExample

```Java
public static void testGetUserInfo() {
JMessageClient client = new JMessageClient(appkey, masterSecret);
try {
String res = client.getUserInfo("test_user");
LOG.info(res);
} catch (APIConnectionException e) {
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}
```

> 以下片断来自项目代码里的文件:example / cn.jmessage.api.examples.GroupExample
```Java
public static void testCreateGroup() {
JMessageClient client = new JMessageClient(appkey, masterSecret);
try {
String res = client.createGroup("test_user", "test_gname1", "description", "test_user");
LOG.info(res);
} catch (APIConnectionException e) {
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}
```

## 贡献者列表

* [@tangyikai](https://github.com/tangyikai)