android個推訊息推送,asp.net呼叫介面

暖楓無敵發表於2015-04-27
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"} 離線狀態
        }
    }
}



相關文章