123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- package com.fdkankan.modeling.push;
- import cn.hutool.core.date.DateUtil;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.fdkankan.modeling.push.android.*;
- import com.fdkankan.modeling.push.ios.*;
- import lombok.extern.slf4j.Slf4j;
- import java.util.Date;
- @Slf4j
- public class PushMessageConfig {
- private String appkey = null;
- private String appMasterSecret = null;
- private String timestamp = null;
- private PushClient client = new PushClient();
- public static final String ANDROID_KEY = "5ee71c03dbc2ec076dd488cb";
- public static final String ANDROID_SECRET = "gzw4r8frbhq6eigxrvgjkdrm7wgtu83g";
- public static final String IOS_KEY = "5ee71ca9978eea081640f22a";
- public static final String IOS_SECRET = "tpuhyojch16pcha2qmpidlbnzkielv9w";
- //转台双目使用
- public static final String ANDROID_KEY_Z = "60efd777a6f90557b7b97c25";
- public static final String ANDROID_SECRET_Z = "ll85ov3qzeuas0ig7cw0v5bgzq1bdl07";
- public static final String IOS_KEY_Z = "60efd7c9a6f90557b7b97d10";
- public static final String IOS_SECRET_Z = "li62b5f3d9kn8idvy6qva3c5gyidmqwl";
- public PushMessageConfig(String key, String secret) {
- try {
- appkey = key;
- appMasterSecret = secret;
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(1);
- }
- }
-
- public void sendAndroidBroadcast() throws Exception {
- AndroidBroadcast broadcast = new AndroidBroadcast(appkey,appMasterSecret);
- broadcast.setTicker( "Android broadcast ticker");
- broadcast.setTitle( "中文的title");
- broadcast.setText( "Android broadcast text");
- broadcast.goAppAfterOpen();
- broadcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
- // TODO Set 'production_mode' to 'false' if it's a test device.
- // For how to register a test device, please see the developer doc.
- broadcast.setProductionMode();
- // Set customized fields
- broadcast.setExtraField("test", "helloworld");
- //厂商通道相关参数
- broadcast.setChannelActivity("your channel activity");
- broadcast.setChannelProperties("abc");
- client.send(broadcast);
- }
-
- public void sendAndroidUnicast(String token, String ticker, String title, String text, String url) throws Exception {
- AndroidUnicast unicast = new AndroidUnicast(appkey,appMasterSecret);
- // TODO Set your device token
- unicast.setDeviceToken(token);
- unicast.setTicker(ticker);
- unicast.setTitle(title);
- unicast.setText(text);
- unicast.goUrlAfterOpen(url);
- unicast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
- // TODO Set 'production_mode' to 'false' if it's a test device.
- // For how to register a test device, please see the developer doc.
- unicast.setProductionMode();
- // Set customized fields
- unicast.setExtraField("test", "helloworld");
- unicast.setChannelActivity("com.fdage.eight.module.EightPushMsgHandlerActivity");
- // unicast.setChannelProperties("abc");
- client.send(unicast);
- }
- //转台相机
- public void sendAndroidUnicast2(String token, String ticker, String title, String text, String url) throws Exception {
- AndroidUnicast unicast = new AndroidUnicast(appkey,appMasterSecret);
- // TODO Set your device token
- unicast.setDeviceToken(token);
- unicast.setTicker(ticker);
- unicast.setTitle(title);
- unicast.setText(text);
- unicast.goUrlAfterOpen(url);
- unicast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
- // TODO Set 'production_mode' to 'false' if it's a test device.
- // For how to register a test device, please see the developer doc.
- unicast.setProductionMode();
- // Set customized fields
- unicast.setExtraField("test", "helloworld");
- unicast.setChannelActivity("io.github.zileyuan.umeng_analytics_push.OfflineNotifyClickActivity");
- // unicast.setChannelProperties("abc");
- client.send(unicast);
- }
-
- public void sendAndroidGroupcast() throws Exception {
- AndroidGroupcast groupcast = new AndroidGroupcast(appkey,appMasterSecret);
- /* TODO
- * Construct the filter condition:
- * "where":
- * {
- * "and":
- * [
- * {"tag":"test"},
- * {"tag":"Test"}
- * ]
- * }
- */
- JSONObject filterJson = new JSONObject();
- JSONObject whereJson = new JSONObject();
- JSONArray tagArray = new JSONArray();
- JSONObject testTag = new JSONObject();
- JSONObject TestTag = new JSONObject();
- testTag.put("tag", "test");
- TestTag.put("tag", "Test");
- tagArray.add(testTag);
- tagArray.add(TestTag);
- whereJson.put("and", tagArray);
- filterJson.put("where", whereJson);
- groupcast.setFilter(filterJson);
- groupcast.setTicker( "Android groupcast ticker");
- groupcast.setTitle( "中文的title");
- groupcast.setText( "Android groupcast text");
- groupcast.goAppAfterOpen();
- groupcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
- groupcast.setChannelActivity("your channel activity");
- // TODO Set 'production_mode' to 'false' if it's a test device.
- // For how to register a test device, please see the developer doc.
- groupcast.setProductionMode();
- //厂商通道相关参数
- groupcast.setChannelActivity("your channel activity");
- groupcast.setChannelProperties("abc");
- client.send(groupcast);
- }
-
- public void sendAndroidCustomizedcast() throws Exception {
- AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(appkey,appMasterSecret);
- // TODO Set your alias here, and use comma to split them if there are multiple alias.
- // And if you have many alias, you can also upload a file containing these alias, then
- // use file_id to send customized notification.
- customizedcast.setAlias("alias", "alias_type");
- customizedcast.setTicker( "Android customizedcast ticker");
- customizedcast.setTitle( "中文的title");
- customizedcast.setText( "Android customizedcast text");
- customizedcast.goAppAfterOpen();
- customizedcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
- // TODO Set 'production_mode' to 'false' if it's a test device.
- // For how to register a test device, please see the developer doc.
- customizedcast.setProductionMode();
- //厂商通道相关参数
- customizedcast.setChannelActivity("your channel activity");
- customizedcast.setChannelProperties("abc");
- client.send(customizedcast);
- }
-
- public void sendAndroidCustomizedcastFile() throws Exception {
- AndroidCustomizedcast customizedcast = new AndroidCustomizedcast(appkey,appMasterSecret);
- // TODO Set your alias here, and use comma to split them if there are multiple alias.
- // And if you have many alias, you can also upload a file containing these alias, then
- // use file_id to send customized notification.
- String fileId = client.uploadContents(appkey,appMasterSecret,"aa"+"\n"+"bb"+"\n"+"alias");
- customizedcast.setFileId(fileId, "alias_type");
- customizedcast.setTicker( "Android customizedcast ticker");
- customizedcast.setTitle( "中文的title");
- customizedcast.setText( "Android customizedcast text");
- customizedcast.goAppAfterOpen();
- customizedcast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
- // TODO Set 'production_mode' to 'false' if it's a test device.
- // For how to register a test device, please see the developer doc.
- customizedcast.setProductionMode();
- //厂商通道相关参数
- customizedcast.setChannelActivity("your channel activity");
- customizedcast.setChannelProperties("abc");
- client.send(customizedcast);
- }
-
- public void sendAndroidFilecast() throws Exception {
- AndroidFilecast filecast = new AndroidFilecast(appkey,appMasterSecret);
- // TODO upload your device tokens, and use '\n' to split them if there are multiple tokens
- String fileId = client.uploadContents(appkey,appMasterSecret,"aa"+"\n"+"bb");
- filecast.setFileId( fileId);
- filecast.setTicker( "Android filecast ticker");
- filecast.setTitle( "中文的title");
- filecast.setText( "Android filecast text");
- filecast.goAppAfterOpen();
- filecast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
- //厂商通道相关参数
- filecast.setChannelActivity("your channel activity");
- filecast.setChannelProperties("abc");
- client.send(filecast);
- }
-
- public void sendIOSBroadcast() throws Exception {
- IOSBroadcast broadcast = new IOSBroadcast(appkey,appMasterSecret);
- //alert值设置为字符串
- //broadcast.setAlert("IOS 广播测试");
- //alert的值设置为字典
- // broadcast.setAlert("今日天气" , "" , "今日可能下雨🌂");
- broadcast.setBadge( 0);
- broadcast.setSound( "default");
- // TODO set 'production_mode' to 'true' if your app is under production mode
- broadcast.setTestMode();
- // Set customized fields
- broadcast.setCustomizedField("test", "helloworld");
- client.send(broadcast);
- }
-
- public void sendIOSUnicast(String token, String title ,String subtitle , String body, String url) throws Exception {
- IOSUnicast unicast = new IOSUnicast(appkey,appMasterSecret);
- // TODO Set your device token
- unicast.setDeviceToken(token);
- //alert值设置为字符串
- //unicast.setAlert("IOS 单播测试");
- //alert的值设置为字典
- unicast.setAlert(title, subtitle, body, url);
- // unicast.setBadge( 0);
- unicast.setSound( "default");
- // TODO set 'production_mode' to 'true' if your app is under production mode
- unicast.setProductionMode();
- // unicast.setTestMode();
- unicast.setDescription(title);
- unicast.setExpireTime(DateUtil.formatTime(DateUtil.offsetDay(new Date(), 1)));
- // Set customized fields
- // unicast.setCustomizedField("url", url);
- client.send(unicast);
- }
-
- public void sendIOSGroupcast() throws Exception {
- IOSGroupcast groupcast = new IOSGroupcast(appkey,appMasterSecret);
- /* TODO
- * Construct the filter condition:
- * "where":
- * {
- * "and":
- * [
- * {"tag":"iostest"}
- * ]
- * }
- */
- JSONObject filterJson = new JSONObject();
- JSONObject whereJson = new JSONObject();
- JSONArray tagArray = new JSONArray();
- JSONObject testTag = new JSONObject();
- testTag.put("tag", "iostest");
- tagArray.add(testTag);
- whereJson.put("and", tagArray);
- filterJson.put("where", whereJson);
- log.info(filterJson.toString());
-
- // Set filter condition into rootJson
- groupcast.setFilter(filterJson);
- //groupcast.setAlert("IOS 组播测试");
- //alert的值设置为字典
- // groupcast.setAlert("今日天气" , "subtitle" , "今日可能下雨🌂");
- groupcast.setBadge( 0);
- groupcast.setSound( "default");
- // TODO set 'production_mode' to 'true' if your app is under production mode
- groupcast.setTestMode();
- client.send(groupcast);
- }
-
- public void sendIOSCustomizedcast() throws Exception {
- IOSCustomizedcast customizedcast = new IOSCustomizedcast(appkey,appMasterSecret);
- // TODO Set your alias and alias_type here, and use comma to split them if there are multiple alias.
- // And if you have many alias, you can also upload a file containing these alias, then
- // use file_id to send customized notification.
- customizedcast.setAlias("alias", "alias_type");
- //customizedcast.setAlert("IOS 个性化测试");
- //alert的值设置为字典
- // customizedcast.setAlert("今日天气" , "" , "今日可能下雨🌂");
- customizedcast.setBadge( 0);
- customizedcast.setSound( "default");
- // TODO set 'production_mode' to 'true' if your app is under production mode
- customizedcast.setTestMode();
- client.send(customizedcast);
- }
-
- public void sendIOSFilecast() throws Exception {
- IOSFilecast filecast = new IOSFilecast(appkey,appMasterSecret);
- // TODO upload your device tokens, and use '\n' to split them if there are multiple tokens
- String fileId = client.uploadContents(appkey,appMasterSecret,"aa"+"\n"+"bb");
- filecast.setFileId( fileId);
- //filecast.setAlert("IOS 文件播测试");
- //alert的值设置为字典
- // filecast.setAlert("今日天气" , "" , "今日可能下雨🌂");
- filecast.setBadge( 0);
- filecast.setSound( "default");
- // TODO set 'production_mode' to 'true' if your app is under production mode
- filecast.setTestMode();
- client.send(filecast);
- }
-
- public static void main(String[] args) {
- // TODO set your appkey and master secret here
- //安卓
- // Demo demo = new Demo(ANDROID_KEY, ANDROID_SECRET);
- //ios
- PushMessageConfig pushMessageConfig = new PushMessageConfig(IOS_KEY, IOS_SECRET);
- try {
- // demo.sendAndroidUnicast("AneqkEZahjbW3cF7gu8juNYqz54ZFfK7kjMpTOiQL9dl",
- // "测试项目计算完成", "四维看看Pro", "您上传的测试项目计算完成,点击查看",
- // "https://test.4dkankan.com/smobile.html?m=t-e9uHHdn");
- pushMessageConfig.sendIOSUnicast("ec61a2aa52673c96c12024e07ce267e391ca560e0c60f15ee09e65c8843ef7f4",
- "四维看看Pro", "测试项目计算完成", "您上传的测试项目计算完成,点击查看",
- "https://test.4dkankan.com/smobile.html?m=t-e9uHHdn");
- /* TODO these methods are all available, just fill in some fields and do the test
- * demo.sendAndroidCustomizedcastFile();
- * demo.sendAndroidBroadcast();
- * demo.sendAndroidGroupcast();
- * demo.sendAndroidCustomizedcast();
- * demo.sendAndroidFilecast();
- *
- * demo.sendIOSBroadcast();
- * demo.sendIOSUnicast();
- * demo.sendIOSGroupcast();
- * demo.sendIOSCustomizedcast();
- * demo.sendIOSFilecast();
- */
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
-
- }
|