个推的作用:可以为手机端的app使用者推送消息,而不是通过手机上的app对用户发送消息。所以用户是被动的接收信息。当然不只是只有对用户弹出窗口的这种方式,也可以把信息推送给app,让app决定对用户实行怎么样的操作,例如在app的栏目中显示出有新信息的图标,以便提高用户体验。

个推的官网http://www.igetui.com/

该api支持Android和iso的推送。

下载个推的sdk,里面有各种不同文档,其中有android的apk的安装文件,可以进行推送的测试。

  1. /**
  2. * 推送的基类
  3. * @author hj
  4. */
  5. public abstract class PushBase {
  6. protected static final String APPID = "b03c5cfef65ed30108f0a3fd82c3f6b4";
  7. protected static final String APPKEY = "110000";
  8. protected static final String MASTERSECRET = "a02a76119b20d4e31620d7597a3b4f35";
  9. protected static final String CLIENTID = "f8b14fc288a21bc3d675190e9a4db0a4";
  10. protected static final String API = "http://sdk.open.api.igexin.com/apiex.htm";     //OpenService接口地址
  11. protected static String getDate(){
  12. Date date = new Date();
  13. return date.toLocaleString();
  14. }
  15. }

对多个app进行推送:

  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import com.gexin.rp.sdk.base.IIGtPush;
  4. import com.gexin.rp.sdk.base.IPushResult;
  5. import com.gexin.rp.sdk.base.impl.AppMessage;
  6. import com.gexin.rp.sdk.http.IGtPush;
  7. import com.gexin.rp.sdk.template.LinkTemplate;
  8. public class PushMessageToAppTest extends PushBase{
  9. public static void main(String[] args) {
  10. // 推送主类
  11. IIGtPush push = new IGtPush(API, APPKEY, MASTERSECRET);
  12. try {
  13. AppMessage message = new AppMessage();
  14. //通知模版:支持TransmissionTemplate、LinkTemplate、NotificationTemplate,此处以LinkTemplate为例
  15. //在通知栏显示一条含图标、标题等的通知,用户点击可打开您指定的网页
  16. LinkTemplate template = new LinkTemplate();
  17. template.setAppId(APPID);                               //应用APPID
  18. template.setAppkey(APPKEY);                         //应用APPKEY
  19. //通知属性设置:如通知的标题,内容
  20. template.setTitle("填写通知标题");                        // 通知标题
  21. template.setText("填写通知内容");                 // 通知内容
  22. template.setLogo("hello.png");
  23. //          template.setIsRing(true);                   // 收到通知是否响铃,可选,默认响铃
  24. //          template.setIsVibrate(true);                    // 收到通知是否震动,可选,默认振动
  25. //          template.setIsClearable(true);              // 通知是否可清除,可选,默认可清除
  26. template.setUrl("http://baidu.com");        //点击通知后打开的网页地址,你可以设定你希望跳转的网页地址如http://www.igetui.com
  27. message.setData(template);
  28. //          message.setOffline(true);       //用户当前不在线时,是否离线存储,可选,默认不存储
  29. //          message.setOfflineExpireTime(72 * 3600 * 1000);     //离线有效时间,单位为毫秒,可选
  30. List<String> appIdList = new ArrayList<String>();
  31. appIdList.add(APPID);
  32. List<String> phoneTypeList = new ArrayList<String>();//通知接收者的手机操作系统类型,可选
  33. phoneTypeList.add("ANDROID");
  34. List<String> provinceList = new ArrayList<String>();        //通知接收者所在省份,可选
  35. provinceList.add("浙江");
  36. provinceList.add("上海");
  37. provinceList.add("北京");
  38. List<String> tagList = new ArrayList<String>();         //通知接收者的标签用户,可选
  39. tagList.add("填写tags名称");
  40. message.setAppIdList(appIdList);
  41. message.setPhoneTypeList(phoneTypeList);
  42. message.setProvinceList(null);
  43. message.setTagList(null);
  44. IPushResult ret = push.pushMessageToApp(message);
  45. System.out.println(ret.getResponse().toString());
  46. } catch (Exception e) {
  47. e.printStackTrace();
  48. }
  49. }
  50. }

