移动app整合个推进行消息推送
首先前端代码写好之后进行发行打包:

然后再进行发行打包:

然后登录个推官网:

测试:

点击推送,在手机端就可以获取到信息了.
java代码测试:
package com.cxy.bean;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import com.gexin.rp.sdk.base.IAliasResult;
import com.gexin.rp.sdk.base.IBatch;
import com.gexin.rp.sdk.base.IIGtPush;
import com.gexin.rp.sdk.base.IPushResult;
import com.gexin.rp.sdk.base.impl.AppMessage;
import com.gexin.rp.sdk.base.impl.SingleMessage;
import com.gexin.rp.sdk.base.impl.Target;
import com.gexin.rp.sdk.base.uitls.AppConditions;
import com.gexin.rp.sdk.exceptions.RequestException;
import com.gexin.rp.sdk.http.IGtPush;
import com.gexin.rp.sdk.template.LinkTemplate;
import com.gexin.rp.sdk.template.NotificationTemplate;
import com.gexin.rp.sdk.template.TransmissionTemplate;
import com.gexin.rp.sdk.template.style.Style0; public class GetuiUtils { /*AppID:
kk36iGrKYvAPFLdEVhfru6
AppSecret:
qXTAXKDSye5hd2QA3FjsP2
AppKey:
Jux7ogPLMUAybHJcSOmgC7
MasterSecret:
II9oWPnaZK9heOl4keBmS9*/ private static String appId = "kk36iGrKYvAPFLdEVhfru6";
private static String appKey = "Jux7ogPLMUAybHJcSOmgC7";
private static String masterSecret = "II9oWPnaZK9heOl4keBmS9";
public static String host = "https://sdk.open.api.igexin.com/apiex.htm";
public static String CID_A = "81a3d3c3bee1adb51d306771af2aeb6a";//在打包后的APP的js中获取 var cId = plus.push.getClientInfo().clientid;
public static String CID_B = "bae837b470994d614f0773097b92dbf3";
public static IGtPush push; static {
push = new IGtPush(host, appKey, masterSecret);
} /**
* 绑定用户cid 别名
*
* @param Alias
* @param CID
* @return
*/
public static boolean bindAlias(String alias, String CID) {
IAliasResult bindSCid = push.bindAlias(appId, alias, CID);
if (bindSCid.getResult()) {
return true;
}
return false;
} /**
* 对单个用户推送消息
*
* @param alias
* @param msg
* @return
*/
public static boolean pushMessageToSingle(String cid, String text, String transMsg) {
IGtPush push = new IGtPush(host, appKey, masterSecret);
NotificationTemplate template = notificationTemplate("title", text, transMsg);
SingleMessage message = new SingleMessage();
message.setOffline(true);
// 离线有效时间,单位为毫秒,可选
message.setOfflineExpireTime( * * );
message.setData(template);
// 可选,1为wifi,0为不限制网络环境。根据手机处于的网络情况,决定是否下发
message.setPushNetWorkType();
Target target = new Target();
target.setAppId(appId);
target.setClientId(cid);
//target.setAlias(Alias);
IPushResult ret = null;
try {
ret = push.pushMessageToSingle(message, target);
} catch (RequestException e) {
e.printStackTrace();
ret = push.pushMessageToSingle(message, target, e.getRequestId());
}
if (ret != null && ret.getResponse() != null && ret.getResponse().containsKey("result")) {
System.out.println(ret.getResponse().toString());
if (ret.getResponse().get("result").toString().equals("ok") && ret.getResponse().containsKey("status")) {
return true;
}
}
return false;
} /**
* 指定应用的所有用户群发推送消息
*
* @param msg
*/
public static boolean pushtoAPP(String text, String transMsg) {
IGtPush push = new IGtPush(host, appKey, masterSecret); NotificationTemplate template = notificationTemplate("title", text, transMsg);
AppMessage message = new AppMessage();
message.setData(template); message.setOffline(true);
//离线有效时间,单位为毫秒,可选
message.setOfflineExpireTime( * * );
//推送给App的目标用户需要满足的条件
AppConditions cdt = new AppConditions();
List<String> appIdList = new ArrayList<String>();
appIdList.add(appId);
message.setAppIdList(appIdList);
//手机类型
List<String> phoneTypeList = new ArrayList<String>();
//省份
List<String> provinceList = new ArrayList<String>();
//自定义tag
List<String> tagList = new ArrayList<String>(); cdt.addCondition(AppConditions.PHONE_TYPE, phoneTypeList);
cdt.addCondition(AppConditions.REGION, provinceList);
cdt.addCondition(AppConditions.TAG, tagList);
message.setConditions(cdt); IPushResult ret = push.pushMessageToApp(message, "msg_toApp"); if (ret != null && ret.getResponse() != null && ret.getResponse().containsKey("result")) {
System.out.println(ret.getResponse().toString());
if (ret.getResponse().get("result").toString().equals("ok")) {
return true;
}
}
return false;
} /**
* 对单个用户推送透传消息
*
* @param alias
* @param title
* @param content
* @return
*/
public static boolean pushTransMessageToSingle(String cid, String msg) {
TransmissionTemplate template = transTemplate(cid, msg);
SingleMessage message = new SingleMessage();
message.setOffline(true);
// 离线有效时间,单位为毫秒,可选
message.setOfflineExpireTime( * * );
message.setData(template);
// 可选,1为wifi,0为不限制网络环境。根据手机处于的网络情况,决定是否下发
message.setPushNetWorkType();
Target target = new Target();
target.setAppId(appId);
target.setClientId(cid);
IPushResult ret = null;
try {
ret = push.pushMessageToSingle(message, target);
} catch (RequestException e) {
e.printStackTrace();
ret = push.pushMessageToSingle(message, target, e.getRequestId());
}
if (ret != null && ret.getResponse() != null && ret.getResponse().containsKey("result")) {
System.out.println(ret.getResponse().toString());
if (ret.getResponse().get("result").toString().equals("ok") && ret.getResponse().containsKey("status")) {
return true;
}
}
return false;
} public static void pushMessageToIBatch(List<String> alias, String msg) {
IBatch batch = push.getBatch();
IPushResult ret = null;
try {
for (int i = ; i < alias.size(); i++) {
// 构建客户a的透传消息a
constructClientTransMsg(alias.get(i), msg, batch);
}
// 构建客户B的点击通知打开网页消息b
// constructClientLinkMsg(CID_B,"msgB",batch);
ret = batch.submit();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(ret.getResponse().toString());
} private static NotificationTemplate notificationTemplate(String title, String text, String obj) {
NotificationTemplate template = new NotificationTemplate();
// 设置APPID与APPKEY
template.setAppId(appId);
template.setAppkey(appKey);
// 透传消息设置,1为强制启动应用,客户端接收到消息后就会立即启动应用;2为等待应用启动
template.setTransmissionType();
template.setTransmissionContent(obj);
// 设置定时展示时间
// template.setDuration("2015-01-16 11:40:00", "2015-01-16 12:24:00");
Style0 style = new Style0();
// 设置通知栏标题与内容
style.setTitle(title);
style.setText(text);
// 配置通知栏图标
style.setLogo("XXX");
// 配置通知栏网络图标
//style.setLogoUrl("");
// 设置通知是否响铃,震动,或者可清除
style.setRing(true);
style.setVibrate(true);
style.setClearable(true);
template.setStyle(style); return template;
} private static TransmissionTemplate transTemplate(String cid, String msg) {
TransmissionTemplate template = new TransmissionTemplate();
// 设置APPID与APPKEY
template.setAppId(appId);
template.setAppkey(appKey);
template.setTransmissionContent(msg);
template.setTransmissionType(); // 这个Type为int型,填写1则自动启动app return template;
}
//点击通知打开应用模板
public static void constructClientTransMsg(String cid, String msg, IBatch batch) throws Exception { SingleMessage message = new SingleMessage();
NotificationTemplate template = new NotificationTemplate();
// TransmissionTemplate template = new TransmissionTemplate();//自定义模板
template.setAppId(appId);
template.setAppkey(appKey);
template.setTransmissionContent(msg);//消息内容
template.setTransmissionType(); // 这个Type为int型,填写1则自动启动app
Style0 style = new Style0(); // 设置通知栏标题与内容
style.setTitle("第一个通知");
style.setText(msg); // 配置通知栏图标
style.setLogo("icon.png"); // 配置通知栏网络图标
style.setLogoUrl("");//网络图标地址
// 设置通知是否响铃,震动,或者可清除
style.setRing(true);
style.setVibrate(true);
style.setClearable(true);
template.setStyle(style); message.setData(template);
message.setOffline(true);
message.setOfflineExpireTime( * * ); // 设置推送目标,填入appid和clientId
Target target = new Target();
target.setAppId(appId);
target.setClientId(cid);
batch.add(message, target);
} //点击通知打开网页消息
public static void constructClientLinkMsg(String cid, String msg, IBatch batch) throws Exception { SingleMessage message = new SingleMessage();
LinkTemplate template = new LinkTemplate();
template.setAppId(appId);
template.setAppkey(appKey);
template.setTitle("title");
template.setText(msg);
template.setLogo("push.png");
template.setLogoUrl("logoUrl");
template.setUrl("http://www.baidu.com"); message.setData(template);
message.setOffline(true);
message.setOfflineExpireTime( * ); // 设置推送目标,填入appid和clientId
Target target = new Target();
target.setAppId(appId);
target.setClientId(cid);
batch.add(message, target);
} }
测试:
public static void main(String[] args) throws IOException {
IIGtPush push = new IGtPush(host, appKey, masterSecret);
IBatch batch = push.getBatch();
try {
//构建客户a的透传消息a
GetuiUtils.constructClientTransMsg(CID_A, "msgA", batch);
//构建客户B的点击通知打开网页消息b
// constructClientLinkMsg(CID_B, "msgB", batch);
} catch (Exception e) {
e.printStackTrace();
}
batch.submit();
}
注意也可以进行异步推送,在springboot中使用@async这个来进行异步推送
首先需要引入pom依赖:
将下边的依赖放到maven项目的 pom.xml 中:
<dependency>
<groupId>com.gexin.platform</groupId>
<artifactId>gexin-rp-sdk-http</artifactId>
<version>4.1.0.0</version>
</dependency> 然后再增加一个repository到 pom.xml 中:
<repositories>
<repository>
<id>getui-nexus</id>
<url>http://mvn.gt.igexin.com/nexus/content/repositories/releases/</url>
</repository>
</repositories>
在pom文件中引入:
在安卓4.0以后需要花钱集成厂商sdk,由于厂商的系统会自动杀死相关未使用的app,从而导致不能推送,需要跟个推客服联系
如果需要单独推送的话需要前端获取cid,然后存入数据,再进行存储,和推送
移动app整合个推进行消息推送的更多相关文章
- springboot整合websocket实现一对一消息推送和广播消息推送
maven依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
- 浅谈APP消息推送
作为移动端APP产品运营最重要的运营手段,消息推送(push)被越来越多的APP厂商所重视,在信息泛滥的移动互联网时代,手机APP应用安装得越来越多,小小的手机屏幕每天收到的消息推送也越来越多,站在用 ...
- 使用WeCloud消息推送接口发送消息NodeJs版
WeCloud是一家初创公司的产品,眼下主要在做Android和IOS消息推送这块.他们提供了用于向设备发送消息的协议,详细协议内容见消息推送协议. 这篇文章将使用NodeJs基于这个推送协议完毕向A ...
- IOS开发之实现App消息推送
转自:http://blog.csdn.net/shenjie12345678/article/details/41120637 第一部分 首先第一步当然是介绍一下苹果的推送机制(APNS)咯(ps: ...
- IOS开发之实现App消息推送(最新)
好久没有写过博客啦,今天就由本菜鸟给大家做一个简单的IOSApp消息推送教程吧!一切从0开始,包括XCode6, IOS8, 以及苹果开发者中心最新如何注册应用,申请证书以及下载配置概要文件,相信很多 ...
- IOS8开发之实现App消息推送
第一部分 Apple Push Notification Service 首先第一步当然是介绍一下苹果的推送机制(APNS)咯(ps:其实每一篇教程都有),先来看一张苹果官方对其推送做出解释的概要图. ...
- App设计:消息推送和界面路由跳转
概要 app消息推送.显示通知栏,点击跳转页面是很一般的功能了,下面以个推为例演示push集成,消息处理模块及app内部路由模块的简单设计. 推送 推送sdk集成 集成sdk步骤根据文档一步步做就行了 ...
- python 全栈开发,Day131(向app推送消息,玩具端消息推送)
先下载github代码,下面的操作,都是基于这个版本来的! https://github.com/987334176/Intelligent_toy/archive/v1.4.zip 注意:由于涉及到 ...
- APP的消息推送(极光推送)
APP的消息推送,使用的第三方平台是极光推送 简单案例(以Thinkphp为例): 1.下载下载PHPSDK 2.把PHPSDK目录下的jpush-api-php-client-3.5.1\src\J ...
随机推荐
- How to clear fmadm log or FMA faults log (ZT)
Here are the step by step of clearing the FMA faults on most of Oracle/Sun server. Work perfectly on ...
- 问题:oracle 计算年龄;结果:oracle中根据生日计算年龄的问题
SELECT FLOOR(MONTHS_BETWEEN(SYSDATE,birthday)/12,1) FROM ltteacherinfo where name='朱雪东111'这个报错ORA 00 ...
- 向vsftp服务器上传文件报“550 Permission denied”错误的解决办法
上传文件: ftp> mput db.iso 550 Permission denied 原因:vsftp默认配置不允许上传文件. 解决:修改/etc/vsftpd.conf 将“write_e ...
- sqlplus--spool命令参数详解
sqlplus--SPOOL参数详解 Spool是Oracle快速导出数据的工具,是sqlplus的指令,不是sql语法里的东西 一.Spool常用的设置set arraysize 5000; // ...
- MyBatis总结二:增删改查
上一篇讲述了MyBatis的快速入门,下面在此基础上进行增删改查的操作: 首先定义dao层的接口: package com.zy.dao; import com.zy.domain.User; imp ...
- 【总结整理】JS的继承
参考阮一峰的文章:http://javascript.ruanyifeng.com/oop/inheritance.html#toc4 function Shape() { this.x = 0; t ...
- mt_rand()函数、str_shuffle() 函数、join() 函数
mt_rand() 使用 Mersenne Twister 算法返回随机整数. 语法 mt_rand(min,max) 定义和用法 str_shuffle() 函数随机地打乱字符串中的所有字符. 语法 ...
- SingletonPattern(23种设计模式之一)
设计模式六大原则(1):单一职责原则 设计模式六大原则(2):里氏替换原则 设计模式六大原则(3):依赖倒置原则 设计模式六大原则(4):接口隔离原则 设计模式六大原则(5):迪米特法则 设计模式六大 ...
- 高性能MySQL笔记-第5章Indexing for High Performance-005聚集索引
一.聚集索引介绍 1.什么是聚集索引? InnoDB’s clustered indexes actually store a B-Tree index and the rows together i ...
- 100722E The Bookcase
传送门 题目大意 给你一些书的高度和宽度,有一个一列三行书柜,要求放进去书后,三行书柜的高的和乘以书柜的宽度最小.问这个值最小是多少. 分析 我们可以先将所有书按照高度降序排好,这样对于每一层只要放过 ...