/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.ifish.helper; import cn.jpush.api.JPushClient; import cn.jpush.api.push.PushResult; import cn.jpush.api.push.model.Platform; import cn.jpush.api.push.model.PushPayload; import cn.jpush.api.push.model.audience.Audience; import cn.jpush.api.push.model.notification.Notification; import java.util.Map; import org.springframework.stereotype.Component; /** * * @author Administrator */ @Component public class JpushHelper implements JpushHelperI { private static JPushClient jPushClient = null; //正式 // private static final String masterSecret = "60162c8cf195ce9f4dc76629"; // private static final String appKey = "d970d5e193cb2a0bbe41653c"; //测试 private final static String masterSecret = "4f759a0609dcd9d2edb06125"; private final static String appKey = "6e5e9d757570859b3f274bb8"; static { jPushClient = new JPushClient(masterSecret, appKey); } /** * 向安卓手机推送一条信息 * * @param message * @return */ @Override public boolean pushMessageByAndroid(String title, String message, String userId, Map map) { try { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.android()) .setAudience(Audience.alias(userId)) .setNotification(Notification.android(title, message, map)) .build(); PushResult result = jPushClient.sendPush(payload); if (result.msg_id > 0 && result.isResultOK()) { return true; } } catch (Exception e) { } return false; } /** * 向苹果手机推送一条信息 * * @param message * @return */ @Override public boolean pushMessageByIOS(String title, String message, String userId, Map map) { try { PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios()) .setAudience(Audience.alias(userId)) .setNotification(Notification.ios(message, map)) .build(); PushResult result = jPushClient.sendPush(payload); if (result.msg_id > 0 && result.isResultOK()) { return true; } } catch (Exception e) { } return false; } }