开发者社区> 暖枫无敌> 正文

android个推消息推送,asp.net调用接口

简介: using System; using System.Collections.Generic; using System.
+关注继续查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using com.igetui.api.openservice;
using com.igetui.api.openservice.igetui.template;
using com.igetui.api.openservice.igetui;


/// <summary>
///个推消息推送类
///  暖枫无敌 2015-04-17
/// 服务端推送接口,支持三个接口推送
/// 1.PushMessageToSingle接口:支持对单个用户进行推送
/// 2.PushMessageToList接口:支持对多个用户进行推送,建议为50个用户
/// 3.PushMessageToApp接口:对单个应用下的所有用户进行推送,可根据省份,标签,机型过滤推送        
/// </summary>
public class gtPushMessage
{
    /// <summary>
    /// 构造函数中传入移动客户端的CLIENTID号
    /// </summary>
    /// <param name="clientId">获取的clientID </param>
    public gtPushMessage(string clientId)
    {


        Environment.SetEnvironmentVariable("needDetails", "true");
        CLIENTID = clientId;
    }


    #region  应用基本参数信息


    //应用的AppId
    public String APPID = "请更换你的Android应用AppId";
    //应用的AppKey              
    public String APPKEY = "请更换你的Android应用AppKey";
    //应用的MasterSecret              
    public String MASTERSECRET = "请更换你的Android应用MasterSecret";
    //获取的clientID     
    public String CLIENTID = "请更换你安装了Android应用的手机clientid";
    //OpenService接口地址
    public static String HOST = "http://sdk.open.api.igexin.com/apiex.htm";
    //填写IOS系统的DeviceToken
    public static String DeviceToken = "";


    #endregion


    #region 1、PushMessageToSingle接口:支持对单个用户进行推送(4种模式)


    /// <summary>
    /// 透传模板
    /// </summary>
    /// <param name="transContent">透传内容</param>
    /// <param name="beginTM">客户端展示开始时间</param>
    /// <param name="endTM">客户端展示结束时间</param>
    /// <returns></returns>
    public string PushMessageToSingleByTransmissionTemplate(string transContent, string beginTM, string endTM)
    {
        // 推送主类
        IGtPush push = new IGtPush("", APPKEY, MASTERSECRET);


        TransmissionTemplate template = TransmissionTemplateDemo(transContent, beginTM, endTM);


        // 单推消息模型
        SingleMessage message = new SingleMessage();
        message.IsOffline = false; // 用户当前不在线时,是否离线存储,可选
        message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选
        message.Data = template;
        //message.PushNetWorkType = 1; //判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为非WIFI环境
        com.igetui.api.openservice.igetui.Target target = new com.igetui.api.openservice.igetui.Target();
        target.appId = APPID;
        target.clientId = CLIENTID;


        String pushResult = push.pushMessageToSingle(message, target);
        return pushResult;
    }


    /// <summary>
    /// 通知链接模板
    /// </summary>
    /// <param name="title">通知栏标题</param>
    /// <param name="text">通知栏内容</param>
    /// <param name="logo">通知栏显示本地图片</param>
    /// <param name="logoUrl">通知栏显示网络图标,如无法读取,则显示本地默认图标,可为空</param>
    /// <param name="url">打开的链接地址</param>
    /// <returns></returns>
    public string PushMessageToSingleByLinkTemplate(string title, string text, string logo, string logoUrl, string url)
    {
        // 推送主类
        IGtPush push = new IGtPush("", APPKEY, MASTERSECRET);


        LinkTemplate template = LinkTemplateDemo(title, text, logo, logoUrl, url);


        // 单推消息模型
        SingleMessage message = new SingleMessage();
        message.IsOffline = false; // 用户当前不在线时,是否离线存储,可选
        message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选
        message.Data = template;
        //message.PushNetWorkType = 1; //判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为非WIFI环境
        com.igetui.api.openservice.igetui.Target target = new com.igetui.api.openservice.igetui.Target();
        target.appId = APPID;
        target.clientId = CLIENTID;


        String pushResult = push.pushMessageToSingle(message, target);
        return pushResult;
    }


