package com.yeshi.fanli.util.push; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import com.yeshi.fanli.entity.xinge.MessageInfo; import com.yeshi.fanli.entity.xinge.PushRecord; import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.inter.config.SystemService; import com.yeshi.fanli.service.inter.push.PushService; import com.yeshi.fanli.util.StringUtil; import net.sf.json.JSONObject; public class PushUtils { private static SystemService systemService; @Resource private PushService pushService; /** * 小米全推 * * @param info * @param json * @param pushRecord * @return * @throws Exception */ public static int allPushXiaoMi(MessageInfo info, JSONObject json, PushRecord pushRecord) throws Exception { JSONObject mapXm = JSONObject.fromObject(json); String android = XiaoMiPushUtil.allPushAndroidForXM(info, mapXm); LogHelper.userInfo("安卓推送测试:" + android); pushRecord.setAndroidPushId(android); if (android != null) { return 1; } else { return 4; } } /** * IOS 全推送 * * @param info * @param json * @param pushRecord * @param type * @param deviceTokenList * @return * @throws Exception */ public static int allPushIOS(MessageInfo info, PushRecord pushRecord, String url, int type, List deviceTokenList) throws Exception { /* * com.yeshi.fanli.entity.system.System b_IOS = * systemService.getSystem("IOS", * Constant.systemCommonConfig.getIosBundleId()); */ String IOS = IOSPushUtil.allPushIOS(deviceTokenList, info, url, type); LogHelper.userInfo("IOS的推送日志:" + IOS); pushRecord.setIosPushId(IOS); if (IOS != null) { return 1; } else { return 4; } } /** * 小米单推 * * @param info * @param json * @return */ public static int singlePushXiaoMi(MessageInfo info, JSONObject json, PushRecord pushRecord) { JSONObject mapXm = JSONObject.fromObject(json); String android = XiaoMiPushUtil.singlePushAndroidForXM(info, mapXm, null); LogHelper.userInfo("安卓推送测试:" + android); pushRecord.setAndroidPushId(android); if (android != null) { return 1; } else { return 4; } } /** * IOS 单推 * * @param info * @param url * @param type * @param deviceTokenList * @return */ public static String singlePushIOS(MessageInfo info, PushRecord pushRecord, String url, int type, List deviceTokenList) { if (deviceTokenList != null && deviceTokenList.size() > 0) { for (String deviceToken : deviceTokenList) { if (!StringUtil.isNullOrEmpty(deviceToken)) { try { List deviceList = new ArrayList<>(); deviceList.add(deviceToken); String IOS = IOSPushUtil.allPushIOS(deviceList, info, url, type); pushRecord.setIosPushId(IOS); } catch (Exception e) { e.printStackTrace(); } } } } return null; } }