Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/easemob/easemob-push-server-sdk
https://github.com/easemob/easemob-push-server-sdk
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/easemob/easemob-push-server-sdk
- Owner: easemob
- Created: 2022-06-21T07:02:10.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-11-29T07:08:09.000Z (11 months ago)
- Last Synced: 2024-04-13T16:05:27.420Z (7 months ago)
- Language: Java
- Size: 273 KB
- Stars: 4
- Watchers: 7
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Easemob PUSH SDK for Java
为使用环信服务端推送提供便捷。
## 准备
### 获取环信 appKey, clientId, clientSecret
如果您有环信管理后台账号并创建过应用,请进入 [这里](https://console.easemob.com/user/login) 进行登录。
![图片](https://user-images.githubusercontent.com/15087647/114996679-a34cb980-9ed1-11eb-89ae-a22c1af7d69d.png)
如图点击查看后,可以看到自己的 appkey、Client ID、ClientSecret,用于 SDK 的初始化。
如果您没有环信管理后台账号,请进入 [这里](https://console.easemob.com/user/register) 进行注册账号,注册成功后请进行登录。
![图片](https://user-images.githubusercontent.com/15087647/114997381-59180800-9ed2-11eb-968a-a29406c78021.png)
如图先添加应用(也就是创建 appkey,自动生成 Client ID、ClientSecret),添加成功后在应用列表中可以看到应用信息,点击查看可以看到自己的 appkey、Client
ID、ClientSecret,用于 SDK 的初始化。## 依赖
### Maven
如果你的项目使用 Maven 构建,在 pom.xml 中添加下面代码即可:
[版本链接](https://search.maven.org/search?q=g:com.easemob.im%20AND%20a:push-sdk-api)``` xml
com.easemob.im
push-sdk-api
${version}```
### Gradle
如果你的项目使用 Gradle 构建,可以在 build.grade 中添加下面代码:
``` gradle
implementation 'com.easemob.im:push-sdk-api:${version}'
```## [JAVA DOCS](https://easemob.github.io/easemob-push-server-sdk/)
### 1、初始化EmPushService
注意: 无特殊需求 EMPushService 上下文中可为单例
``` java
EmPushProperties emPushProperties=EmPushProperties.builder()
.setProtocol(EmPushProperties.Protocol.HTTPS)
.setCredentials(EasemobAppCredentials.of("client_id","client_secret"))
.setAppKey("appkey")
.build();EMPushService emPushService=new EMPushService(emPushProperties);
```### 2、API 调用
``` java
//推送特性配置内容,详见:https://docs-im.easemob.com/push/apppush/pushkv
PushMessage pushMessage = PushMessage.builder()
.title("环信")
.content("欢迎使用环信推送服务")
.config(Config.builder()
.clickAction(
ClickAction.builder().url("https://www.easemob.com").build()
)
.badge(
Badge.builder().addNum(1).activity("com.xxx.activity").build()
)
.build()
)
.build();
EMPushHttpResponse eMPushHttpResponse = emPushService.push().single(
PushRequest.builder()
.setTargets(Collections.singletonList("username"))
.setPushMessage(pushMessage)
.build()
);
```