    /// <summary>
    /// 通知透传模板
    /// </summary>
    /// <param name="title">通知栏标题</param>
    /// <param name="text">通知栏内容</param>
    /// <param name="logo">通知栏显示本地图片</param>
    /// <param name="logoUrl">通知栏显示网络图标</param>
    /// <param name="transContent">透传内容</param>
    /// <param name="beginTM">客户端展示开始时间</param>
    /// <param name="endTM">客户端展示结束时间</param>
    /// <returns></returns>
    public string PushMessageToSingleByNotificationTemplate(string title, string text, string logo, string logoUrl, string transContent, string beginTM, string endTM)
    {
        // 推送主类
        IGtPush push = new IGtPush("", APPKEY, MASTERSECRET);


        NotificationTemplate template = NotificationTemplateDemo(title, text, logo, logoUrl, transContent, beginTM, endTM);


        // 单推消息模型
        SingleMessage message = new SingleMessage();
        message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选
        message.OfflineExpireTime = 1000 * 600;// 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选
        message.Data = template;
        //message.PushNetWorkType = 1; //判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为非WIFI环境
        com.igetui.api.openservice.igetui.Target target = new com.igetui.api.openservice.igetui.Target();
        target.appId = APPID;
        target.clientId = CLIENTID;


        String pushResult = push.pushMessageToSingle(message, target);
        return pushResult;
    }


    /// <summary>
    /// 通知弹框下载模板
    /// </summary>
    /// <param name="notyTitle">通知栏标题</param>
    /// <param name="notyContent">通知栏内容</param>
    /// <param name="notyIcon">通知栏显示本地图片</param>
    /// <param name="logoUrl">通知栏显示网络图标</param>
    /// <param name="popTitle">弹框显示标题</param>
    /// <param name="popContent">弹框显示内容</param>
    /// <param name="popImage">弹框显示图片</param>
    /// <param name="popButton1">弹框左边按钮显示文本</param>
    /// <param name="popButton2">弹框右边按钮显示文本</param>
    /// <param name="loadTitle">通知栏显示下载标题</param>
    /// <param name="loadIcon">通知栏显示下载图标,可为空</param>
    /// <param name="loadUrl">下载地址,不可为空</param>
    /// <returns></returns>
    public string PushMessageToSingleByNotyPopLoadTemplate(string notyTitle, string notyContent, string notyIcon, string logoUrl, string popTitle, string popContent, string popImage, string popButton1, string popButton2, string loadTitle, string loadIcon, string loadUrl)
    {
        // 推送主类
        IGtPush push = new IGtPush("", APPKEY, MASTERSECRET);


        NotyPopLoadTemplate template = NotyPopLoadTemplateDemo(notyTitle, notyContent, notyIcon, logoUrl, popTitle, popContent, popImage, popButton1, popButton2, loadTitle, loadIcon, loadUrl);


        // 单推消息模型
        SingleMessage message = new SingleMessage();
        message.IsOffline = false; // 用户当前不在线时,是否离线存储,可选
        message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选
        message.Data = template;
        //message.PushNetWorkType = 1; //判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为非WIFI环境
        com.igetui.api.openservice.igetui.Target target = new com.igetui.api.openservice.igetui.Target();
        target.appId = APPID;
        target.clientId = CLIENTID;


        String pushResult = push.pushMessageToSingle(message, target);
        return pushResult;
    }


    #endregion


    #region 2、PushMessageToList接口:支持对多个用户进行推送,建议为50个用户


    /// <summary>
    /// 透传模板
    /// </summary>
    /// <param name="transContent">透传内容</param>
    /// <param name="beginTM">客户端展示开始时间</param>
    /// <param name="endTM">客户端展示结束时间</param>
    /// <returns></returns>
    public string PushMessageToListByTransmissionTemplate(string transContent, string beginTM, string endTM)
    {
        IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);
        ListMessage message = new ListMessage();
        TransmissionTemplate template = TransmissionTemplateDemo(transContent, beginTM, endTM);


        message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选
        message.OfflineExpireTime = 1000 * 3600 * 12;// 离线有效时间,单位为毫秒,可选
        message.Data = template;
        //message.PushNetWorkType = 0;//判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为非WIFI环境


