public void Can_See_Error_Messages() { // Arrange try { var client = new GeckoConnect(); var obj = new NumberAndSecondaryStat() { DataItems = new DataItem[] { new DataItem() { Text = "Visitors", Value = 4223 } , new DataItem() { Text = string.Empty, Value = 238 } } }; var push = new PushPayload<NumberAndSecondaryStat>() { ApiKey = Guid.NewGuid().ToString(), Data = obj }; // Act var result = client.Push<NumberAndSecondaryStat>(push, Guid.NewGuid().ToString()); } catch (GeckoException gEx) { // Assert Assert.IsNotNull(gEx); Assert.IsNotNull(gEx.PushErrorContent); Assert.IsTrue(!string.IsNullOrEmpty(gEx.PushErrorContent.Error) || !string.IsNullOrEmpty(gEx.PushErrorContent.Message)); } }
public static PushPayload PushObject_Android_Tag_AlertWithTitle(string title, string alert, string tag) { PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.android(); pushPayload.audience = Audience.s_tag(tag); pushPayload.notification = Notification.android(alert, title); return(pushPayload); }
/// <summary> /// 推送消息给拥有特定“标签”的用户群 /// </summary> /// <returns></returns> public static bool PushObject_Android_Tag_AlertWithTitle(string alert, string title, params string[] tags) { PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.android(); pushPayload.audience = Audience.s_tag(tags); pushPayload.notification = Notification.android(alert, title); return(SendPush(pushPayload)); }
public PushPayload PushToAll(string title, string content) { PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.all(); pushPayload.audience = Audience.all(); pushPayload.notification = Notification.android(content, title); return(pushPayload); }
//推送给所有用户 public static PushPayload PushObject_all(string content) { var pushPayload = new PushPayload(); pushPayload.platform = Platform.android(); pushPayload.audience = Audience.all(); pushPayload.message = Message.content(content).AddExtras("Tag", "1"); pushPayload.notification = Notification.android(ALERT, TITLE); return(pushPayload); }
public static PushPayload PushObject_all_alias_alert(string mobile, string msg) { PushPayload pushPayload_alias = new PushPayload(); pushPayload_alias.platform = Platform.all(); pushPayload_alias.audience = Audience.s_alias(mobile); pushPayload_alias.notification = new Notification().setAlert(msg); pushPayload_alias.ResetOptionsApnsProduction(false); return(pushPayload_alias); }
public PushPayload PushObject_ios_audienceMore_messageWithExtras(Msg msg) { var pushPayload = new PushPayload(); pushPayload.platform = Platform.android_ios(); //pushPayload.audience = Audience.s_tag("tag1", "tag2"); pushPayload.audience = Audience.s_registrationId(msg.users.ToArray()); pushPayload.message = cn.jpush.api.push.mode.Message.content(msg.content).setContentType(msg.action).setTitle(msg.title).AddExtras("from", "JPush"); return(pushPayload); }
//推送给只要满足任何一种标签的用户 public static PushPayload PushObject_tags(string companyId, string[] selects, string content) { var pushPayload = new PushPayload(); pushPayload.platform = Platform.android(); pushPayload.audience = Audience.s_tag(selects).tag_and(companyId); pushPayload.message = Message.content(content).AddExtras("Tag", "2").AddExtras("CompanyTag", "1"); pushPayload.notification = Notification.android(ALERT, TITLE); return(pushPayload); }
public static bool PushObject_All_All_Alert(string alert) { PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.all(); pushPayload.audience = Audience.all(); pushPayload.notification = new Notification().setAlert(alert); return(SendPush(pushPayload)); }
public static PushPayload PushObject_Android_Tag_AlertWithTitle() { PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.android(); pushPayload.audience = Audience.s_tag("tag1"); pushPayload.notification = Notification.android(ALERT, TITLE); return(pushPayload); }
protected override void AddKeyContentAndExtras(PushPayload pushPayload) { pushPayload.message = Message.content(Content); pushPayload.message.AddExtras("key", Key); if (!string.IsNullOrEmpty(Value)) { pushPayload.message.AddExtras("value", Value); } }
public static PushPayload PushToAllAlias(string title, string content, string[] alias) { PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.android(); pushPayload.audience = Audience.s_alias(alias); pushPayload.notification = Notification.android(content, title); return(pushPayload); }
public static PushPayload PushObject_apns_production_options() { var pushPayload = new PushPayload(); pushPayload.platform = Platform.android_ios(); pushPayload.audience = Audience.s_tag("tag1", "tag2"); pushPayload.message = Message.content(MSG_CONTENT).AddExtras("from", "JPush"); pushPayload.options.apns_production = false; return(pushPayload); }
public static PushPayload PushObject_new_user(string userName, string companyName) { var pushPayload = new PushPayload(); pushPayload.platform = Platform.android(); pushPayload.audience = Audience.s_alias(userName); pushPayload.message = Message.content("欢迎来到张量公司办公系统!").AddExtras("Tag", "2").AddExtras("CompanyTag", "1"); pushPayload.notification = Notification.android("欢迎来到" + companyName, TITLE); return(pushPayload); }
/// <summary> /// 发送推送 /// </summary> /// <param name="alert">推送内容</param> /// <param name="MemberIds">推送到的用户用逗号分隔, 如果留空则为全部用户</param> /// <param name="MerId">商家ID</param> public void SendPush(string alert, string MemberIds, string eventStr, decimal MerId, string[] tag) { string[] sa = { "JPushAppKey", "JPushMasterSecret" }; Dictionary <string, string> MerConfig = BLL.StaticBLL.MerConfig(MerId, sa); JPushClient client = new JPushClient(MerConfig["JPushAppKey"], MerConfig["JPushMasterSecret"]); PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.all(); var notification = new Notification().setAlert(alert); AndroidNotification androidNotification = new AndroidNotification(); IosNotification iosNotification = new IosNotification(); Options options = new Options(); options.apns_production = true; //生产环境的 pushPayload.options = options; androidNotification.AddExtra("eventStr", eventStr); iosNotification.AddExtra("eventStr", eventStr); notification.setAndroid(androidNotification); notification.setIos(iosNotification); if (MemberIds.Trim() != "") { //如果不为空,说明指定了MemberId string[] MemberArray = MemberIds.Split(','); pushPayload.audience = Audience.s_alias(MemberArray); //推送设备对象,表示一条推送可以被推送到那些设备,确认推送设备的对象,JPush提供了多种方式,比如:别名,标签,注册id,分群,广播等。 } else if (tag != null) { if (tag.Length > 0) { pushPayload.audience = Audience.s_tag(tag); //按照标签推送 } } else { pushPayload.audience = Audience.all();//推送设备对象,表示一条推送可以被推送到那些设备,确认推送设备的对象,JPush提供了多种方式,比如:别名,标签,注册id,分群,广播等。 } pushPayload.notification = notification; pushPayload.message = Message.content("msg") .AddExtras("DoEvent", "GetNewMsgNum()"); //如果不加一条自定义消息的话, android是不会触发监听事件的.但是IOS可以 var result = client.SendPush(pushPayload); }
//接受推送信息 private void SecondContentCode(HttpContext context) { var msgContent = context.Request.Params["content"]; var userId = context.Request.Params["userId"]; var senderId = string.IsNullOrEmpty(context.Request.Params["senderId"]) ? 0 : Convert.ToInt32(context.Request.Params["senderId"]); string[] userIds = userId.Split(','); var query = userIds.Aggregate(string.Empty, (current, s) => current + ("'" + s + "',")); query = query.Substring(0, query.LastIndexOf(',')); string[] registrationId; var conductorManager = new ConductorManager(); var dtRegistration = conductorManager.GetRegistrationIds(query); if (dtRegistration != null && dtRegistration.Rows.Count > 0) { registrationId = dtRegistration.Rows.Cast <DataRow>().Select(o => o["PhoneId"].ToString()).ToArray(); //开发者标识 var appKeyAndrow = ServiceLocator.DevKey; var masterSecretAndrow = ServiceLocator.DevSecret; var alert = ServiceLocator.AppAlert;//推送提示 //var title = ServiceLocator.AppTitle;//推送标题 JPushClient clientAndrow = new JPushClient(appKeyAndrow, masterSecretAndrow); PushPayload payload = PushObject(registrationId, alert); payload.ResetOptionsApnsProduction(true); try { DateTime lssuedTime = DateTime.Now; //var lssuedPeople = 0; var result = clientAndrow.SendPush(payload); System.Threading.Thread.Sleep(10000); //查询推送结果 var apiResult = clientAndrow.getReceivedApi_v3(result.msg_id.ToString()); if (apiResult.isResultOK())//发送成功 { conductorManager.Insert(senderId, lssuedTime, msgContent, userIds); context.Response.Write("{\"msg\":\"Ok\"}"); } } catch (APIRequestException e) { context.Response.Write("{\"msg\":\"Error\"}"); } catch (APIConnectionException e) { context.Response.Write("{\"msg\":\"Error\"}"); } } else { context.Response.Write("{\"msg\":\"Error\"}"); } }
/// <summary> /// <see cref="IsPushValid(PushPayload)"/> /// </summary> public async Task <HttpResponse> IsPushValidAsync(PushPayload payload) { if (payload == null) { throw new ArgumentNullException(nameof(payload)); } var body = payload.ToString(); return(await IsPushValidAsync(body)); }
public static PushPayload PushObject_Android_Tag_AlertWithTitle(string ALERT, string TITLE) { PushPayload pushPayload = new PushPayload() { platform = Platform.android(), audience = Audience.s_tag("tag1"), notification = Notification.android(ALERT, TITLE) }; return(pushPayload); }
/// <summary> /// 极光推送主体 Android /// </summary> /// <param name="registrationId"></param> /// <param name="alert"></param> /// <param name="title"></param> /// <returns></returns> private PushPayload PushObject(string[] registrationId, string alert, string title) { var pushPayload = new PushPayload(); pushPayload.platform = Platform.all(); pushPayload.audience = Audience.s_registrationId(registrationId); pushPayload.notification = new Notification() .setAlert(alert) .setAndroid(new AndroidNotification().setTitle(title)); return(pushPayload); }
public static PushPayload PushObject_ios_audienceMore_messageWithExtras(string MSG_CONTENT) { var pushPayload = new PushPayload() { platform = Platform.android_ios(), audience = Audience.s_tag("tag1", "tag2"), message = Message.content(MSG_CONTENT).AddExtras("from", "JPush") }; return(pushPayload); }
public static PushPayload PushObject_ios_audienceMore_messageWithExtras(string[] alias, string from) { var pushPayload = new PushPayload(); pushPayload.platform = Platform.android_ios(); //pushPayload.audience = Audience.s_tag("tag1","tag2"); pushPayload.audience = Audience.s_alias(alias); pushPayload.notification = new Notification().setAlert(ALERT); pushPayload.message = Message.content(MSG_CONTENT).AddExtras("from", from); return(pushPayload); }
public static PushPayload PushObject_all_alia_alert(string ALERT) { PushPayload pushPayload_alias = new PushPayload() { platform = Platform.android(), audience = Audience.s_alias("alias1"), notification = new Notification().setAlert(ALERT) }; return(pushPayload_alias); }
public void sendByAliasMore() { PushPayload payload = new PushPayload(); payload.platform = Platform.all(); payload.audience = Audience.s_alias(ALIAS1, ALIAS2); payload.notification = new Notification().setAlert(ALERT); var result = _client.SendPush(payload); Assert.IsTrue(result.isResultOK()); }
public void testIllegal_NoPlatform() { Notification notifcation = new Notification().setAlert("alert"); PushPayload pushPayliad = new PushPayload(); pushPayliad.audience = Audience.all();; pushPayliad.notification = notifcation; pushPayliad.Check(); }
/// <summary> /// <see cref="SendPush(PushPayload)"/> /// </summary> public async Task <HttpResponse> SendPushAsync(PushPayload payload) { if (payload == null) { throw new ArgumentNullException(nameof(payload)); } string body = payload.ToString(); return(await SendPushAsync(body)); }
public static void Push_all_tag_alert_message(string alert, string message, params string[] tag) { PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.android_ios(); pushPayload.audience = Audience.s_tag(tag); pushPayload.notification = new Notification().setAlert(alert); pushPayload.message = Message.content(message); Push(pushPayload); }
public void sendByTagAndMore() { PushPayload payload = new PushPayload(); payload.platform = Platform.all(); payload.audience = Audience.s_tag_and(TAG1, TAG_ALL); payload.notification = new Notification().setAlert(ALERT); var result = _client.SendPush(payload); Assert.IsTrue(result.isResultOK()); }
public static PushPayload PushObject_Android_Tag_AlertWithTitle(User user) { PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.android(); // pushPayload.audience = Audience.all(); pushPayload.audience = Audience.s_tag("0000000008"); pushPayload.notification = Notification.android(user.MessageAlert, user.MessageTitle); return(pushPayload); }
public void sendByRegistrationID() { PushPayload payload = new PushPayload(); payload.platform = Platform.all(); payload.audience = Audience.s_registrationId(REGISTRATION_ID1); payload.notification = new Notification().setAlert(ALERT); var result = _client.SendPush(payload); Assert.IsTrue(result.isResultOK()); }
public static PushPayload PushObject_All_All_Alert(string ALERT, int plaform) { PushPayload pushPayload = new PushPayload() { platform = GetPlaform(plaform), audience = Audience.all(), notification = new Notification().setAlert(ALERT) }; return(pushPayload); }
public static PushPayload PushObject_all_alias_alert() { PushPayload pushPayload_alias = new PushPayload(); pushPayload_alias.platform = Platform.android(); string[] alias = new string[] { "alias1", "alias2", "alias3" }; Console.WriteLine(alias); pushPayload_alias.audience = Audience.s_alias(alias); pushPayload_alias.notification = new Notification().setAlert(ALERT); return(pushPayload_alias); }
public void Can_Serialize_Push_Payload() { // Arrange var obj = new NumberAndSecondaryStat() { DataItems = new DataItem[] { new DataItem() { Text = "Visitors", Value = 4223 } , new DataItem() { Text = string.Empty, Value = 238 } } }; var push = new PushPayload<NumberAndSecondaryStat>() { ApiKey = Guid.NewGuid().ToString(), Data = obj }; // Act var result = JsonConvert.SerializeObject(push, Formatting.Indented); // Assert Assert.IsNotNull(result); Assert.IsTrue(!string.IsNullOrWhiteSpace(result)); }
public void Live_Push_BarChart() { // Arrange var widgetKey = "<widget key here>"; // replace this value with your own var obj = new GeckoBarChart() { XAxis = new GeckoBarChartXAxis() { Labels = new List<string> { "2000", "2001", "2002", "2003", "2004", "2005" } }, YAxis = new GeckoBarChartYAxis() { Format = "currency", Unit = "USD" }, Series = new List<GeckoBarChartSeries>() { new GeckoBarChartSeries(){ Data = new List<int>{ 1000, 1500, 30600, 28800, 22300, 36900 } } } }; var push = new PushPayload<GeckoBarChart>() { ApiKey = this.apiKey, Data = obj }; var client = new GeckoConnect(); var json = JsonConvert.SerializeObject(push, Formatting.Indented); // Just for curiosity sake // Act Assert.AreNotEqual("<api key here>", this.apiKey); Assert.AreNotEqual("<widget key here>", widgetKey); var result = client.Push<GeckoBarChart>(push, widgetKey); // Assert Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.IsTrue(string.IsNullOrWhiteSpace(result.Message)); }
public void Live_Push_RagNumbers() { // Arrange var widgetKey = "<widget key here>"; // replace this value with your own var obj = new GeckoItems() { DataItems = new DataItem[3] { new DataItem() { Value = 16, Text = "Long past due" }, new DataItem() { Value = 64, Text = "Overdue" }, new DataItem() { Value = 32, Text = "Due" } } }; var push = new PushPayload<GeckoItems>() { ApiKey = this.apiKey, Data = obj }; var client = new GeckoConnect(); var json = JsonConvert.SerializeObject(push, Formatting.Indented); // Just for curiosity sake // Act Assert.AreNotEqual("<api key here>", this.apiKey); Assert.AreNotEqual("<widget key here>", widgetKey); var result = client.Push<GeckoItems>(push, widgetKey); // Assert Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.IsTrue(string.IsNullOrWhiteSpace(result.Message)); }
public void Live_Push_NumberAndSecondaryStat() { // Arrange var widgetKey = "<widget key here>"; // replace this value with your own var obj = new NumberAndSecondaryStat() { DataItems = new DataItem[] { new DataItem() { Text = "Visitors", Value = 4223 } , new DataItem() { Text = string.Empty, Value = 238 } } }; var push = new PushPayload<NumberAndSecondaryStat>() { ApiKey = this.apiKey, Data = obj }; var client = new GeckoConnect(); // Act Assert.AreNotEqual("<api key here>", this.apiKey); Assert.AreNotEqual("<widget key here>", widgetKey); var result = client.Push<NumberAndSecondaryStat>(push, widgetKey); // Assert Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.IsTrue(string.IsNullOrWhiteSpace(result.Message)); }
public void Live_Push_Monitoring() { // Arrange Random.Org.Random rand = new Random.Org.Random(); var widgetKey = "<widget key here>"; // replace this value with your own var obj = new GeckoMonitoring() { Status = rand.Next(1, 2) % 2 == 1 ? MonitoringStatus.Up : MonitoringStatus.Down, Downtime = DateTime.Now.AddDays(rand.Next(1, 60)).Humanize(), ResponseTime = string.Format("{0} ms", rand.Next(1, 1000)) }; var push = new PushPayload<GeckoMonitoring>() { ApiKey = this.apiKey, Data = obj }; var client = new GeckoConnect(); // Act Assert.AreNotEqual("<api key here>", this.apiKey); Assert.AreNotEqual("<widget key here>", widgetKey); var result = client.Push<GeckoMonitoring>(push, widgetKey); // Assert Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.IsTrue(string.IsNullOrWhiteSpace(result.Message)); }
public void Live_Push_Geckometer() { // Arrange var widgetKey = "<widget key here>"; // replace this value with your own var obj = new GeckoMeterChart() { Item = 0.9m, Format = "percent", Min = new DataItem() { Text = "Min", Value = 0.0m }, Max = new DataItem() { Text = "Max", Value = 1.0m } }; var push = new PushPayload<GeckoMeterChart>() { ApiKey = this.apiKey, Data = obj }; var client = new GeckoConnect(); // Act Assert.AreNotEqual("<api key here>", this.apiKey); Assert.AreNotEqual("<widget key here>", widgetKey); var result = client.Push<GeckoMeterChart>(push, widgetKey); // Assert Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.IsTrue(string.IsNullOrWhiteSpace(result.Message)); }
public void Live_Push_Bullet() { // Arrange var widgetKey = "<api widget here>"; // replace this value with your own var obj = new GeckoBulletChart() { Orientation = "horizontal", Item = new GeckoBulletItem() { Axis = new GeckoBulletAxis() { Points = new System.Collections.Generic.List<string> { "0", "50", "100", "150", "200", "250" } }, Comparative = new GeckoBulletPointString() { Point = "220" }, Label = "Revenue", Measure = new GeckoBulletMeasure() { Current = new GeckoBulletRangeItemString() { End = "235", Start = "0" } }, Range = new System.Collections.Generic.List<GeckoBulletRangeItem>() { new GeckoBulletRangeItem(){ Color = "red", End = 125, Start = 0}, new GeckoBulletRangeItem(){ Color = "amber", End = 200, Start = 126}, new GeckoBulletRangeItem(){ Color = "green", End = 250, Start = 201} }, SubLabel = "U.S. $ (1,000s)" } }; var push = new PushPayload<GeckoBulletChart>() { ApiKey = this.apiKey, Data = obj }; var client = new GeckoConnect(); var json = JsonConvert.SerializeObject(push, Formatting.Indented); // Just for curiosity sake // Act Assert.AreNotEqual("<api key here>", this.apiKey); Assert.AreNotEqual("<widget key here>", widgetKey); var result = client.Push<GeckoBulletChart>(push, widgetKey); // Assert Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.IsTrue(string.IsNullOrWhiteSpace(result.Message)); }