对单个app的多个用户进行推送:

  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import com.gexin.rp.sdk.base.IIGtPush;
  4. import com.gexin.rp.sdk.base.IPushResult;
  5. import com.gexin.rp.sdk.base.impl.ListMessage;
  6. import com.gexin.rp.sdk.base.impl.Target;
  7. import com.gexin.rp.sdk.http.IGtPush;
  8. import com.gexin.rp.sdk.template.NotificationTemplate;
  9. //可接收多个用户,最多为50个
  10. public class PushMessageToListTest extends PushBase{
  11. public static void main(String[] args) {
  12. //显示每个用户的用户状态,false:不显示,true:显示
  13. System.setProperty("gexin.rp.sdk.pushlist.needDetails", "true");
  14. // 推送主类
  15. IIGtPush push = new IGtPush(API, APPKEY, MASTERSECRET);
  16. try {
  17. ListMessage message = new ListMessage();
  18. //通知模版:支持TransmissionTemplate、LinkTemplate、NotificationTemplate,此处以NotificationTemplate为例
  19. //在通知栏显示一条含图标、标题等的通知,用户点击后激活您的应用
  20. NotificationTemplate template = new NotificationTemplate();
  21. template.setAppId(APPID);                           //应用APPID
  22. template.setAppkey(APPKEY);                         //应用APPKEY
  23. //通知属性设置:如通知的标题,内容
  24. template.setTitle("此处填写通知标题"+getDate());                    // 通知标题
  25. template.setText("此处填写通知内容"+getDate());                 // 通知内容
  26. template.setLogo("push.png");               // 通知图标,需要客户端开发时嵌入
  27. template.setIsRing(false);                  // 收到通知是否响铃,可选,默认响铃
  28. //          template.setIsVibrate(true);                    // 收到通知是否震动,可选,默认振动
  29. template.setIsClearable(true);              // 通知是否可清除,可选,默认可清除
  30. template.setTransmissionType(2);                // 收到消息是否立即启动应用,1为立即启动,2则广播等待客户端自启动
  31. template.setTransmissionContent("你需要透传的内容"+getDate());  // 透传内容(点击通知后SDK将透传内容传给你的客户端,需要客户端做相应开发)
  32. message.setData(template);
  33. //          message.setOffline(true);       //用户当前不在线时,是否离线存储,可选,默认不存储
  34. //          message.setOfflineExpireTime(72 * 3600 * 1000);     //离线有效时间,单位为毫秒,可选
  35. // 接收者
  36. List<Target> targets = new ArrayList<Target>();
  37. Target target1 = new Target();
  38. //          Target target2 = new Target();                      //如果需要可设置多个接收者
  39. target1.setAppId(APPID);                            //接收者安装的应用的APPID
  40. target1.setClientId(CLIENTID);                      //接收者的ClientID
  41. //如需,可设置多个接收者
  42. //          target2.setAppId(APPID2);                           //接收者2安装应用的APPID
  43. //          target2.setClientId(CLIENTID2);                     //接收者2的ClientID
  44. targets.add(target1);
  45. //          targets.add(target2);
  46. //推送前通过该接口申请“ContentID”
  47. String contentId = push.getContentId(message);
  48. IPushResult ret = push.pushMessageToList(contentId, targets);
  49. System.out.println(ret.getResponse().toString());
  50. } catch (Exception e) {
  51. e.printStackTrace();
  52. }
  53. }
  54. }

