android個推訊息推送,asp.net呼叫介面
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"} 離線狀態
}
}
}
相關文章
- Android之訊息推送原理Android
- APP訊息推送,如何做到精推?APP
- Android 訊息推送:第三方訊息推送平臺 詳細解析Android
- 訊息推送介面設計(內含原始碼)原始碼
- 呼叫推送介面返回成功,手機端未收到通知欄訊息,該如何自檢?
- Android呼叫訊息欄通知(Notification)Android
- 個推百億級訊息推送的優先順序解決方案
- 【重磅分享】個推《APP訊息推送白皮書》.pdf(附下載連結)APP
- 史上最全解析Android訊息推送解決方案Android
- Android 推送訊息的實現,使用百度雲推送Android
- 免費呼叫微信推送介面
- iOS 點選推送訊息跳轉指定介面 —總結篇iOS
- Android訊息推送技術原理分析和實踐Android
- workerman 實現訊息推送
- IOS 訊息推送處理iOS
- 個推11週年慶,最長90天訊息推送VIP權益免費領!
- IOS 推送訊息 php做推送服務端iOSPHP服務端
- uni-app訊息推送方案APP
- 訊息推送背後的思考
- mqtt訊息推送(vue前端篇)MQQTVue前端
- 玩轉釘釘訊息推送!
- iOS開發訊息推送原理iOS
- Flutter websocket 實現訊息推送FlutterWeb
- 微信開發推送訊息案例
- 使用redis進行訊息推送Redis
- 訊息推送系統架構架構
- 實時訊息推送方案-SSE
- 小程式訊息推送訂閱
- 設計一個百萬級的訊息推送系統
- 【雙十一福利】個推訊息推送VIP服務免費用,更有潮流禮品抽獎!
- APP訊息推送 極光推送 示例程式碼APP
- 個推支援小程式訊息推送,助力開發者實現使用者高觸達、高轉化
- uni-app小程式訊息推送APP
- App訊息推送思維導圖APP
- Android 基於Netty的訊息推送方案之Hello World(一)AndroidNetty
- 用 Laravel 自帶訊息模組搭建小程式實時推送訊息Laravel
- 個推打造訊息推送專項運營提升方案,資料驅動APP觸達效果升級APP
- 訊息推送一個好功能,90%的開發者都不知道。