        //设置接收者
        List<com.igetui.api.openservice.igetui.Target> targetList = new List<com.igetui.api.openservice.igetui.Target>();
        com.igetui.api.openservice.igetui.Target target1 = new com.igetui.api.openservice.igetui.Target();
        target1.appId = APPID;
        target1.clientId = CLIENTID;


        // 如需要,可以设置多个接收者
        com.igetui.api.openservice.igetui.Target target2 = new com.igetui.api.openservice.igetui.Target();
        target2.appId = APPID;


        targetList.Add(target1);
        targetList.Add(target2);


        String contentId = push.getContentId(message, "任务组名");
        String pushResult = push.pushMessageToList(contentId, targetList);
        return pushResult;
    }


    /// <summary>
    /// 通知链接模板
    /// </summary>
    /// <param name="title">通知栏标题</param>
    /// <param name="text">通知栏内容</param>
    /// <param name="logo">通知栏显示本地图片</param>
    /// <param name="logoUrl">通知栏显示网络图标,如无法读取,则显示本地默认图标,可为空</param>
    /// <param name="url">打开的链接地址</param>
    /// <returns></returns>
    public string PushMessageToListByLinkTemplate(string title, string text, string logo, string logoUrl, string url)
    {
        IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);
        ListMessage message = new ListMessage();
        LinkTemplate template = LinkTemplateDemo(title, text, logo, logoUrl, url);


        message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选
        message.OfflineExpireTime = 1000 * 3600 * 12;// 离线有效时间,单位为毫秒,可选
        message.Data = template;
        //message.PushNetWorkType = 0;//判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为非WIFI环境


        //设置接收者
        List<com.igetui.api.openservice.igetui.Target> targetList = new List<com.igetui.api.openservice.igetui.Target>();
        com.igetui.api.openservice.igetui.Target target1 = new com.igetui.api.openservice.igetui.Target();
        target1.appId = APPID;
        target1.clientId = CLIENTID;


        // 如需要,可以设置多个接收者
        com.igetui.api.openservice.igetui.Target target2 = new com.igetui.api.openservice.igetui.Target();
        target2.appId = APPID;


        targetList.Add(target1);
        targetList.Add(target2);


        String contentId = push.getContentId(message, "任务组名");
        String pushResult = push.pushMessageToList(contentId, targetList);
        return pushResult;


    }


    /// <summary>
    /// 通知透传模板
    /// </summary>
    /// <param name="title">通知栏标题</param>
    /// <param name="text">通知栏内容</param>
    /// <param name="logo">通知栏显示本地图片</param>
    /// <param name="logoUrl">通知栏显示网络图标</param>
    /// <param name="transContent">透传内容</param>
    /// <param name="beginTM">客户端展示开始时间</param>
    /// <param name="endTM">客户端展示结束时间</param>
    /// <returns></returns>
    public string PushMessageToListByNotificationTemplate(string title, string text, string logo, string logoUrl, string transContent, string beginTM, string endTM)
    {
        IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);
        ListMessage message = new ListMessage();
        NotificationTemplate template = NotificationTemplateDemo(title, text, logo, logoUrl, transContent, beginTM, endTM);


        message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选
        message.OfflineExpireTime = 1000 * 3600 * 12;// 离线有效时间,单位为毫秒,可选
        message.Data = template;
        //message.PushNetWorkType = 0;//判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为非WIFI环境


        //设置接收者
        List<com.igetui.api.openservice.igetui.Target> targetList = new List<com.igetui.api.openservice.igetui.Target>();
        com.igetui.api.openservice.igetui.Target target1 = new com.igetui.api.openservice.igetui.Target();
        target1.appId = APPID;
        target1.clientId = CLIENTID;


        // 如需要,可以设置多个接收者
        com.igetui.api.openservice.igetui.Target target2 = new com.igetui.api.openservice.igetui.Target();
        target2.appId = APPID;


        targetList.Add(target1);
        targetList.Add(target2);


        String contentId = push.getContentId(message, "任务组名");
        String pushResult = push.pushMessageToList(contentId, targetList);
        return pushResult;
    }




    /// <summary>
    /// 通知弹框下载模板
    /// </summary>
    /// <param name="notyTitle">通知栏标题</param>
    /// <param name="notyContent">通知栏内容</param>
    /// <param name="notyIcon">通知栏显示本地图片</param>
    /// <param name="logoUrl">通知栏显示网络图标</param>
    /// <param name="popTitle">弹框显示标题</param>
    /// <param name="popContent">弹框显示内容</param>
    /// <param name="popImage">弹框显示图片</param>
    /// <param name="popButton1">弹框左边按钮显示文本</param>
    /// <param name="popButton2">弹框右边按钮显示文本</param>
    /// <param name="loadTitle">通知栏显示下载标题</param>
    /// <param name="loadIcon">通知栏显示下载图标,可为空</param>
    /// <param name="loadUrl">下载地址,不可为空</param>
    /// <returns></returns>
    public string PushMessageToListByNotyPopLoadTemplate(string notyTitle, string notyContent, string notyIcon, string logoUrl, string popTitle, string popContent, string popImage, string popButton1, string popButton2, string loadTitle, string loadIcon, string loadUrl)
    {
        IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);
        ListMessage message = new ListMessage();
        NotyPopLoadTemplate template = NotyPopLoadTemplateDemo(notyTitle, notyContent, notyIcon, logoUrl, popTitle, popContent, popImage, popButton1, popButton2, loadTitle, loadIcon, loadUrl);


        message.IsOffline = true; // 用户当前不在线时,是否离线存储,可选
        message.OfflineExpireTime = 1000 * 3600 * 12;// 离线有效时间,单位为毫秒,可选
        message.Data = template;
        //message.PushNetWorkType = 0;//判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为非WIFI环境


        //设置接收者
        List<com.igetui.api.openservice.igetui.Target> targetList = new List<com.igetui.api.openservice.igetui.Target>();
        com.igetui.api.openservice.igetui.Target target1 = new com.igetui.api.openservice.igetui.Target();
        target1.appId = APPID;
        target1.clientId = CLIENTID;


        // 如需要,可以设置多个接收者
        com.igetui.api.openservice.igetui.Target target2 = new com.igetui.api.openservice.igetui.Target();
        target2.appId = APPID;


        targetList.Add(target1);
        targetList.Add(target2);


        String contentId = push.getContentId(message, "任务组名");
        String pushResult = push.pushMessageToList(contentId, targetList);
        return pushResult;
    }


    #endregion


    #region 3、PushMessageToApp接口:对单个应用下的所有用户进行推送,可根据省份,标签,机型过滤推送


    /// <summary>
    /// 透传模板
    /// </summary>
    /// <param name="transContent">透传内容</param>
    /// <param name="beginTM">客户端展示开始时间</param>
    /// <param name="endTM">客户端展示结束时间</param>
    /// <returns></returns>
    public string PushMessageToAppByTransmissionTemplate(string transContent, string beginTM, string endTM)
    {
        IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);
        AppMessage message = new AppMessage();
        TransmissionTemplate template = TransmissionTemplateDemo(transContent, beginTM, endTM);


        message.IsOffline = false;// 用户当前不在线时,是否离线存储,可选
        message.OfflineExpireTime = 1000 * 3600 * 12;// 离线有效时间,单位为毫秒,可选
        message.Data = template;
        //message.PushNetWorkType = 0; //判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为非WIFI环境
        message.Speed = 1;


        List<String> appIdList = new List<string>();
        appIdList.Add(APPID);


        List<String> phoneTypeList = new List<string>();//通知接收者的手机操作系统类型
        //phoneTypeList.Add("ANDROID");
        //phoneTypeList.Add("IOS");


        List<String> provinceList = new List<string>();//通知接收者所在省份
        //provinceList.Add("浙江");
        //provinceList.Add("上海");
        //provinceList.Add("北京");


        List<String> tagList = new List<string>();
        //tagList.Add("标签5");


        message.AppIdList = appIdList;
        message.PhoneTypeList = phoneTypeList;
        message.ProvinceList = provinceList;
        message.TagList = tagList;


        String pushResult = push.pushMessageToApp(message, "toAPP任务别名");
        return pushResult;
    }




    /// <summary>
    /// 通知链接模板
    /// </summary>
    /// <param name="title">通知栏标题</param>
    /// <param name="text">通知栏内容</param>
    /// <param name="logo">通知栏显示本地图片</param>
    /// <param name="logoUrl">通知栏显示网络图标,如无法读取,则显示本地默认图标,可为空</param>
    /// <param name="url">打开的链接地址</param>
    /// <returns></returns>
    public string PushMessageToAppByLinkTemplate(string title, string text, string logo, string logoUrl, string url)
    {
        IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);
        AppMessage message = new AppMessage();
        LinkTemplate template = LinkTemplateDemo(title, text, logo, logoUrl, url);


        message.IsOffline = false; // 用户当前不在线时,是否离线存储,可选
        message.OfflineExpireTime = 1000 * 3600 * 12; // 离线有效时间,单位为毫秒,可选
        message.Data = template;
        //message.PushNetWorkType = 0;//判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为非WIFI环境
        message.Speed = 1;


        List<String> appIdList = new List<string>();
        appIdList.Add(APPID);


        List<String> phoneTypeList = new List<string>();//通知接收者的手机操作系统类型
        //phoneTypeList.Add("ANDROID");
        //phoneTypeList.Add("IOS");


        List<String> provinceList = new List<string>();//通知接收者所在省份
        //provinceList.Add("浙江");
        //provinceList.Add("上海");
        //provinceList.Add("北京");


        List<String> tagList = new List<string>();
        //tagList.Add("标签5");


        message.AppIdList = appIdList;
        message.PhoneTypeList = phoneTypeList;
        message.ProvinceList = provinceList;
        message.TagList = tagList;


        String pushResult = push.pushMessageToApp(message, "toAPP任务别名");
        return pushResult;
    }


    /// <summary>
    /// 通知透传模板
    /// </summary>
    /// <param name="title">通知栏标题</param>
    /// <param name="text">通知栏内容</param>
    /// <param name="logo">通知栏显示本地图片</param>
    /// <param name="logoUrl">通知栏显示网络图标</param>
    /// <param name="transContent">透传内容</param>
    /// <param name="beginTM">客户端展示开始时间</param>
    /// <param name="endTM">客户端展示结束时间</param>
    /// <returns></returns>
    public string PushMessageToAppByNotificationTemplate(string title, string text, string logo, string logoUrl, string transContent, string beginTM, string endTM)
    {
        IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);
        AppMessage message = new AppMessage();
        NotificationTemplate template = NotificationTemplateDemo(title, text, logo, logoUrl, transContent, beginTM, endTM);


        message.IsOffline = false;// 用户当前不在线时,是否离线存储,可选
        message.OfflineExpireTime = 1000 * 3600 * 12;// 离线有效时间,单位为毫秒,可选
        message.Data = template;
        //message.PushNetWorkType = 0;//判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为非WIFI环境
        message.Speed = 1;


        List<String> appIdList = new List<string>();
        appIdList.Add(APPID);


        List<String> phoneTypeList = new List<string>();//通知接收者的手机操作系统类型
        //phoneTypeList.Add("ANDROID");
        //phoneTypeList.Add("IOS");


        List<String> provinceList = new List<string>();//通知接收者所在省份
        //provinceList.Add("浙江");
        //provinceList.Add("上海");
        //provinceList.Add("北京");


        List<String> tagList = new List<string>();
        //tagList.Add("标签5");


        message.AppIdList = appIdList;
        message.PhoneTypeList = phoneTypeList;
        message.ProvinceList = provinceList;
        message.TagList = tagList;


        String pushResult = push.pushMessageToApp(message, "toAPP任务别名");
        return pushResult;
    }


     /// <summary>
    /// 通知弹框下载模板
    /// </summary>
    /// <param name="notyTitle">通知栏标题</param>
    /// <param name="notyContent">通知栏内容</param>
    /// <param name="notyIcon">通知栏显示本地图片</param>
    /// <param name="logoUrl">通知栏显示网络图标</param>
    /// <param name="popTitle">弹框显示标题</param>
    /// <param name="popContent">弹框显示内容</param>
    /// <param name="popImage">弹框显示图片</param>
    /// <param name="popButton1">弹框左边按钮显示文本</param>
    /// <param name="popButton2">弹框右边按钮显示文本</param>
    /// <param name="loadTitle">通知栏显示下载标题</param>
    /// <param name="loadIcon">通知栏显示下载图标,可为空</param>
    /// <param name="loadUrl">下载地址,不可为空</param>
    /// <returns></returns>
    public string PushMessageToAppByNotyPopLoadTemplate(string notyTitle, string notyContent, string notyIcon, string logoUrl, string popTitle, string popContent, string popImage, string popButton1, string popButton2, string loadTitle, string loadIcon, string loadUrl)
    {
        IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);
        AppMessage message = new AppMessage();
        NotyPopLoadTemplate template = NotyPopLoadTemplateDemo(notyTitle, notyContent, notyIcon, logoUrl, popTitle, popContent, popImage, popButton1, popButton2, loadTitle, loadIcon, loadUrl);


        message.IsOffline = false;// 用户当前不在线时,是否离线存储,可选
        message.OfflineExpireTime = 1000 * 3600 * 12;// 离线有效时间,单位为毫秒,可选
        message.Data = template;
        //message.PushNetWorkType = 0; //判断是否客户端是否wifi环境下推送,1为在WIFI环境下,0为非WIFI环境
        message.Speed = 1;


        List<String> appIdList = new List<string>();
        appIdList.Add(APPID);


        List<String> phoneTypeList = new List<string>(); //通知接收者的手机操作系统类型
        //phoneTypeList.Add("ANDROID");
        //phoneTypeList.Add("IOS");


        List<String> provinceList = new List<string>(); //通知接收者所在省份
        //provinceList.Add("浙江");
        //provinceList.Add("上海");
        //provinceList.Add("北京");


        List<String> tagList = new List<string>();
        //tagList.Add("标签5");


        message.AppIdList = appIdList;
        message.PhoneTypeList = phoneTypeList;
        message.ProvinceList = provinceList;
        message.TagList = tagList;


        String pushResult = push.pushMessageToApp(message, "toAPP任务别名");
        return pushResult;
    }


    #endregion


    #region 2、四种消息模板


    /*
     * 
     * 所有推送接口均支持四个消息模板,依次为透传模板,通知透传模板,通知链接模板,通知弹框下载模板
     * 注:IOS离线推送需通过APN进行转发,需填写pushInfo字段,目前仅不支持通知弹框下载功能
     *
     */


    /// <summary>
    /// 通知弹框下载模板动作内容,常用于下载apk更新软件等
    /// </summary>
    /// <param name="notyTitle">通知栏标题</param>
    /// <param name="notyContent">通知栏内容</param>
    /// <param name="notyIcon">通知栏显示本地图片</param>
    /// <param name="logoUrl">通知栏显示网络图标</param>
    /// <param name="popTitle">弹框显示标题</param>
    /// <param name="popContent">弹框显示内容</param>
    /// <param name="popImage">弹框显示图片</param>
    /// <param name="popButton1">弹框左边按钮显示文本</param>
    /// <param name="popButton2">弹框右边按钮显示文本</param>
    /// <param name="loadTitle">通知栏显示下载标题</param>
    /// <param name="loadIcon">通知栏显示下载图标,可为空</param>
    /// <param name="loadUrl">下载地址,不可为空</param>
    /// <returns></returns>
    public NotyPopLoadTemplate NotyPopLoadTemplateDemo(string notyTitle, string notyContent, string notyIcon, string logoUrl, string popTitle, string popContent, string popImage, string popButton1, string popButton2, string loadTitle, string loadIcon, string loadUrl)
    {
        NotyPopLoadTemplate template = new NotyPopLoadTemplate();
        template.AppId = APPID;
        template.AppKey = APPKEY;
        template.NotyTitle = notyTitle; //通知栏标题
        template.NotyContent = notyContent; //通知栏内容
        template.NotyIcon = notyIcon; //通知栏显示本地图片,如icon.png
        template.LogoURL = logoUrl; //通知栏显示网络图标,如http://www-igexin.qiniudn.com/wp-content/uploads/2013/08/logo_getui1.png


        template.PopTitle = popTitle; //弹框显示标题
        template.PopContent = popContent; //弹框显示内容
        template.PopImage = popImage;  //弹框显示图片
        template.PopButton1 = popButton1; //弹框左边按钮显示文本
        template.PopButton2 = popButton2; //弹框右边按钮显示文本


        template.LoadTitle = loadTitle;//通知栏显示下载标题
        template.LoadIcon = loadIcon;//通知栏显示下载图标,可为空,如file://push.png
        template.LoadUrl = loadUrl;//下载地址,不可为空,http://www.appchina.com/market/d/425201/cop.baidu_0/com.gexin.im.apk


        template.IsActived = true;//应用安装完成后,是否自动启动
        template.IsAutoInstall = true; //下载应用完成后,是否弹出安装界面,true:弹出安装界面,false:手动点击弹出安装界面


        template.IsBelled = true;//接收到消息是否响铃,true:响铃 false:不响铃
        template.IsVibrationed = true;//接收到消息是否震动,true:震动 false:不震动
        template.IsCleared = true;//接收到消息是否可清除,true:可清除 false:不可清除
        return template;
    }


    /// <summary>
    /// 通知链接动作内容
    /// </summary>
    /// <param name="title">通知栏标题</param>
    /// <param name="text">通知栏内容</param>
    /// <param name="logo">通知栏显示本地图片</param>
    /// <param name="logoUrl">通知栏显示网络图标,如无法读取,则显示本地默认图标,可为空</param>
    /// <param name="url">打开的链接地址</param>
    /// <returns></returns>
    public LinkTemplate LinkTemplateDemo(string title, string text, string logo, string logoUrl, string url)
    {
        LinkTemplate template = new LinkTemplate();
        template.AppId = APPID;
        template.AppKey = APPKEY;
        template.Title = title;//通知栏标题
        template.Text = text;//通知栏内容
        template.Logo = logo;//通知栏显示本地图片
        template.LogoURL = logoUrl;  //通知栏显示网络图标,如无法读取,则显示本地默认图标,可为空
        template.Url = url; //打开的链接地址,如http://www.baidu.com


        //iOS推送需要的pushInfo字段
        //template.setPushInfo(actionLocKey, badge, message, sound, payload, locKey, locArgs, launchImage);


        template.IsRing = true;//接收到消息是否响铃,true:响铃 false:不响铃
        template.IsVibrate = true;//接收到消息是否震动,true:震动 false:不震动
        template.IsClearable = true;//接收到消息是否可清除,true:可清除 false:不可清除


        return template;
    }




    /// <summary>
    /// 通知透传模板动作内容
    /// </summary>
    /// <param name="title">通知栏标题</param>
    /// <param name="text">通知栏内容</param>
    /// <param name="logo">通知栏显示本地图片</param>
    /// <param name="logoUrl">通知栏显示网络图标</param>
    /// <param name="transContent">透传内容</param>
    /// <param name="beginTM">客户端展示开始时间</param>
    /// <param name="endTM">客户端展示结束时间</param>
    /// <returns></returns>
    public NotificationTemplate NotificationTemplateDemo(string title, string text, string logo, string logoUrl, string transContent, string beginTM, string endTM)
    {
        NotificationTemplate template = new NotificationTemplate();
        template.AppId = APPID;
        template.AppKey = APPKEY;
        template.Title = title;//通知栏标题
        template.Text = text;//通知栏内容
        template.Logo = logo;//通知栏显示本地图片
        template.LogoURL = logoUrl;//通知栏显示网络图标,如https://www.baidu.com/img/bd_logo1.png


        template.TransmissionType = "1";//应用启动类型,1:强制应用启动  2:等待应用启动
        template.TransmissionContent = transContent;//透传内容
        //iOS推送需要的pushInfo字段
        //template.setPushInfo(actionLocKey, badge, message, sound, payload, locKey, locArgs, launchImage);


        //设置客户端展示时间
        String begin = beginTM;
        String end = endTM;
        template.setDuration(begin, end);


        template.IsRing = true; //接收到消息是否响铃,true:响铃 false:不响铃
        template.IsVibrate = true; //接收到消息是否震动,true:震动 false:不震动
        template.IsClearable = true; //接收到消息是否可清除,true:可清除 false:不可清除


        return template;
    }


    /// <summary>
    /// 透传模板动作内容
    /// </summary>
    /// <param name="transContent">透传内容</param>
    /// <param name="beginTM">客户端展示开始时间</param>
    /// <param name="endTM">客户端展示结束时间</param>
    /// <returns></returns>
    public TransmissionTemplate TransmissionTemplateDemo(string transContent, string beginTM, string endTM)
    {
        TransmissionTemplate template = new TransmissionTemplate();
        template.AppId = APPID;
        template.AppKey = APPKEY;
        template.TransmissionType = "1"; //应用启动类型,1:强制应用启动 2:等待应用启动
        template.TransmissionContent = transContent;  //透传内容
        //iOS推送需要的pushInfo字段
        //template.setPushInfo(actionLocKey, badge, message, sound, payload, locKey, locArgs, launchImage);
        template.setPushInfo("1", 4, "2", "", "", "", "", "");
        //设置客户端展示时间
        String begin = beginTM;
        String end = endTM;
        template.setDuration(begin, end);


        return template;
    }


    #endregion


    #region 3、获取用户当前状态


    /// <summary>
    /// 获取用户当前状态
    /// </summary>
    /// <returns></returns>
    public string getUserStatus()
    {
        IGtPush push = new IGtPush(HOST, APPKEY, MASTERSECRET);
        String ret = push.getClientIdStatus(APPID, CLIENTID);
        return ret;
    }


    #endregion


}


