仔细阅读文档,下边的都是废话。

为了省事,iOS和Android 提供了所有了参数,需要那个了修改传参。

  1. //ios actionURL为自定义参数
  2.  
  3. $.ajax({
  4. type : "POST",
  5. url:_basePath + "/------.html",
  6. data:{"testing":"1","type":"groupcast","title":"推送标题","subtitle":"","body":"推送内容"
  7. ,"description":"","actionURL":""
  8. ,"device_tokens":"","app_version":"","launch_from":"","not_launch_from":"","alias_type":"","alias":"","tag":""
  9. ,"badge":"","sound":"","available":"","category":""
  10. ,"policy":"","start_time":"","expire_time":""},
  11. dataType : "JSON",
  12. success : function(res) {
  13. alert(res);
  14. }
  15.  
  16. });
  17.  
  18. //Android go_custom 可以设置自定义参数,没有参数打不开app,只想打开app 只能用go_app
  19. $.ajax({
  20. type : "POST",
  21. url:_basePath + "/-------.html",
  22. dataType : "JSON",
  23. data:{"testing":"1","type":"groupcast","ticker":"tuisong","title":"挑剔","text":"内容","description":""
  24. ,"after_open": "go_custom", "url":"https://www.baidu.com","activity":"","custom":"","device_tokens":""
  25. ,"app_version":"","alias_type":"","alias":"","tag":"北京市北京市海淀区"
  26. ,"policy":"","start_time":"","expire_time":"","out_biz_no":"","launch_from":"","not_launch_from":""
  27. ,"sound":"","play_vibrate":"","play_lights":"","play_sound":""},
  28. success : function(res) {
  29. alert(res);
  30. }
  31.  
  32. });
  33.  
  34. }

JS提交参数

java 后台签名上传

  1. //MD5
  2. private String md5(String value){
  3. String result = null;
  4. MessageDigest md5 = null;
  5. try{
  6. md5 = MessageDigest.getInstance("MD5");
  7. md5.update((value).getBytes("UTF-8"));
  8. }catch (NoSuchAlgorithmException error){
  9. error.printStackTrace();
  10. }catch (UnsupportedEncodingException e){
  11. e.printStackTrace();
  12. }
  13. byte b[] = md5.digest();
  14. int i;
  15. StringBuffer buf = new StringBuffer("");
  16.  
  17. for(int offset=0; offset<b.length; offset++){
  18. i = b[offset];
  19. if(i<0){
  20. i+=256;
  21. }
  22. if(i<16){
  23. buf.append("0");
  24. }
  25. buf.append(Integer.toHexString(i));
  26. }
  27.  
  28. result = buf.toString();
  29. return result;
  30. }

java md5签名

