极光推送

This commit is contained in:
wuchunlei
2025-09-08 09:49:34 +08:00
parent d6d594b82b
commit 35f0cc51e2
4 changed files with 108 additions and 0 deletions

View File

@@ -63,6 +63,12 @@
</dependencies>
</dependencyManagement>
<dependencies>
<!-- 极光推送 -->
<dependency>
<groupId>io.github.jpush</groupId>
<artifactId>jiguang-sdk</artifactId>
<version>5.2.3</version>
</dependency>
<!-- markdown字符串转html -->
<dependency>
<groupId>com.vladsch.flexmark</groupId>

View File

@@ -0,0 +1,47 @@
package com.peanut.config;
import cn.jiguang.sdk.api.*;
import feign.Logger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.net.InetSocketAddress;
import java.net.Proxy;
@Slf4j
@Configuration
public class JiguangApiConfig {
@Value("${jiguang.api.app-key}")
private String appKey;
@Value("${jiguang.api.master-secret}")
private String masterSecret;
@Bean
public PushApi pushApi() {
okhttp3.OkHttpClient okHttpClient = new okhttp3.OkHttpClient().newBuilder()
// 自定义proxy其他设置参考https://square.github.io/okhttp/5.x/okhttp/okhttp3/-ok-http-client/-builder/index.html
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy_host", 8000)))
.build();
return new PushApi.Builder()
// .setClient(new feign.okhttp.OkHttpClient(okHttpClient)) // sdk默认使用的feign-okhttp可自定义可选
// .setOptions(new Request.Options(10, TimeUnit.SECONDS, 60, TimeUnit.SECONDS, true)) // 可自定义超时参数,可选
// .setRetryer(new Retryer.Default(100, SECONDS.toMillis(1), 5)) // 可自定义重试参数,可选
// .setLoggerLevel(Logger.Level.FULL) // 可自定义日志打印级别,可选
.setAppKey(appKey) // 必填
.setMasterSecret(masterSecret) // 必填
.setLoggerLevel(Logger.Level.FULL)
.build();
}
@Bean
public DeviceApi deviceApi() {
return new DeviceApi.Builder()
.setAppKey(appKey)
.setMasterSecret(masterSecret)
.build();
}
}

View File

@@ -0,0 +1,51 @@
package com.peanut.modules.common.controller;
import cn.jiguang.sdk.api.PushApi;
import cn.jiguang.sdk.bean.push.PushSendParam;
import cn.jiguang.sdk.bean.push.PushSendResult;
import cn.jiguang.sdk.bean.push.audience.Audience;
import cn.jiguang.sdk.bean.push.message.notification.NotificationMessage;
import cn.jiguang.sdk.constants.ApiConstants;
import com.peanut.common.utils.R;
import com.peanut.common.utils.ShiroUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
@Slf4j
@RestController("commonJiGuangPush")
@RequestMapping("common/jiGuangPush")
public class JiGuangPushController {
@Autowired
private PushApi pushApi;
//推送测试
@RequestMapping("/sendTest")
public R sendTest(){
PushSendParam param = new PushSendParam();
// 通知内容
NotificationMessage.Android android = new NotificationMessage.Android();
android.setAlert("this is android alert");
android.setTitle("this is android title");
NotificationMessage notificationMessage = new NotificationMessage();
notificationMessage.setAlert("this is alert");
notificationMessage.setAndroid(android);
param.setNotification(notificationMessage);
// 目标人群
Audience audience = new Audience();
audience.setAliasList(Arrays.asList(ShiroUtils.getUId()+""));
param.setAudience(audience);
// param.setAudience(ApiConstants.Audience.ALL);
// 指定平台
// param.setPlatform(Arrays.asList(Platform.android));
param.setPlatform(ApiConstants.Platform.ALL);
// 发送
PushSendResult result = pushApi.send(param);
return R.ok().put("result",result);
}
}

View File

@@ -126,4 +126,8 @@ ragflow:
url: http://125.39.141.154:81
authorization: Bearer ragflow-A5NTQzNGVlMzE2NjExZjBiZjk3MTZlZm
jiguang:
api:
app-key: 215f72f1b85f4028404addb3
master-secret: bae0c6a0b57419c018cef53a