Web系统中点击下发任务,调用接口,示例如下:

public partial class PushMessage_Test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string clientId = "f67adb8d5b04a225fa7192b8741eb47b";
            gtPushMessage message = new gtPushMessage(clientId);
            //方法调用过程中一定要注意,截止时间一定要大于当前操作时间,建议在当前操作时间的基础上加5分钟时间
            string msg = message.PushMessageToSingleByNotificationTemplate("XXX - 单用户", "您有新的任务,点击查看!"+System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "", "", "", "2015-04-20 15:10", "2015-04-20 16:30");
            string msg2 = message.PushMessageToAppByNotificationTemplate("XXX  - APP应用", "您有新的任务,点击查看!", "", "", "", "2015-04-20 10:10", "2015-04-20 14:30");
            string msg3 = message.PushMessageToListByNotificationTemplate("XXX  - 多用户", "您有新的任务,点击查看!", "", "", "", "2015-04-20 10:10", "2015-04-20 14:30");
             Response.Write(msg+"</br>");
            Response.Write(msg2 + "</br>");
            Response.Write(msg3 + "</br>");
            //解析输出结果
            //{"taskId":"OSS-0420_ZiFBb3Sx7A7Pz7YWMwJdD9","result":"ok","status":"successed_online"} 在线状态
            //{"taskId":"OSS-0420_2qtgpolflJAuYGSiGTfQ04","result":"ok","status":"successed_offline"} 离线状态
        }
    }
}