后台参数操作

  1. // 发送推送 iOS
  2. @RequestMapping("/=-------------OS")
  3. public void coreManagementsendPushiOS(HttpServletRequest request, HttpServletResponse response) throws Exception {
  4.  
  5. DefaultValidate validate = new DefaultValidate();
  6. Map<String, Object> params = read(request, validate);
  7.  
  8. HashMap<String, Object> aps = new HashMap<>();
  9. HashMap<String, Object> payload = new HashMap<>();
  10. HashMap<String, Object> md5s = new HashMap<>();
  11.  
  12. HashMap<String, Object> alert = new HashMap<>();
  13. //主标题
  14. if(params.get("title").toString().length()>0) {
  15. alert.put("title", params.get("title"));
  16. }
  17. //副标题
  18. if(params.get("subtitle").toString().length()>0) {
  19. alert.put("subtitle", params.get("subtitle"));
  20. }
  21. //内容
  22. if(params.get("body").toString().length()>0) {
  23. alert.put("body", params.get("body"));
  24. }
  25. aps.put("alert",alert);
  26.  
  27. md5s.put("appkey", "-------");
  28. md5s.put("timestamp", System.currentTimeMillis());
  29.  
  30. //0正式 1测试
  31.  
  32. if(params.get("testing").toString().length()>0) {
  33. if("1".equals(params.get("testing"))) {
  34. md5s.put("production_mode", false);
  35. }
  36. }
  37. //判断加入
  38.  
  39. //发送类型 单播广播等
  40. if("unicast".equals(params.get("type"))) {
  41. md5s.put("device_tokens", params.get("device_tokens"));
  42. } //列表播 英文,隔开,不超500
  43. else if("listcast".equals(params.get("type"))) {
  44. md5s.put("device_tokens", params.get("device_tokens"));
  45. }//groupcast组播 按照filter条件筛选特定用户群, 具体请参照filter参数
  46. else if("groupcast".equals(params.get("type"))) {
  47.  
  48. // 多个标签 安定 or 标签
  49. HashMap<String, Object> where = new HashMap<>();
  50. List<Map<String, Object>> and =new ArrayList<>();
  51.  
  52. HashMap<String, Object> filter = new HashMap<>();
  53.  
  54. //应用版本
  55. if(params.get("app_version").toString().length()>0) {
  56. HashMap<String, Object> app_version = new HashMap<>();
  57. app_version.put("app_version", params.get("app_version"));
  58. and.add(app_version);
  59.  
  60. }
  61.  
  62. //一段时间呢你活跃
  63. if(params.get("launch_from").toString().length()>0) {
  64. HashMap<String, Object> launch_from = new HashMap<>();
  65. launch_from.put("launch_from", params.get("launch_from"));
  66. and.add(launch_from);
  67. }
  68.  
  69. //一段时间内不活跃活跃
  70. if(params.get("not_launch_from").toString().length()>0) {
  71. HashMap<String, Object> not_launch_from = new HashMap<>();
  72. not_launch_from.put("not_launch_from", params.get("not_launch_from"));
  73. and.add(not_launch_from);
  74. }
  75.  
  76. //别名
  77. if(params.get("tag").toString().length()>0) {
  78. HashMap<String, Object> tag = new HashMap<>();
  79. tag.put("tag", params.get("tag"));
  80. and.add(tag);
  81. }
  82.  
  83. where.put("and", and);
  84. filter.put("where", where);
  85. md5s.put("filter", filter);
  86. }//按照filter条件筛选特定用户群, 具体请参照filter参数
  87. else if("customizedcast".equals(params.get("type"))) {
  88.  
  89. //别名
  90. if(params.get("alias_type").toString().length()>0) {
  91. md5s.put("alias_type", params.get("alias_type"));
  92. }
  93.  
  94. if(params.get("alias").toString().length()>0) {
  95. md5s.put("alias", params.get("alias"));
  96. }
  97.  
  98. }
  99.  
  100. //aps
  101. if(params.get("badge").toString().length()>0) {
  102. aps.put("badge", params.get("badge"));
  103. }
  104. if(params.get("sound").toString().length()>0) {
  105. aps.put("sound", params.get("sound"));
  106. }
  107.  
  108. if(params.get("category").toString().length()>0) {
  109. aps.put("category", params.get("category"));
  110. }
  111.  
  112. //自定义内容 payload里边 actionURL:url
  113. if(params.get("actionURL").toString().length()>0) {
  114. payload.put("actionURL", params.get("actionURL"));
  115. }
  116.  
  117. //发送策略
  118. if(params.get("policy").toString().length()>0) {
  119.  
  120. HashMap<String, Object> policy = new HashMap<>();
  121.  
  122. //定时发送
  123. if(params.get("start_time").toString().length()>0) {
  124. policy.put("start_time", params.get("start_time"));
  125. }
  126.  
  127. //过期时间
  128. if(params.get("expire_time").toString().length()>0) {
  129. policy.put("expire_time", params.get("expire_time"));
  130. }
  131.  
  132. md5s.put("policy", policy);
  133. }
  134.  
  135. //消息描述
  136. if(params.get("description").toString().length()>0) {
  137. md5s.put("description", params.get("description"));
  138. }
  139.  
  140. payload.put("aps", aps);
  141. md5s.put("type", params.get("type"));
  142. md5s.put("payload", payload);
  143.  
  144. String url = "http://msg.umeng.com/api/send?sign="+this.md5("POST"+"http://msg.umeng.com/api/send"+JsonUtils.parseObjectToJson(md5s)+"------你的App Master Secret------");
  145. String message = "";
  146. try {
  147. message = HttpClientUtil.doPostJsonAuth(url, JsonUtils.parseObjectToJson(md5s));
  148. } catch (Exception e) {
  149. e.printStackTrace();
  150. message = e.getMessage();
  151. }
  152. write(response,message);
  153. }

iOS

  1. // 发送推送 Android
  2. @RequestMapping("------------")
  3. public void core-----Push(HttpServletRequest request, HttpServletResponse response) throws Exception {
  4.  
  5. DefaultValidate validate = new DefaultValidate();
  6. Map<String, Object> params = read(request, validate);
  7.  
  8. HashMap<String, Object> body = new HashMap<>();
  9. HashMap<String, Object> payload = new HashMap<>();
  10. HashMap<String, Object> md5s = new HashMap<>();
  11. HashMap<String, Object> extra = new HashMap<>();
  12.  
  13. body.put("ticker",params.get("ticker"));
  14. body.put("title",params.get("title"));
  15. body.put("text",params.get("text"));
  16. body.put("after_open",params.get("after_open"));
  17.  
  18. payload.put("display_type","notification");
  19.  
  20. //0正式 1测试
  21. if(params.get("testing").toString().length()>0) {
  22. if("1".equals(params.get("testing"))) {
  23. md5s.put("production_mode", false);
  24. }
  25. }
  26.  
  27. //extra 自定义参数
  28. extra.put("url", params.get("url"));
  29.  
  30. //打开应用行为
  31. if("go_url".equals(params.get("after_open"))) {
  32. body.put("url",params.get("url"));
  33. }
  34.  
  35. //特定行为
  36. else if("go_activity".equals(params.get("after_open"))) {
  37. body.put("activity",params.get("activity"));
  38. }
  39. //用户自定义
  40. else if("go_custom".equals(params.get("after_open"))) {
  41. body.put("custom",params.get("custom"));
  42. }
  43.  
  44. //发送策略
  45. if(params.get("policy").toString().length()>0) {
  46.  
  47. HashMap<String, Object> policy = new HashMap<>();
  48.  
  49. //定时发送
  50. if(params.get("start_time").toString().length()>0) {
  51. policy.put("start_time", params.get("start_time"));
  52. }
  53.  
  54. //过期时间
  55. if(params.get("expire_time").toString().length()>0) {
  56. policy.put("expire_time", params.get("expire_time"));
  57. }
  58. //消息标识
  59. if(params.get("out_biz_no").toString().length()>0) {
  60. policy.put("out_biz_no", params.get("out_biz_no"));
  61. }
  62.  
  63. md5s.put("policy", policy);
  64. }
  65.  
  66. //判断加入
  67.  
  68. //发送类型 单播广播等
  69. if("unicast".equals(params.get("type"))) {
  70. md5s.put("device_tokens", params.get("device_tokens"));
  71. } //列表播 英文,隔开,不超500
  72. else if("listcast".equals(params.get("type"))) {
  73. md5s.put("device_tokens", params.get("device_tokens"));
  74. }//按照filter条件筛选特定用户群, 具体请参照filter参数
  75. else if("groupcast".equals(params.get("type"))) {
  76.  
  77. // 多个标签 安定 or 标签
  78. HashMap<String, Object> where = new HashMap<>();
  79. List<Map<String, Object>> and =new ArrayList<>();
  80. HashMap<String, Object> filter = new HashMap<>();
  81.  
  82. //应用版本
  83. if(params.get("app_version").toString().length()>0) {
  84. HashMap<String, Object> app_version = new HashMap<>();
  85. app_version.put("app_version", params.get("app_version"));
  86. and.add(app_version);
  87.  
  88. }
  89.  
  90. //一段时间呢你活跃
  91. if(params.get("launch_from").toString().length()>0) {
  92. HashMap<String, Object> launch_from = new HashMap<>();
  93. launch_from.put("launch_from", params.get("launch_from"));
  94. and.add(launch_from);
  95. }
  96.  
  97. //一段时间内不活跃活跃
  98. if(params.get("not_launch_from").toString().length()>0) {
  99. HashMap<String, Object> not_launch_from = new HashMap<>();
  100. not_launch_from.put("not_launch_from", params.get("not_launch_from"));
  101. and.add(not_launch_from);
  102. }
  103.  
  104. //别名
  105. if(params.get("tag").toString().length()>0) {
  106. HashMap<String, Object> tag = new HashMap<>();
  107. tag.put("tag", params.get("tag"));
  108. and.add(tag);
  109. }
  110.  
  111. where.put("and", and);
  112. filter.put("where", where);
  113. md5s.put("filter", filter);
  114.  
  115. }//按照filter条件筛选特定用户群, 具体请参照filter参数
  116. else if("customizedcast".equals(params.get("type"))) {
  117.  
  118. //别名
  119. if(params.get("alias_type").toString().length()>0) {
  120. md5s.put("alias_type", params.get("alias_type"));
  121. }
  122.  
  123. if(params.get("alias").toString().length()>0) {
  124. md5s.put("alias", params.get("alias"));
  125. }
  126. //需要调用sdk
  127. }
  128.  
  129. //sound
  130. if(params.get("sound").toString().length()>0) {
  131. md5s.put("sound", params.get("sound"));
  132. }
  133.  
  134. //是否震动
  135. if(params.get("play_vibrate").toString().length()>0) {
  136. md5s.put("play_vibrate", params.get("play_vibrate"));
  137. }
  138.  
  139. //是否闪灯
  140. if(params.get("play_lights").toString().length()>0) {
  141. md5s.put("play_lights", params.get("play_lights"));
  142. }
  143.  
  144. //是否发出声音
  145. if(params.get("play_sound").toString().length()>0) {
  146. md5s.put("play_sound", params.get("play_sound"));
  147. }
  148.  
  149. //消息描述
  150. if(params.get("description").toString().length()>0) {
  151. md5s.put("description", params.get("description"));
  152. }
  153.  
  154. payload.put("extra", extra);
  155. payload.put("body", body);
  156. md5s.put("appkey", "----------");
  157. md5s.put("timestamp", System.currentTimeMillis());
  158. md5s.put("type", params.get("type"));
  159. md5s.put("payload", payload);
  160.  
  161. String url = "http://msg.umeng.com/api/send?sign="+this.md5("POST"+"http://msg.umeng.com/api/send"+JsonUtils.parseObjectToJson(md5s)+"-------你的App Master Secret---");
  162. String message = "";
  163. try {
  164. message = HttpClientUtil.doPostJson(url, JsonUtils.parseObjectToJson(md5s));
  165. } catch (Exception e) {
  166. e.printStackTrace();
  167. message = e.getMessage();
  168. }
  169. write(response,message);
  170. }

Android

想区分什么类型在app上传什么样的字段,通过tag设置更准确的发送通知

需要注意的是,Android 的 after_open 设置为go_custom ,可以设置自定义参数,没有参数打不开app,只想打开app 只能用go_app


JAVA web 使用有盟推送总结的更多相关文章

  1. java 集成友盟推送

    原文:https://blog.csdn.net/Athena072213/article/details/83414743 最近应公司业务需求需要完善友盟推送,认真看了官方文档后其实很简单,只需要细 ...

  2. 友盟推送 .NET (C#) 服务端 SDK rest api 调用库

    友盟推送 .NET SDK rest api 介绍 该版本是基于友盟推送2.3版本封装的,网上查询了下发现没有.NET版本的调用库,官方也没有封装.NET的版本,只有python.java.php版本 ...

  3. 极光推送和友盟推送,ios端和安卓端的后端调试设置

    我是最后端的,这两天搞了一个app项目,前端安卓使用友盟很方便,调试比较顺利,然后ios就遇到各种问题了,证书.发送成功推送不成功,测试时用的TestMode(),ios上架之后就必须用product ...

  4. IOS----友盟推送详解

    这两天好好的研究了下推送这功能,关于它我将分成两部分来讲,一.IOS手机端,二.Servlet服务端,今天先讲下IOS端 一.感受 下面讲下我对推送这个功能在IOS下的感受,这个算是我做了服务端的功能 ...

  5. 使用极光/友盟推送,APP进程杀死后为什么收不到推送(转)

    为什么会存在这样的 问题,刚开始的时候我也搞不清楚,之前用极光的时候杀死程序后也会收到推送,但最近重新再去集成时就完全不好使了,这我就纳闷了,虽然Google在高版本上的android上面不建议线程守 ...

  6. 友盟推送里面的Alias怎么用?可以理解成账号吗?

    友盟推送里面的Alias怎么用?可以理解成账号吗? 我们的App有自己的账号体系的,想在每次用户登陆的时候,给用户发一个欢迎消息. 看了一下友盟推送,里面有一个概念叫做Alias(别名),但是官方文档 ...

  7. iOS app 集成友盟推送问题

    之前做app推送主要是集成友盟SDK,在程序获取deviceToken时,老是提示如下错误: Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用 ...

  8. iOS集成友盟推送

    之前有写过利用Python自己写一个推送服务器, 今天说下如果集成友盟的推送服务 在这之前我们需要做一些准备动作 #1. 注册一个App ID #2. Enable Push Notification ...

  9. AppDelegate减负之常用三方封装 - 友盟推送篇

    之前分享过集成友盟推送的方法, 需要的朋友可以查看一下链接: http://www.cnblogs.com/zhouxihi/p/6533058.html 一般开发中我们比较多使用的三方有友盟推送, ...

随机推荐

  1. Linux内存管理之mmap详解

    转发之:http://blog.chinaunix.net/uid-26669729-id-3077015.html Linux内存管理之mmap详解 一. mmap系统调用 1. mmap系统调用  ...

  2. Keil软件常见配置

    1.tab键占据字节数 Edit-->Configuration-->Tab Size-->安装上默认2个空格,这里改为4,符合通用代码编辑器的处理. 2.编码配置 Edit--&g ...

  3. FineUIMvc随笔(3)不能忘却的回发(__doPostBack)

    声明:FineUIMvc(基础版)是免费软件,本系列文章适用于基础版. 用户反馈 有网友在官方论坛抛出了这么一个问题,似乎对 FineUIMvc 中的浏览器端与服务器端的交互方式很有异议. 这里面的关 ...

  4. zookeeper-分布式锁的代码实现-【每日五分钟搞定大数据】

    本文涉及到几个zookeeper简单的知识点,永久节点.有序节点.watch机制.比较基础,熟悉的就别看了跳过这篇吧 每个线程在/locks节点下创建一个临时有序节点test_lock_0000000 ...

  5. OSGI基础环境搭建

    1.安装jdk,步骤自行搜索 2.下载eclipse,用luna版本,下载地址: https://pan.baidu.com/s/1gdfmW5znU4fltsLCAo8tkg 提取码: nrg7 3 ...

  6. 如何让vba与java的TripleDES算法通用

    本文链接:http://www.cnblogs.com/Charltsing/p/TripleDES.html 众所周知,java默认采用的TripleDES算法是ECB+PKCS#5填充方式.网上可 ...

  7. MySQL和Oracle的区别

    由于SQL Server不常用,所以这里只针对MySQL数据库和Oracle数据库的区别 (1) 对事务的提交    MySQL默认是自动提交,而Oracle默认不自动提交,需要用户手动提交,需要在写 ...

  8. mysql 中Varchar 与char的区别

    一.字符与字节与编码关系 ASCII码中,一个英文字母(不分大小写)占一个字节的空间,一个中文汉字占两个字节的空间.一个二进制数字序列,在计算机中作为一个数字单元,一般为8位二进制数,换算为十进制.最 ...

  9. ibatis实战之插入数据(自动生成主键)

    ibatis实战之插入数据(自动生成主键) --------- 如果你将数据库设计为使用自动生成的主键,就可以使用ibatis的<selectKey>元素(该元素是<insert&g ...

  10. redis 运维手册

    redis cli命令 - milkty - 博客园https://www.cnblogs.com/kongzhongqijing/p/6867960.html Redis多个数据库 - EasonJ ...