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 一般开发中我们比较多使用的三方有友盟推送, ...
随机推荐
- Unity编辑器:清空控制台(Console)
static MethodInfo clearMethod = null; /// <summary> /// 清空log信息 /// </summary> private s ...
- ASP.NET Core 2.1 源码学习之 Options[1]:Configure
配置的本质就是字符串的键值对,但是对于面向对象语言来说,能使用强类型的配置是何等的爽哉! 目录 ASP.NET Core 配置系统 强类型的 Options Configure 方法 Configur ...
- Taro、Weex、Hippy 齐聚IMWebConf 2018!
IMWebConf 2018 前端大会,10 月 14 日重磅来袭! 想了解 2018 前端前沿技术和发展趋势?想挖掘前端更深远的价值?就在这个秋季,第七届 IMWebConf 大会重磅来袭,我们邀请 ...
- docker安装并修改Nginx镜像
1.安装nginx镜像,命令:docker pull nginx 2.创建nginx容器,并启动,命令:docker run --name webserver -d -p 192.168.51.227 ...
- Deflation Methods for Sparse PCA
目录 背景 总括 Hotelling's deflation 公式 特点 Projection deflation 公式 特点 Schur complement deflation Orthogona ...
- Python云端系统开发入门 pycharm代码
html <!DOCTYPE html><html><head> <meta charset="UTF-8"> <title& ...
- openstack-KVM安装与使用
一.KVM安装 1.安装条件 VT-x BIOS Intel9R) Virtualization Tech [Enabled] cat /proc/cpuinfo | grep -e vmx -e n ...
- Python_守护进程、锁、信号量、事件、队列
1.创建进程 守护进程(*****) _.daemon = True # _进程成为守护进程 守护进程也是一个子进程. 主进程的<代码>执行结束之后守护进程自动结束. import ti ...
- Vue父子传值
昨天创建完项目以后,今日首先使用项目来做一个简单的导航栏体会一下Vue的使用 1.项目的结构: 2.首先在Vheader.Vue中编辑代码: <template> <header c ...
- bat 文本合并
小工具—把多个TXT文件合成一个 - TTXS_RS的博客 - CSDN博客https://blog.csdn.net/TTXS_RS/article/details/79743384 把所有文本文件 ...