码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA web 使用有盟推送总结

时间:2018-02-09 15:05:02      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:port   def   put   integer   多个   convert   nic   ida   上传   

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

为了省事,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 使用有盟推送总结

标签:port   def   put   integer   多个   convert   nic   ida   上传   

原文地址:https://www.cnblogs.com/xujiahui/p/8434589.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!