对单个app的单个用户进行推送:

  1. import com.gexin.rp.sdk.base.IIGtPush;
  2. import com.gexin.rp.sdk.base.IPushResult;
  3. import com.gexin.rp.sdk.base.impl.SingleMessage;
  4. import com.gexin.rp.sdk.base.impl.Target;
  5. import com.gexin.rp.sdk.http.IGtPush;
  6. import com.gexin.rp.sdk.template.TransmissionTemplate;
  7. //对单个用户推送
  8. public class PushMessageToSingleTest extends PushBase{
  9. public static void main(String[] args) {
  10. // 推送主类
  11. IIGtPush push = new IGtPush(API, APPKEY, MASTERSECRET);
  12. try {
  13. //单推消息类型
  14. SingleMessage message = new SingleMessage();
  15. //通知模版:支持TransmissionTemplate、LinkTemplate、NotificationTemplate,此处以TransmissionTemplate为例
  16. //数据经SDK传给您的客户端,由您写代码决定如何处理展现给用户
  17. TransmissionTemplate template = new TransmissionTemplate();//透传方式
  18. template.setAppId(APPID);
  19. template.setAppkey(APPKEY);
  20. template.setTransmissionContent("您需要透传的内容:"+getDate());
  21. //收到消息是否立即启动应用,1为立即启动,2则广播等待客户端自启动
  22. template.setTransmissionType(1);
  23. message.setData(template);
  24. //          message.setOffline(true);                   //用户当前不在线时,是否离线存储,可选
  25. //          message.setOfflineExpireTime(72 * 3600 * 1000); //离线有效时间,单位为毫秒,可选
  26. Target target1 = new Target();
  27. target1.setAppId(APPID);
  28. target1.setClientId(CLIENTID);
  29. //单推
  30. IPushResult ret = push.pushMessageToSingle(message, target1);
  31. System.out.println(ret.getResponse().toString());
  32. } catch (Exception e) {
  33. e.printStackTrace();
  34. }
  35. }
  36. }
  1. import com.gexin.rp.sdk.base.IIGtPush;
  2. import com.gexin.rp.sdk.base.IPushResult;
  3. import com.gexin.rp.sdk.base.impl.SingleMessage;
  4. import com.gexin.rp.sdk.base.impl.Target;
  5. import com.gexin.rp.sdk.http.IGtPush;
  6. import com.gexin.rp.sdk.template.NotyPopLoadTemplate;
  7. public class PushMessageToSingleTest1 extends PushBase{
  8. public static void main(String[] args) {
  9. // 推送主类
  10. IIGtPush push = new IGtPush(API, APPKEY, MASTERSECRET);
  11. try {
  12. // 单推消息类型
  13. SingleMessage message = new SingleMessage();
  14. //通知栏弹框下载模版
  15. //在通知栏显示一条含图标、标题等的通知,用户点击后弹出框,用户可以选择直接下载应用或者取消下载应用。
  16. NotyPopLoadTemplate template = new NotyPopLoadTemplate();
  17. // 是否激活
  18. template.setActived(true);
  19. // 安卓标识
  20. template.setAndroidMark("android_mark");
  21. template.setAppId(APPID);
  22. template.setAppkey(APPKEY);
  23. // 是否自动安装
  24. template.setAutoInstall(true);
  25. // 是否响铃
  26. template.setBelled(true);
  27. // 通知是否可清除
  28. template.setCleared(true);
  29. // 苹果标识
  30. template.setIphoneMark("iphone_mark");
  31. // 下载图标
  32. template.setLoadIcon("");
  33. // 下载标题
  34. template.setLoadTitle("LoadTitle");
  35. // 下载地址
  36. template.setLoadUrl("http://dizhensubao.igexin.com/dl/com.ceic.apk");
  37. // 通知栏内容
  38. template.setNotyContent("NotyContent");
  39. // 通知栏图标
  40. template.setNotyIcon("");
  41. // 通知栏标题
  42. template.setNotyTitle("NotyTitle");
  43. // 左侧按钮名称
  44. template.setPopButton1("下载");
  45. // 右侧按钮名称
  46. template.setPopButton2("取消");
  47. // 弹框内容
  48. template.setPopContent("popContent");
  49. // 弹框图标
  50. template.setPopImage("");
  51. // 弹框标题
  52. template.setPopTitle("PopTitle");
  53. // 塞班标识
  54. template.setSymbianMark("symbian_mark");
  55. // 是否震动
  56. template.setVibrationed(true);
  57. message.setData(template);
  58. message.setOffline(true);
  59. message.setOfflineExpireTime(72 * 3600 * 1000);
  60. // 设置优先级
  61. message.setPriority(1);
  62. Target target1 = new Target();
  63. target1.setAppId(APPID);
  64. target1.setClientId(CLIENTID);
  65. // 单推
  66. IPushResult ret = push.pushMessageToSingle(message, target1);
  67. System.out.println(ret.getResponse().toString());
  68. } catch (Exception e) {
  69. // TODO Auto-generated catch block
  70. e.printStackTrace();
  71. }
  72. }
  73. }