版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
产品百科 | RTC Android SDK 播放音效文件的接口方法
阿里云 RTC SDK 为您提供伴奏文件和音效文件的相关接口方法,您可以通过本文了解其具体的实现方法。
97 0
Asp.Net Web API 2第三课——.NET客户端调用Web API
原文:Asp.Net Web API 2第三课——.NET客户端调用Web API Asp.Net Web API 导航     Asp.Net Web API第一课——入门http://www.cnblogs.com/aehyok/p/3432158.html       Asp.Net Web API第二课——CRUD操作http://www.cnblogs.com/aehyok/p/3434578.html 前言 本教程演示从一个控制台应用程序,使用HttpClient调用Web API。
1145 0
Asp.Net Web API 2第四课——HttpClient消息处理器
原文:Asp.Net Web API 2第四课——HttpClient消息处理器 Asp.Net Web API 导航     Asp.Net Web API第一课:入门http://www.cnblogs.
822 0
php封装json通信接口详解及实例
php创建JSON数据详解: ``` <?php //创建一个字符数组 $arr=array( 'id'=>1, 'name'=>'david' ); echo json_encode($arr);//这个是创建JSON的关键函数 ?> ...
1698 0
+关注
625
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
JS零基础入门教程(上册)
立即下载
性能优化方法论
立即下载
手把手学习日志服务SLS,云启实验室实战指南
立即下载