Usages of

com.baidu.yun.push.auth.PushKeyPair.PushKeyPair(?, ?)
/** * ��������������� * @return */ private static BaiduPushClient initPushClient(){ // 1. get apiKey and secretKey from developer console PushKeyPair pair = null; pair = new PushKeyPair("Aa39yzDCHnK5GhTAxyVXndnI", "TkhqYMbPiudSsZtFyBWt0ke3aVWNbWZb"); // 2. build a BaidupushClient object to access released interfaces BaiduPushClient pushClient = new BaiduPushClient(pair,"api.tuisong.baidu.com"); // 3. register a YunLogHandler to get detail interacting information pushClient.setChannelLogHandler(new YunLogHandler() { @Override public void onHandle(YunLogEvent event) { System.out.println(event.getMessage()); } }); return pushClient; }
public static void pushMsgToSingleDevice(UserElement userElement, String message) throws SharingBikesException { PushKeyPair pair = new PushKeyPair(Constants.BAIDU_YUN_PUSH_API_KEY, Constants.BAIDU_YUN_PUSH_SECRET_KEY); BaiduPushClient pushClient = new BaiduPushClient(pair, Constants.CHANNEL_REST_URL); try { PushMsgToSingleDeviceRequest request = new PushMsgToSingleDeviceRequest() .addChannelId(userElement.getPushChannelId()) .addMsgExpires(3600) .addMessageType(1) .addMessage(message); if ("android".equals(userElement.getPlatform())) { request.setDeviceType(3); } else if ("ios".equals(userElement.getPlatform())) { request.setDeviceType(4); } PushMsgToSingleDeviceResponse response = pushClient.pushMsgToSingleDevice(request); } catch (PushClientException | PushServerException e) { e.printStackTrace(); throw new SharingBikesException(e.getMessage()); } }
@PostConstruct public void afterPropertiesSet() throws Exception { baiduClient = LazyLoader.getDefault(new Loader<BaiduPushClient, Object>(){ @Override public BaiduPushClient load(Object context) { PushKeyPair pair = new PushKeyPair(apiKey, secretKey); BaiduPushClient client = new BaiduPushClient(pair, BaiduPushConstants.CHANNEL_REST_URL); client.setChannelLogHandler(new YunLogHandler() { @Override public void onHandle(YunLogEvent event) { log.info(event.getMessage()); } }); return client; } }); }
private PushKeyPair pushKeyPair; // code omitted ... public void initClient(){ pushKeyPair = new PushKeyPair(apiKey,secretKey); }
public static void main(String[] args) throws PushClientException, PushServerException { // 1. get apiKey and secretKey from developer console String apiKey = "xxxxxxxxxxxxxxxxxxxx"; String secretKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"; PushKeyPair pair = new PushKeyPair(apiKey, secretKey); // 2. build a BaidupushClient object to access released interfaces BaiduPushClient pushClient = new BaiduPushClient(pair, BaiduPushConstants.CHANNEL_REST_URL); // 3. register a YunLogHandler to get detail interacting information // in this request. pushClient.setChannelLogHandler(new YunLogHandler() { public void onHandle(YunLogEvent event) { System.out.println(event.getMessage()); } }); try { // 4. specify request arguments //��������� Android��������������� JSONObject notification = new JSONObject(); notification.put("title", "TEST"); notification.put("description","Hello Baidu Push"); notification.put("notification_builder_id", 0); notification.put("notification_basic_style", 4); notification.put("open_type", 1); notification.put("url", "http://push.baidu.com"); JSONObject jsonCustormCont = new JSONObject(); jsonCustormCont.put("key", "value"); //���������������������������key-value notification.put("custom_content", jsonCustormCont); PushMsgToSingleDeviceRequest request = new PushMsgToSingleDeviceRequest() .addChannelId("xxxxxxxxxxxxxxxxxxxxx") .addMsgExpires(new Integer(3600)). // message������������������ addMessageType(1).// 1���������������0:������������������. ��������������� ���������IOS������������������. addMessage(notification.toString()). addDeviceType(3);// deviceType => 3:android, 4:ios // 5. http request PushMsgToSingleDeviceResponse response = pushClient .pushMsgToSingleDevice(request); // Http������������������������������������ System.out.println("msgId: " + response.getMsgId() + ",sendTime: " + response.getSendTime()); } catch (PushClientException e) { /* * ERROROPTTYPE ���������������������������������������������������-- ������������������������������������������'true' ������������������, 'false' ������������������������ */ if (BaiduPushConstants.ERROROPTTYPE) { throw e; } else { e.printStackTrace(); } } catch (PushServerException e) { if (BaiduPushConstants.ERROROPTTYPE) { throw e; } else { System.out.println(String.format( "requestId: %d, errorCode: %d, errorMessage: %s", e.getRequestId(), e.getErrorCode(), e.getErrorMsg())); } } }
public static String pushMsgToAll(String message,int messageType) throws PushClientException,PushServerException { // 1. get apiKey and secretKey from developer console String apiKey = "qENo6eZgyhv0nQXBfo5W7LAN"; String secretKey = "zHq6yDUqqkgY2c6apj09o9dxV7lwXpd6"; PushKeyPair pair = new PushKeyPair(apiKey, secretKey); // 2. build a BaidupushClient object to access released interfaces BaiduPushClient pushClient = new BaiduPushClient(pair, BaiduPushConstants.CHANNEL_REST_URL); // 3. register a YunLogHandler to get detail interacting information // in this request. pushClient.setChannelLogHandler(new YunLogHandler() { @Override public void onHandle(YunLogEvent event) { System.out.println(event.getMessage()); } }); try { // 4. specify request arguments PushMsgToAllRequest request = new PushMsgToAllRequest() .addMsgExpires(new Integer(3600)).addMessageType(messageType) // .addMessage("{\"title\":\"TEST\",\"description\":\"Hello Baidu push!\"}") //������������������ .addMessage(message) .addSendTime(System.currentTimeMillis() / 1000 + 60) // ������������������������������������������������������������������������.������2��������������� .addDeviceType(3); // 5. http request PushMsgToAllResponse response = pushClient.pushMsgToAll(request); // Http������������������������ return ("msgId: " + response.getMsgId() + ",sendTime: " + response.getSendTime() + ",timerId: " + response.getTimerId()); } catch (PushClientException e) { if (BaiduPushConstants.ERROROPTTYPE) { throw e; } else { e.printStackTrace(); return ExceptionUtil.getStackTrace(e); } } catch (PushServerException e) { if (BaiduPushConstants.ERROROPTTYPE) { throw e; } else { return (String.format( "requestId: %d, errorCode: %d, errorMessage: %s", e.getRequestId(), e.getErrorCode(), e.getErrorMsg())); } } }
public static void androidPushBatchMsg(String msgtitle,String description,String[] channelIds) throws PushClientException,PushServerException { PushKeyPair pair = new PushKeyPair(BaiduPushConstants.ANDROIDAPIKEY,BaiduPushConstants.ANDROIDSECRETKEY); // 2. build a BaidupushClient object to access released interfaces BaiduPushClient pushClient = new BaiduPushClient(pair, BaiduPushConstants.CHANNEL_REST_URL); // 3. register a YunLogHandler to get detail interacting information // in this request. pushClient.setChannelLogHandler(new YunLogHandler() { public void onHandle(YunLogEvent event) { System.out.println(event.getMessage()); } }); try { // 4. specify request arguments //������Android������ JSONObject notification = new JSONObject(); notification.put("title", msgtitle); notification.put("description",description); notification.put("notification_builder_id", 0); notification.put("notification_basic_style", 4); notification.put("open_type", 1); notification.put("url", "http://push.baidu.com"); JSONObject jsonCustormCont = new JSONObject(); jsonCustormCont.put("key", "value"); //������������������key-value notification.put("custom_content", jsonCustormCont); /* String[] channelIds = { "3915307812372707376","3833069788300443092"}; */ PushBatchUniMsgRequest request = new PushBatchUniMsgRequest() .addChannelIds(channelIds) .addMsgExpires(new Integer(3600*5)) .addMessageType(1) .addMessage(notification.toString()) .addDeviceType(3) .addTopicId("BaiduPush");// ������������������ // 5. http request PushBatchUniMsgResponse response = pushClient .pushBatchUniMsg(request); // Http������������������������ System.out.println(String.format("msgId: %s, sendTime: %d", response.getMsgId(), response.getSendTime())); } catch (PushClientException e) { if (BaiduPushConstants.ERROROPTTYPE) { throw e; } else { e.printStackTrace(); } } catch (PushServerException e) { if (BaiduPushConstants.ERROROPTTYPE) { throw e; } else { System.out.println(String.format( "requestId: %d, errorCode: %d, errorMessage: %s", e.getRequestId(), e.getErrorCode(), e.getErrorMsg())); } } }
public static void main(String[] args) throws PushClientException,PushServerException { // 1. get apiKey and secretKey from developer console String apiKey = "wXTWbMwgmMGwAsMibzZnidCO"; String secretKey = "ThK9S55dHYpkPqLC4kIMRqP0gGD74c5U"; PushKeyPair pair = new PushKeyPair(apiKey, secretKey); // 2. build a BaidupushClient object to access released interfaces BaiduPushClient pushClient = new BaiduPushClient(pair, BaiduPushConstants.CHANNEL_REST_URL); // 3. register a YunLogHandler to get detail interacting information // in this request. pushClient.setChannelLogHandler(new YunLogHandler() { public void onHandle(YunLogEvent event) { System.out.println(event.getMessage()); } }); try { JSONObject notification = new JSONObject(); notification.put("title", "������"); notification.put("description","������"); // 4. specify request arguments PushMsgToAllRequest request = new PushMsgToAllRequest() .addMsgExpires(new Integer(3600)).addMessageType(1) .addMessage(notification.toString()) //��������������������������� /* .addSendTime(System.currentTimeMillis() / 1000 + 120) // ������������������������������������������������������������������������������������������������������������.���������2������������������������ */ .addDeviceType(3); // 5. http request PushMsgToAllResponse response = pushClient.pushMsgToAll(request); // Http������������������������������������ System.out.println("msgId: " + response.getMsgId() + ",sendTime: " + response.getSendTime() + ",timerId: " + response.getTimerId()); } catch (PushClientException e) { if (BaiduPushConstants.ERROROPTTYPE) { throw e; } else { e.printStackTrace(); } } catch (PushServerException e) { if (BaiduPushConstants.ERROROPTTYPE) { throw e; } else { System.out.println(String.format( "requestId: %d, errorCode: %d, errorMessage: %s", e.getRequestId(), e.getErrorCode(), e.getErrorMsg())); } } }
public static void androidPushBatchMsg(String msgtitle,String description,String[] channelIds,JSONObject jsonCustormCont) throws PushClientException,PushServerException { String apiKey = "fM7HqL5MbOl5UUWPB6nSsLNa"; String secretKey = "7r2XI1DHGGg3cFp61xAE5GvBd5ebA8VM"; PushKeyPair pair = new PushKeyPair(apiKey, secretKey); // 2. build a BaidupushClient object to access released interfaces BaiduPushClient pushClient = new BaiduPushClient(pair, BaiduPushConstants.CHANNEL_REST_URL); // 3. register a YunLogHandler to get detail interacting information // in this request. pushClient.setChannelLogHandler(new YunLogHandler() { public void onHandle(YunLogEvent event) { System.out.println(event.getMessage()); } }); try { // 4. specify request arguments //������Android������ JSONObject notification = new JSONObject(); notification.put("title", msgtitle); notification.put("description",description); notification.put("notification_builder_id", 0); notification.put("pkg_content","");// notification.put("notification_basic_style", 5); notification.put("open_type",2); /*notification.put("url", "http://push.baidu.com");*/ //JSONObject jsonCustormCont = new JSONObject(); //jsonCustormCont.put("key", "value"); //������������������key-value notification.put("custom_content", jsonCustormCont); /* String[] channelIds = { "3915307812372707376","3833069788300443092"}; */ PushBatchUniMsgRequest request = new PushBatchUniMsgRequest() .addChannelIds(channelIds) .addMsgExpires(new Integer(3600*5)) .addMessageType(1) .addMessage(notification.toString()) .addDeviceType(3) .addTopicId("BaiduPush");// ������������������ // 5. http request PushBatchUniMsgResponse response = pushClient .pushBatchUniMsg(request); // Http������������������������ System.out.println(String.format("msgId: %s, sendTime: %d", response.getMsgId(), response.getSendTime())); } catch (PushClientException e) { if (BaiduPushConstants.ERROROPTTYPE) { throw e; } else { e.printStackTrace(); } } catch (PushServerException e) { if (BaiduPushConstants.ERROROPTTYPE) { throw e; } else { System.out.println(String.format( "requestId: %d, errorCode: %d, errorMessage: %s", e.getRequestId(), e.getErrorCode(), e.getErrorMsg())); } } }
public static void androidPushBatchMsg(String msgtitle,String description,String[] channelIds) throws PushClientException,PushServerException { String apiKey = "fM7HqL5MbOl5UUWPB6nSsLNa"; String secretKey = "7r2XI1DHGGg3cFp61xAE5GvBd5ebA8VM"; PushKeyPair pair = new PushKeyPair(apiKey, secretKey); // 2. build a BaidupushClient object to access released interfaces BaiduPushClient pushClient = new BaiduPushClient(pair, BaiduPushConstants.CHANNEL_REST_URL); // 3. register a YunLogHandler to get detail interacting information // in this request. pushClient.setChannelLogHandler(new YunLogHandler() { public void onHandle(YunLogEvent event) { System.out.println(event.getMessage()); } }); try { // 4. specify request arguments //������Android������ JSONObject notification = new JSONObject(); notification.put("title", msgtitle); notification.put("description",description); notification.put("notification_builder_id", 0); notification.put("notification_basic_style", 5); notification.put("open_type", 2); /*notification.put("url", "http://push.baidu.com");*/ JSONObject jsonCustormCont = new JSONObject(); jsonCustormCont.put("key", "value"); //������������������key-value notification.put("custom_content", jsonCustormCont); /* String[] channelIds = { "3915307812372707376","3833069788300443092"}; */ PushBatchUniMsgRequest request = new PushBatchUniMsgRequest() .addChannelIds(channelIds) .addMsgExpires(new Integer(3600*5)) .addMessageType(1) .addMessage(notification.toString()) .addDeviceType(3) .addTopicId("BaiduPush");// ������������������ // 5. http request PushBatchUniMsgResponse response = pushClient .pushBatchUniMsg(request); // Http������������������������ System.out.println(String.format("msgId: %s, sendTime: %d", response.getMsgId(), response.getSendTime())); } catch (PushClientException e) { if (BaiduPushConstants.ERROROPTTYPE) { throw e; } else { e.printStackTrace(); } } catch (PushServerException e) { if (BaiduPushConstants.ERROROPTTYPE) { throw e; } else { System.out.println(String.format( "requestId: %d, errorCode: %d, errorMessage: %s", e.getRequestId(), e.getErrorCode(), e.getErrorMsg())); } } }
Usage snippet has been bookmarked! Review your bookmarks
Thank you! Review your likes