1 changed files with 39 additions and 0 deletions
@ -0,0 +1,39 @@ |
|||
package cc.hiver.core.serviceimpl; |
|||
|
|||
import cc.hiver.core.service.JPushService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import cn.jpush.api.JPushClient; |
|||
import cn.jpush.api.push.PushResult; |
|||
import cn.jpush.api.push.model.PushPayload; |
|||
import cn.jpush.api.push.model.notification.Notification; |
|||
|
|||
@Service |
|||
public class JPushServiceImpl implements JPushService { |
|||
|
|||
@Autowired |
|||
private JPushClient jPushClient; |
|||
|
|||
@Autowired |
|||
public JPushServiceImpl(JPushClient jPushClient) { |
|||
this.jPushClient = jPushClient; |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public void sendPushNotification(String registrationId, String message) { |
|||
PushPayload payload = PushPayload.newBuilder() |
|||
.setPlatform(cn.jpush.api.push.model.Platform.all()) |
|||
.setAudience(cn.jpush.api.push.model.audience.Audience.registrationId(registrationId)) |
|||
.setNotification(Notification.alert(message)) |
|||
.build(); |
|||
|
|||
try { |
|||
PushResult result = jPushClient.sendPush(payload); |
|||
System.out.println("Push result: " + result); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue