JAVA web 使用有盟推送总结
仔细阅读文档,下边的都是废话。
为了省事,iOS和Android 提供了所有了参数,需要那个了修改传参。
- //ios actionURL为自定义参数
- $.ajax({
- type : "POST",
- url:_basePath + "/------.html",
- data:{"testing":"1","type":"groupcast","title":"推送标题","subtitle":"","body":"推送内容"
- ,"description":"","actionURL":""
- ,"device_tokens":"","app_version":"","launch_from":"","not_launch_from":"","alias_type":"","alias":"","tag":""
- ,"badge":"","sound":"","available":"","category":""
- ,"policy":"","start_time":"","expire_time":""},
- dataType : "JSON",
- success : function(res) {
- alert(res);
- }
- });
- //Android go_custom 可以设置自定义参数,没有参数打不开app,只想打开app 只能用go_app
- $.ajax({
- type : "POST",
- url:_basePath + "/-------.html",
- dataType : "JSON",
- data:{"testing":"1","type":"groupcast","ticker":"tuisong","title":"挑剔","text":"内容","description":""
- ,"after_open": "go_custom", "url":"https://www.baidu.com","activity":"","custom":"","device_tokens":""
- ,"app_version":"","alias_type":"","alias":"","tag":"北京市北京市海淀区"
- ,"policy":"","start_time":"","expire_time":"","out_biz_no":"","launch_from":"","not_launch_from":""
- ,"sound":"","play_vibrate":"","play_lights":"","play_sound":""},
- success : function(res) {
- alert(res);
- }
- });
- }
JS提交参数
java 后台签名上传
- //MD5
- private String md5(String value){
- String result = null;
- MessageDigest md5 = null;
- try{
- md5 = MessageDigest.getInstance("MD5");
- md5.update((value).getBytes("UTF-8"));
- }catch (NoSuchAlgorithmException error){
- error.printStackTrace();
- }catch (UnsupportedEncodingException e){
- e.printStackTrace();
- }
- byte b[] = md5.digest();
- int i;
- StringBuffer buf = new StringBuffer("");
- for(int offset=0; offset<b.length; offset++){
- i = b[offset];
- if(i<0){
- i+=256;
- }
- if(i<16){
- buf.append("0");
- }
- buf.append(Integer.toHexString(i));
- }
- result = buf.toString();
- return result;
- }
java md5签名
后台参数操作
- // 发送推送 iOS
- @RequestMapping("/=-------------OS")
- public void coreManagementsendPushiOS(HttpServletRequest request, HttpServletResponse response) throws Exception {
- DefaultValidate validate = new DefaultValidate();
- Map<String, Object> params = read(request, validate);
- HashMap<String, Object> aps = new HashMap<>();
- HashMap<String, Object> payload = new HashMap<>();
- HashMap<String, Object> md5s = new HashMap<>();
- HashMap<String, Object> alert = new HashMap<>();
- //主标题
- if(params.get("title").toString().length()>0) {
- alert.put("title", params.get("title"));
- }
- //副标题
- if(params.get("subtitle").toString().length()>0) {
- alert.put("subtitle", params.get("subtitle"));
- }
- //内容
- if(params.get("body").toString().length()>0) {
- alert.put("body", params.get("body"));
- }
- aps.put("alert",alert);
- md5s.put("appkey", "-------");
- md5s.put("timestamp", System.currentTimeMillis());
- //0正式 1测试
- if(params.get("testing").toString().length()>0) {
- if("1".equals(params.get("testing"))) {
- md5s.put("production_mode", false);
- }
- }
- //判断加入
- //发送类型 单播广播等
- if("unicast".equals(params.get("type"))) {
- md5s.put("device_tokens", params.get("device_tokens"));
- } //列表播 英文,隔开,不超500
- else if("listcast".equals(params.get("type"))) {
- md5s.put("device_tokens", params.get("device_tokens"));
- }//groupcast组播 按照filter条件筛选特定用户群, 具体请参照filter参数
- else if("groupcast".equals(params.get("type"))) {
- // 多个标签 安定 or 标签
- HashMap<String, Object> where = new HashMap<>();
- List<Map<String, Object>> and =new ArrayList<>();
- HashMap<String, Object> filter = new HashMap<>();
- //应用版本
- if(params.get("app_version").toString().length()>0) {
- HashMap<String, Object> app_version = new HashMap<>();
- app_version.put("app_version", params.get("app_version"));
- and.add(app_version);
- }
- //一段时间呢你活跃
- if(params.get("launch_from").toString().length()>0) {
- HashMap<String, Object> launch_from = new HashMap<>();
- launch_from.put("launch_from", params.get("launch_from"));
- and.add(launch_from);
- }
- //一段时间内不活跃活跃
- if(params.get("not_launch_from").toString().length()>0) {
- HashMap<String, Object> not_launch_from = new HashMap<>();
- not_launch_from.put("not_launch_from", params.get("not_launch_from"));
- and.add(not_launch_from);
- }
- //别名
- if(params.get("tag").toString().length()>0) {
- HashMap<String, Object> tag = new HashMap<>();
- tag.put("tag", params.get("tag"));
- and.add(tag);
- }
- where.put("and", and);
- filter.put("where", where);
- md5s.put("filter", filter);
- }//按照filter条件筛选特定用户群, 具体请参照filter参数
- else if("customizedcast".equals(params.get("type"))) {
- //别名
- if(params.get("alias_type").toString().length()>0) {
- md5s.put("alias_type", params.get("alias_type"));
- }
- if(params.get("alias").toString().length()>0) {
- md5s.put("alias", params.get("alias"));
- }
- }
- //aps
- if(params.get("badge").toString().length()>0) {
- aps.put("badge", params.get("badge"));
- }
- if(params.get("sound").toString().length()>0) {
- aps.put("sound", params.get("sound"));
- }
- if(params.get("category").toString().length()>0) {
- aps.put("category", params.get("category"));
- }
- //自定义内容 payload里边 actionURL:url
- if(params.get("actionURL").toString().length()>0) {
- payload.put("actionURL", params.get("actionURL"));
- }
- //发送策略
- if(params.get("policy").toString().length()>0) {
- HashMap<String, Object> policy = new HashMap<>();
- //定时发送
- if(params.get("start_time").toString().length()>0) {
- policy.put("start_time", params.get("start_time"));
- }
- //过期时间
- if(params.get("expire_time").toString().length()>0) {
- policy.put("expire_time", params.get("expire_time"));
- }
- md5s.put("policy", policy);
- }
- //消息描述
- if(params.get("description").toString().length()>0) {
- md5s.put("description", params.get("description"));
- }
- payload.put("aps", aps);
- md5s.put("type", params.get("type"));
- md5s.put("payload", payload);
- String url = "http://msg.umeng.com/api/send?sign="+this.md5("POST"+"http://msg.umeng.com/api/send"+JsonUtils.parseObjectToJson(md5s)+"------你的App Master Secret------");
- String message = "";
- try {
- message = HttpClientUtil.doPostJsonAuth(url, JsonUtils.parseObjectToJson(md5s));
- } catch (Exception e) {
- e.printStackTrace();
- message = e.getMessage();
- }
- write(response,message);
- }
iOS
- // 发送推送 Android
- @RequestMapping("------------")
- public void core-----Push(HttpServletRequest request, HttpServletResponse response) throws Exception {
- DefaultValidate validate = new DefaultValidate();
- Map<String, Object> params = read(request, validate);
- HashMap<String, Object> body = new HashMap<>();
- HashMap<String, Object> payload = new HashMap<>();
- HashMap<String, Object> md5s = new HashMap<>();
- HashMap<String, Object> extra = new HashMap<>();
- body.put("ticker",params.get("ticker"));
- body.put("title",params.get("title"));
- body.put("text",params.get("text"));
- body.put("after_open",params.get("after_open"));
- payload.put("display_type","notification");
- //0正式 1测试
- if(params.get("testing").toString().length()>0) {
- if("1".equals(params.get("testing"))) {
- md5s.put("production_mode", false);
- }
- }
- //extra 自定义参数
- extra.put("url", params.get("url"));
- //打开应用行为
- if("go_url".equals(params.get("after_open"))) {
- body.put("url",params.get("url"));
- }
- //特定行为
- else if("go_activity".equals(params.get("after_open"))) {
- body.put("activity",params.get("activity"));
- }
- //用户自定义
- else if("go_custom".equals(params.get("after_open"))) {
- body.put("custom",params.get("custom"));
- }
- //发送策略
- if(params.get("policy").toString().length()>0) {
- HashMap<String, Object> policy = new HashMap<>();
- //定时发送
- if(params.get("start_time").toString().length()>0) {
- policy.put("start_time", params.get("start_time"));
- }
- //过期时间
- if(params.get("expire_time").toString().length()>0) {
- policy.put("expire_time", params.get("expire_time"));
- }
- //消息标识
- if(params.get("out_biz_no").toString().length()>0) {
- policy.put("out_biz_no", params.get("out_biz_no"));
- }
- md5s.put("policy", policy);
- }
- //判断加入
- //发送类型 单播广播等
- if("unicast".equals(params.get("type"))) {
- md5s.put("device_tokens", params.get("device_tokens"));
- } //列表播 英文,隔开,不超500
- else if("listcast".equals(params.get("type"))) {
- md5s.put("device_tokens", params.get("device_tokens"));
- }//按照filter条件筛选特定用户群, 具体请参照filter参数
- else if("groupcast".equals(params.get("type"))) {
- // 多个标签 安定 or 标签
- HashMap<String, Object> where = new HashMap<>();
- List<Map<String, Object>> and =new ArrayList<>();
- HashMap<String, Object> filter = new HashMap<>();
- //应用版本
- if(params.get("app_version").toString().length()>0) {
- HashMap<String, Object> app_version = new HashMap<>();
- app_version.put("app_version", params.get("app_version"));
- and.add(app_version);
- }
- //一段时间呢你活跃
- if(params.get("launch_from").toString().length()>0) {
- HashMap<String, Object> launch_from = new HashMap<>();
- launch_from.put("launch_from", params.get("launch_from"));
- and.add(launch_from);
- }
- //一段时间内不活跃活跃
- if(params.get("not_launch_from").toString().length()>0) {
- HashMap<String, Object> not_launch_from = new HashMap<>();
- not_launch_from.put("not_launch_from", params.get("not_launch_from"));
- and.add(not_launch_from);
- }
- //别名
- if(params.get("tag").toString().length()>0) {
- HashMap<String, Object> tag = new HashMap<>();
- tag.put("tag", params.get("tag"));
- and.add(tag);
- }
- where.put("and", and);
- filter.put("where", where);
- md5s.put("filter", filter);
- }//按照filter条件筛选特定用户群, 具体请参照filter参数
- else if("customizedcast".equals(params.get("type"))) {
- //别名
- if(params.get("alias_type").toString().length()>0) {
- md5s.put("alias_type", params.get("alias_type"));
- }
- if(params.get("alias").toString().length()>0) {
- md5s.put("alias", params.get("alias"));
- }
- //需要调用sdk
- }
- //sound
- if(params.get("sound").toString().length()>0) {
- md5s.put("sound", params.get("sound"));
- }
- //是否震动
- if(params.get("play_vibrate").toString().length()>0) {
- md5s.put("play_vibrate", params.get("play_vibrate"));
- }
- //是否闪灯
- if(params.get("play_lights").toString().length()>0) {
- md5s.put("play_lights", params.get("play_lights"));
- }
- //是否发出声音
- if(params.get("play_sound").toString().length()>0) {
- md5s.put("play_sound", params.get("play_sound"));
- }
- //消息描述
- if(params.get("description").toString().length()>0) {
- md5s.put("description", params.get("description"));
- }
- payload.put("extra", extra);
- payload.put("body", body);
- md5s.put("appkey", "----------");
- md5s.put("timestamp", System.currentTimeMillis());
- md5s.put("type", params.get("type"));
- md5s.put("payload", payload);
- String url = "http://msg.umeng.com/api/send?sign="+this.md5("POST"+"http://msg.umeng.com/api/send"+JsonUtils.parseObjectToJson(md5s)+"-------你的App Master Secret---");
- String message = "";
- try {
- message = HttpClientUtil.doPostJson(url, JsonUtils.parseObjectToJson(md5s));
- } catch (Exception e) {
- e.printStackTrace();
- message = e.getMessage();
- }
- write(response,message);
- }
Android
想区分什么类型在app上传什么样的字段,通过tag设置更准确的发送通知
需要注意的是,Android 的 after_open 设置为go_custom ,可以设置自定义参数,没有参数打不开app,只想打开app 只能用go_app
JAVA web 使用有盟推送总结的更多相关文章
- java 集成友盟推送
原文:https://blog.csdn.net/Athena072213/article/details/83414743 最近应公司业务需求需要完善友盟推送,认真看了官方文档后其实很简单,只需要细 ...
- 友盟推送 .NET (C#) 服务端 SDK rest api 调用库
友盟推送 .NET SDK rest api 介绍 该版本是基于友盟推送2.3版本封装的,网上查询了下发现没有.NET版本的调用库,官方也没有封装.NET的版本,只有python.java.php版本 ...
- 极光推送和友盟推送,ios端和安卓端的后端调试设置
我是最后端的,这两天搞了一个app项目,前端安卓使用友盟很方便,调试比较顺利,然后ios就遇到各种问题了,证书.发送成功推送不成功,测试时用的TestMode(),ios上架之后就必须用product ...
- IOS----友盟推送详解
这两天好好的研究了下推送这功能,关于它我将分成两部分来讲,一.IOS手机端,二.Servlet服务端,今天先讲下IOS端 一.感受 下面讲下我对推送这个功能在IOS下的感受,这个算是我做了服务端的功能 ...
- 使用极光/友盟推送,APP进程杀死后为什么收不到推送(转)
为什么会存在这样的 问题,刚开始的时候我也搞不清楚,之前用极光的时候杀死程序后也会收到推送,但最近重新再去集成时就完全不好使了,这我就纳闷了,虽然Google在高版本上的android上面不建议线程守 ...
- 友盟推送里面的Alias怎么用?可以理解成账号吗?
友盟推送里面的Alias怎么用?可以理解成账号吗? 我们的App有自己的账号体系的,想在每次用户登陆的时候,给用户发一个欢迎消息. 看了一下友盟推送,里面有一个概念叫做Alias(别名),但是官方文档 ...
- iOS app 集成友盟推送问题
之前做app推送主要是集成友盟SDK,在程序获取deviceToken时,老是提示如下错误: Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用 ...
- iOS集成友盟推送
之前有写过利用Python自己写一个推送服务器, 今天说下如果集成友盟的推送服务 在这之前我们需要做一些准备动作 #1. 注册一个App ID #2. Enable Push Notification ...
- AppDelegate减负之常用三方封装 - 友盟推送篇
之前分享过集成友盟推送的方法, 需要的朋友可以查看一下链接: http://www.cnblogs.com/zhouxihi/p/6533058.html 一般开发中我们比较多使用的三方有友盟推送, ...
随机推荐
- Linux内存管理之mmap详解
转发之:http://blog.chinaunix.net/uid-26669729-id-3077015.html Linux内存管理之mmap详解 一. mmap系统调用 1. mmap系统调用 ...
- Keil软件常见配置
1.tab键占据字节数 Edit-->Configuration-->Tab Size-->安装上默认2个空格,这里改为4,符合通用代码编辑器的处理. 2.编码配置 Edit--&g ...
- FineUIMvc随笔(3)不能忘却的回发(__doPostBack)
声明:FineUIMvc(基础版)是免费软件,本系列文章适用于基础版. 用户反馈 有网友在官方论坛抛出了这么一个问题,似乎对 FineUIMvc 中的浏览器端与服务器端的交互方式很有异议. 这里面的关 ...
- zookeeper-分布式锁的代码实现-【每日五分钟搞定大数据】
本文涉及到几个zookeeper简单的知识点,永久节点.有序节点.watch机制.比较基础,熟悉的就别看了跳过这篇吧 每个线程在/locks节点下创建一个临时有序节点test_lock_0000000 ...
- OSGI基础环境搭建
1.安装jdk,步骤自行搜索 2.下载eclipse,用luna版本,下载地址: https://pan.baidu.com/s/1gdfmW5znU4fltsLCAo8tkg 提取码: nrg7 3 ...
- 如何让vba与java的TripleDES算法通用
本文链接:http://www.cnblogs.com/Charltsing/p/TripleDES.html 众所周知,java默认采用的TripleDES算法是ECB+PKCS#5填充方式.网上可 ...
- MySQL和Oracle的区别
由于SQL Server不常用,所以这里只针对MySQL数据库和Oracle数据库的区别 (1) 对事务的提交 MySQL默认是自动提交,而Oracle默认不自动提交,需要用户手动提交,需要在写 ...
- mysql 中Varchar 与char的区别
一.字符与字节与编码关系 ASCII码中,一个英文字母(不分大小写)占一个字节的空间,一个中文汉字占两个字节的空间.一个二进制数字序列,在计算机中作为一个数字单元,一般为8位二进制数,换算为十进制.最 ...
- ibatis实战之插入数据(自动生成主键)
ibatis实战之插入数据(自动生成主键) --------- 如果你将数据库设计为使用自动生成的主键,就可以使用ibatis的<selectKey>元素(该元素是<insert&g ...
- redis 运维手册
redis cli命令 - milkty - 博客园https://www.cnblogs.com/kongzhongqijing/p/6867960.html Redis多个数据库 - EasonJ ...