个推,手机推送api的使用的更多相关文章

  1. Python人脸识别 + 手机推送,老板来了你就会收到短信提示

  2. 百度收录检测并主动推送API(实时 mip推送通用)

    简要描述: 百度收录检测并主动推送API(实时) 请求URL: api.bigjiji.com/baiduCheck_123456 调用方式: img标签 参数: 参数名 必选 类型 说明 site ...

  3. Jasper:推送 API

    ylbtech-Jasper:推送 API Control Center 还维护一个“推送 API”系统,一旦发生特定事件,就会向应用程序发送编程通知.例如,您可能选择在设备接近流量上限时收到通知.或 ...

  4. 2019-11-29-dotnet-使用-Qpush-快速从电脑到手机推送文字

    title author date CreateTime categories dotnet 使用 Qpush 快速从电脑到手机推送文字 lindexi 2019-11-29 08:58:57 +08 ...

  5. 2019-1-29-dotnet-使用-Qpush-快速从电脑到手机推送文字

    title author date CreateTime categories dotnet 使用 Qpush 快速从电脑到手机推送文字 lindexi 2019-01-29 16:22:56 +08 ...

  6. dotnet 使用 Qpush 快速从电脑到手机推送文字

    在手机打字总不是方便,于是就有了 Qpush 这个工具,通过这个工具可以快速从电脑到手机推送文字. 但是这个工具没有找到客户端,于是我就给他写了一个库,通过这个库可以快速进行开发 先介绍QPush 快 ...

  7. 手把手教你搞定个推iOS推送SDK集成

    以下是一位开发者在集成个推iOS推送SDK过程中的真实经历. 作者:Ezreallp 一次偶然的机会,公司的项目要用到推送,我自己本来就很懒,不愿意去弄整套APNS的流程,刚好之前跟朋友聊起过他们的产 ...

  8. 个推安卓推送SDK集成步骤详解

    以下是一位开发者在集成个推安卓推送SDK时候的亲身经历: 作者:吃饱了想睡. 概述 公司准备采用个推作为第三方推送平台,我作为客户端的头号小鸟,掐指一算已经毕业 0.1 年了,Leader 准备把这个 ...

  9. 手机版地图api

    手机版地图api一: <iframe style="height:300px;" src="http://map.baidu.com/mobile/webapp/s ...

随机推荐

  1. js获取url中参数

      /** * 获取地址栏参数值 * @param name 参数名 * @returns */ $(function () { var url = location.search; //获取url中 ...

  2. c语言-交换两个整数

    使用c来写一个函数来实现交换两个整数. 第一种 一般的方法,引用中间变量,方便快捷. void swap(int *a, int *b) { int tmp = *a; *a = *b; *b = t ...

  3. ASP.NET获取工程根目录的方法集合

    1.取得控制台应用程序的根目录方法 方法1.Environment.CurrentDirectory //取得或设置当前工作目录的完整限定路径 方法2.AppDomain.CurrentDomain. ...

  4. github 或者gitlab 设置添加SSH, 避免每次提交重复输入用户名

    克隆项目二种方式: 1. 使用https url克隆,   复制https url 然后到 git clone https-url 2.使用 SSH url 克隆却需要在克隆之前先配置和添加好 SSH ...

  5. 弹出框以及提示插件lghdialog.js的使用

    以下使用方法 swfupload的使用

  6. AMQP

    AMQP,即Advanced Message Queuing Protocol,一个提供统一消息服务的应用层标准高级消息队列协议,是应用层协议的一个开放标准,为面向消息的中间件设计.基于此协议的客户端 ...

  7. js实现发送短信验证码后的倒计时功能(无视页面刷新)

    [1].[代码] 这是页面上的发送验证码按钮 跳至 [1] [2] [3]<input id="second" type="button" value=& ...

  8. javascript设计模式简介

  9. string.Format出现异常"输入的字符串格式有误"的解决方法

    string.Format出现异常"输入的字符串格式有误"的解决方法 今天在做项目时,碰到一个很奇怪的问题,我使用string.Format居然报“输入的字符串格式有误”的错误,我 ...

  10. c++ type_info and typeid

    c++ type_info and typeid typeid 关键字typeid提供了对一个对象查询类型的功能. 该关键字和dynami_cast一起提供了c++的RTTI(rumtime type ...