极光推送
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user