1.引入依赖
<dependency>
<groupId>cn.jpush.api</groupId>
<artifactId>jpush-client</artifactId>
<version>3.3.9</version>
</dependency>
<dependency>
<groupId>cn.jpush.api</groupId>
<artifactId>jmessage-client</artifactId>
<version>1.1.7</version>
</dependency>
<dependency>
<groupId>cn.jpush.api</groupId>
<artifactId>jiguang-common</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
service 代码
public static void regPP(String username,String password) {
JMessageClient client = new JMessageClient(appKey, masterSecret);
String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret);
ApacheHttpClient httpClient = new ApacheHttpClient(authCode, null, ClientConfig.getInstance());
client.setHttpClient(httpClient);
try {
List<RegisterInfo> users = new ArrayList<RegisterInfo>();
RegisterInfo user = RegisterInfo.newBuilder()
.setUsername(username)
.setPassword(password)
.build();
users.add(user);
RegisterInfo[] regUsers = new RegisterInfo[users.size()];
String res = client.registerUsers(users.toArray(regUsers));
//LOG.info(res);
} catch (APIConnectionException e) {
// LOG.error("连接错误。请稍后重试。 ", e);
} catch (APIRequestException e) {
//LOG.error("JPush服务器的错误响应。请检查并改正。", e);
//LOG.info("网络状态: " + e.getStatus());
//LOG.info("错误信息: " + e.getMessage());
}
}
将password username 传入即可