Blame view

parking-module-pay/src/main/java/com/zteits/pay/util/JPushForPDAUtil.java 4.18 KB
55f68655   王彪总   新项目
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
  package com.zteits.pay.util;
  
  import com.alibaba.fastjson.JSON;
  import com.alibaba.fastjson.JSONObject;
  import com.clouds.common.utils.ResultUtils;
  import com.zteits.clouds.api.apibase.bean.BizResult;
  import com.zteits.clouds.api.dto.clouds.param.GetEmployeeRequest;
  import com.zteits.clouds.api.dto.park.dto.TpEEmployeeChargeDTO;
  import com.zteits.clouds.api.dto.pda.msgpush.InOutParkMsgPushDTO;
  import com.zteits.clouds.api.dto.pda.msgpush.PDAMsgPushDTO;
  import com.zteits.clouds.api.dto.pda.msgpush.PDAMsgTypeEnum;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  import com.zteits.pay.configuration.JPushPDAConfigure;
  
  import cn.jiguang.common.ClientConfig;
  import cn.jiguang.common.resp.APIConnectionException;
  import cn.jiguang.common.resp.APIRequestException;
  import cn.jpush.api.JPushClient;
  import cn.jpush.api.push.PushResult;
  import cn.jpush.api.push.model.Message;
  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;
  
  public class JPushForPDAUtil {
  	
  	 private static final Logger log = LoggerFactory.getLogger(JPushForPDAUtil.class);
  	 
  	 private static JPushClient pdaJpushClient = new JPushClient(JPushPDAConfigure.getMASTER_SECRET(), JPushPDAConfigure.getAPP_KEY(), null,ClientConfig.getInstance());
  
  	/**
  	 * PDA单个android用户推送消息
  	 * @param title
  	 * @param msgContent
  	 * @param alias
  	 * @return
  	 * 2017年11月28日 zhaowg
  	 */
  	public static PushResult pdaSendPush(String title, String msgContent,String... alias) {
  		PushResult result = new PushResult();
  		try {
  			PushPayload payload = sendAndroidMessageWithAlias(title,msgContent,null,alias);
  			 result = pdaJpushClient.sendPush(payload);
  		} catch (Exception e) {
  			e.printStackTrace();
  			log.debug(" 单个用户推送消息 失败:"+e);
  		}
  		return result;
  	}
  	
  	
  	public static PushPayload buildPushObject_all_alias_alert(String msgContent,String alias) {
          return PushPayload.newBuilder()
                  .setPlatform(Platform.all())
                  .setAudience(Audience.alias(alias))
                  .setNotification(Notification.alert(msgContent))
                  .build();
      }
  	
  	
  	 public static PushPayload sendAndroidMessageWithAlias(String title, String msgContent, String contentType,String... alias) 
  	            throws APIConnectionException, APIRequestException {
  	      return   PushPayload.newBuilder()
  	                .setPlatform(Platform.android())
  	                .setAudience(Audience.alias(alias))
  	                .setMessage(Message.newBuilder()
  	                        .setTitle(title)
  	                        .setMsgContent(msgContent)
  	                        .setContentType(contentType)
  	                        .build())
  	                .build();
  	    }
  	
  	  public static PushPayload sendIosMessageWithAlias(String title, String msgContent, String contentType,String... alias) 
  	            throws APIConnectionException, APIRequestException {
  		  return PushPayload.newBuilder()
  	                .setPlatform(Platform.ios())
  	                .setAudience(Audience.alias(alias))
  	                .setMessage(Message.newBuilder()
  	                        .setTitle(title)
  	                        .setMsgContent(msgContent)
  	                        .setContentType(contentType)
  	                        .build())
  	                .build();
  	    }
  
  
  	/*public static void main(String[] args) {
  		PDAMsgPushDTO<InspectMsgPushDTO> msgPushDTO = new  PDAMsgPushDTO<>();
  		InspectMsgPushDTO inOutParkMsgPushDTO = new InspectMsgPushDTO();
  		inOutParkMsgPushDTO.setMsg("到点了,签退吧");
  		msgPushDTO.setContent(inOutParkMsgPushDTO);
  		msgPushDTO.setMsgType(PDAMsgTypeEnum.SIGN_OUT_ALERT.name());
  		PushResult result = new PushResult();
  		try {
  			PushPayload payload = sendAndroidMessageWithAlias("", JSON.toJSONString(msgPushDTO),null,"18261520692");
  			JPushClient pdaJpushClient = new JPushClient("11350a6a38cfaf518c1beafe", "b7aabe15e95547f3fb1815ca", null,
  					ClientConfig.getInstance());
  			result = pdaJpushClient.sendPush(payload);
  			System.out.println(result);
  		} catch (Exception e) {
  			e.printStackTrace();
  			log.debug(" 单个用户推送消息 失败:"+e);
  		}
  	}*/
  }