/// <summary> /// 发送消息 /// </summary> /// <param name="msg">消息</param> /// <param name="appKey">appkey</param> /// <param name="masterSecret">主密钥</param> private static void sendAndroidMsgToUsers(PushMsgModel msg, List <PushStaff> userDics, string appKey = "9b725db3484eceb1abab684a", string masterSecret = "7a6081367b0d0dda83a8b969") { JPushClient client = new JPushClient(appKey, masterSecret); PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.android(); foreach (PushStaff item in userDics) { pushPayload.audience = Audience.s_alias(item.UserName); pushPayload.options.time_to_live = 30; if (item.IsPushVoice) { msg.IsPushVoice = true; pushPayload.message = Message.content(JsonConvert.SerializeObject(msg)); } else { msg.IsPushVoice = false; pushPayload.message = Message.content(JsonConvert.SerializeObject(msg)); } try { var result = client.SendPush(pushPayload); } catch { } } }
/// <summary> /// 发送消息 /// </summary> /// <param name="msg">消息</param> /// <param name="appKey">appkey</param> /// <param name="masterSecret">主密钥</param> private static void sendAndroidMsgToUsers(PushMsgModel msg, List <PushStaff> userDics, string appKey = "a91410f29fd95fe5800fff9a", string masterSecret = "2bd0c5a1418c05f97ae9048a") { JPushClient client = new JPushClient(appKey, masterSecret); PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.android(); foreach (PushStaff item in userDics) { pushPayload.audience = Audience.s_alias(item.UserName); pushPayload.options.time_to_live = 30; if (item.IsPushVoice) { msg.IsPushVoice = true; pushPayload.message = Message.content(SerializationHelper.JsonSerialize(msg)); } else { msg.IsPushVoice = false; pushPayload.message = Message.content(SerializationHelper.JsonSerialize(msg)); } try { var result = client.SendPush(pushPayload); } catch (Exception ex) { } } }
public JsonResult JpushTest(String Title, String Alert, String Msg_content, String Recevier)//, String ALERT, String MSG_CONTENT) { JPushClient client = new JPushClient(app_key, master_secret); PushPayload payload = PushObject_Android_Tag_AlertWithTitle(Title, Alert, Msg_content, Recevier);//, MSG_CONTENT);//选择一种方式 try { var result = client.SendPush(payload);//推送 //由于统计数据并非非是即时的,所以等待一小段时间再执行下面的获取结果方法 System.Threading.Thread.Sleep(10000); /*如需查询上次推送结果执行下面的代码*/ var apiResultv3 = client.getReceivedApi_v3(result.msg_id.ToString()); /*如需查询某个messageid的推送结果执行下面的代码*/ // var querResultWithV3 = client.getReceivedApi_v3("1739302794"); return(Json(result, JsonRequestBehavior.AllowGet)); } catch (APIRequestException e)//处理请求异常 { var message = "Error response from JPush server. Should review and fix it." + "HTTP Status:" + e.Status + "Error Code: " + e.ErrorCode + "Error Message: " + e.ErrorCode; return(Json(message, JsonRequestBehavior.AllowGet)); } catch (APIConnectionException e)//处理连接异常 { return(Json(e.Message, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 别名消息 /// </summary> /// <param name="title">消息标题</param> /// <param name="content">消息内容</param> /// <param name="json">json数据</param> /// <param name="aliases">别名集合</param> /// <returns></returns> public static string JPushMessageAliases(string title, string content, Dictionary <string, object> json, ArrayList aliases) { JPushClient jpushClient = new JPushClient(AppKey, Master_Secret); PushPayload payload = new PushPayload(); payload.Platform = "all"; Dictionary <string, ArrayList> aliasSet = new Dictionary <string, ArrayList>(); aliasSet.Add("alias", aliases); payload.Audience = aliasSet; Message msg = new Message(); msg.ContentType = "text"; msg.Title = title; msg.Content = content; msg.Extras = json; payload.Message = msg; Jiguang.JPush.Model.HttpResponse response = jpushClient.SendPush(payload); return(response.Content); }
static void Main(string[] args) { //Console.WriteLine("*****开始发送******"); JPushClient client = new JPushClient(app_key, master_secret); PushPayload payload = PushObject_All_All_Alert(args); try { var result = client.SendPush(payload); ////由于统计数据并非非是即时的,所以等待一小段时间再执行下面的获取结果方法 //System.Threading.Thread.Sleep(10000); ///*如需查询上次推送结果执行下面的代码*/ //var apiResult = client.getReceivedApi(result.msg_id.ToString()); //var apiResultv3 = client.getReceivedApi_v3(result.msg_id.ToString()); ///*如需查询某个messageid的推送结果执行下面的代码*/ //var queryResultWithV2 = client.getReceivedApi("1739302794"); //var querResultWithV3 = client.getReceivedApi_v3("1739302794"); } catch (APIRequestException e) { //Console.WriteLine("Error response from JPush server. Should review and fix it. "); //Console.WriteLine("HTTP Status: " + e.Status); //Console.WriteLine("Error Code: " + e.ErrorCode); //Console.WriteLine("Error Message: " + e.ErrorCode); } catch (APIConnectionException e) { //Console.WriteLine(e.Message); } //Console.WriteLine("*****结束发送******"); //Console.Read(); //HF.Cloud.JPushForm.Program.c }
/// <summary> /// 安卓推送线程 /// </summary> internal void AndroidThread() { string Key = string.Empty; string MasterSecret = string.Empty; if (UserType == "0")//推送给经销商 { Key = ConfigurationManager.AppSettings["DisKey"].ToString(); MasterSecret = ConfigurationManager.AppSettings["DisMasterSecret"].ToString(); } else//推送给企业 { Key = ConfigurationManager.AppSettings["CompKey"].ToString(); MasterSecret = ConfigurationManager.AppSettings["CompMasterSecret"].ToString(); } JPushClient push = new JPushClient(Key, MasterSecret); PushPayload payload = new MsgSend().GetSendUserModel(UserType, OrderID, Type, money_all); if (payload != null) { MessageResult msgResult = push.SendPush(payload); //if (msgResult!=null) //threadAndroid.Abort(); } }
public void PushOther() { JPushClient client = new JPushClient(app_key, master_secret); PushPayload payload = PushObject_All_All_Alert(); payload.platform = Platform.all(); payload.audience = Audience.all(); payload.options.apns_production = true; try { string title = Context.Request["t"]; //标题 string model = Context.Request["m"]; //模块名 string content = Context.Request["c"]; //内容 var notification = new Notification(); notification.IosNotification = new IosNotification().setAlert(title).setBadge(1).setSound("default").AddExtra("c", content).AddExtra("m", model); notification.AndroidNotification = new AndroidNotification().setAlert(title).AddExtra("c", content).AddExtra("m", model); payload.notification = notification; var result = client.SendPush(payload); Context.Response.Write("[{\"STATE\":\"SUCCESS\",\"MESSAGE\":\"" + result + "\"}]"); } catch (Exception ex) { Context.Response.Write("[{\"STATE\":\"ERROR\",\"MESSAGE\":\"" + ex.Message + "\"}]"); } }
public static int PushMessageToGroup(string pushTag, string pushTitle, string pushMessager) { JPushClient jpush_client = new JPushClient(app_key, master_secret); var registrationId = "12145125123151"; var devicePayload = new DevicePayload() { Alias = "alias1", Mobile = "12300000000", Tags = new Dictionary <string, object>() { { "add", new List <string>() { "tag1", "tag2" } }, { "remove", new List <string>() { "tag3", "tag4" } } } }; var response = jpush_client.Device.UpdateDeviceInfo(registrationId, devicePayload); Console.WriteLine(response.Content); return(0); }
/// <summary> /// /// </summary> /// <param name="Title"></param> /// <param name="Content">发送内容</param> /// <param name="Platform">1:ios,0:Android,3群发</param>调用钱,先在WebConfig中的参数 /// <returns></returns> public static string SendPush(string Title, string Content, int Platform, string s_registrationId) { TITLE = Title; ALERT = Content; string msg = string.Empty; if (Platform == 1) { JPushClient client = new JPushClient(app_key_ios, master_secret_ios); //ios PushPayload payload = PushObject_IOSMsg(s_registrationId, Content); //ios推送 msg = JGPushing(client, payload); } else if (Platform == 0) { JPushClient client = new JPushClient(app_key_android, master_secret_android);//andriod PushPayload payload = PushObject_AndroidMsg(s_registrationId, Content); msg = JGPushing(client, payload); } else if (Platform == 3) { JPushClient client = new JPushClient(app_key_ios, master_secret_ios);//ios群发 PushPayload payload = PushObject_All_All_Aler_ios(); msg = JGPushing(client, payload); client = new JPushClient(app_key_android, master_secret_android);//andriod群发 payload = PushObject_All_All_Alert_Android(); msg = JGPushing(client, payload); } return(msg); // // PushPayload payload = PushObject_All_All_Alert();//群发 // PushPayload payload = PushObject_IOSMsg("191e35f7e040cd09c20", Content);//ios推送 //PushPayload payload = PushObject_AndroidMsg("1a0018970aa3a3b76b7", Content);//Android推送 }
public void testDeleteResult() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); TagListResult result = pushClient.getTagList(); Assert.IsTrue(result.isResultOK()); }
//private RequestParamModel<MessageModel> GetRpm(FormCollection context) //{ // var json = context["json"]; // var rpm = new RequestParamModel<MessageModel>(context) { CurrentContext = context, Action = Request["action"] }; // if (!string.IsNullOrEmpty(json)) // { // rpm = JSONhelper.ConvertToObject<RequestParamModel<MessageModel>>(json); // rpm.CurrentContext = context; // } // return rpm; //} //public ActionResult Send() //{ // ViewBag.ToolBar = BuildToolbar(); // return View(); //} //[HttpPost] //[ValidateInput(false)] //public string Send(FormCollection context) //{ // try // { // var ids = Request["ids"]; // var title = Request["title"]; // var content = Request["content"]; // if (string.IsNullOrEmpty(ids)) // { // try // { // List<AppUserModel> list = AppUserDal.Instance.GetWhereStr(" and MASTER_ID IS NOT NULL").ToList(); // foreach (AppUserModel userModel in list) // { // MessageModel messageModel = new MessageModel(); // messageModel.RECEIVE_ID = 0;// PublicMethod.GetDecimal(id); // // model.CONTENT = content; // messageModel.HTML_CONTENT = content; // messageModel.IS_RREAD = 0; // messageModel.SEND_TIME = DateTime.Now; // messageModel.TITLE = title; // messageModel.USER_ID = userModel.FID; // MessageDal.Instance.Insert(messageModel); // } // JPushClient client = new JPushClient(SysVisitor.Instance.PushAppKey, SysVisitor.Instance.PushMasterSecret); // PushPayload pushPayload = new PushPayload(); // pushPayload.platform = Platform.all(); // pushPayload.audience = Audience.all(); // pushPayload.notification = new Notification().setAlert(title); // client.SendPush(pushPayload); // } // catch (Exception ex) // { // LogHelper.WriteLog(string.Format("Error: appKey={0},masterSecret={1},phone={2},title={3},msg={4}", SysVisitor.Instance.PushAppKey, SysVisitor.Instance.PushMasterSecret, "全体", title, ex.Message)); // } // } // else // { // string[] array = ids.Split(','); // foreach (string id in array) // { // MessageModel model = new MessageModel(); // model.RECEIVE_ID = 0;// PublicMethod.GetDecimal(id); // // model.CONTENT = content; // model.HTML_CONTENT = content; // model.IS_RREAD = 0; // model.SEND_TIME = DateTime.Now; // model.TITLE = title; // model.USER_ID = id; // if (MessageDal.Instance.Insert(model) != "") // { // OnPushMessage(id, title); // } // } // } // return JSONhelper.ToJson("发送成功!"); // } // catch (Exception ex) // { // return JSONhelper.ToJson(ex.Message); // } //} private void OnPushMessage(string id, string title) { //DriverModel model = DriverDal.Instance.GetByID(id); AppUserModel model = AppUserDal.Instance.Get(id); if (model != null) { try { JPushClient client = new JPushClient(SysVisitor.Instance.PushAppKey, SysVisitor.Instance.PushMasterSecret); PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.all(); pushPayload.audience = Audience.s_alias(model.PHONE); pushPayload.notification = new Notification().setAlert(title); client.SendPush(pushPayload); } catch (Exception ex) { LogHelper.WriteLog(string.Format("Error: appKey={0},masterSecret={1},phone={2},title={3},msg={4}", SysVisitor.Instance.PushAppKey, SysVisitor.Instance.PushMasterSecret, model.PHONE, title, ex.Message)); } } }
public void testGetAliasDeviceList_2() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); AliasDeviceListResult result = pushClient.getAliasDeviceList("alias2", null); Assert.IsTrue(result.registration_ids.Count == 0); }
public void testGetAliasDeviceList() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); AliasDeviceListResult result = pushClient.getAliasDeviceList("alias1", "android"); Assert.IsTrue(result.isResultOK()); }
public void testDeleteAlias_2() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); DefaultResult result = pushClient.deleteAlias("alias2", null); Assert.IsTrue(result.isResultOK()); }
public void testGetAliasDeviceList_1() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); AliasDeviceListResult result = pushClient.getAliasDeviceList("alias1", null); Assert.IsTrue(result.registration_ids.Contains(REGISTRATION_ID1)); }
public void testUpdateDeviceTagAlias_clear() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); DefaultResult result = pushClient.updateDeviceTagAlias(REGISTRATION_ID1, true, true); Assert.IsTrue(result.isResultOK()); }
/// <summary> /// 极光推送服务 /// </summary> /// <param name="userid">用户ID</param> /// <param name="Msg">用户ID</param> public static void PushiOS_Android(string userid, string Msg) { try { JPushClient pushClient = new JPushClient(Config.app_key, Config.masterSecret); PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.android_ios(); pushPayload.audience = Audience.s_alias(userid); var options = new Options(); options.apns_production = false; //true表示IOS 生产环境 false 表示开发环境 pushPayload.options = options; //如果默认不设置则表示开发环境 var notification = new Notification(); // "您有新的订单,请处理" notification.IosNotification = new IosNotification().setAlert(Msg) .setBadge(1) .setSound("happy") .AddExtra("from", "JPush"); notification.AndroidNotification = new AndroidNotification().setAlert(Msg).AddExtra("from", "JPush"); pushPayload.notification = notification; var result = pushClient.SendPush(pushPayload); } catch (Exception ex) { System.Diagnostics.Debug.Print(ex.Message); } }
public void testGetTagList_1() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); TagListResult result = pushClient.getTagList(); Assert.IsTrue(result.tags.Count > 0); }
public static void PushMessage(string message, int notificationType, int updateDocumentTypeId, string tag, string updateCity, string updateDocumentType, int updateCityId) { try { if (notificationType == 1) { var client = new JPushClient(AndroidAppKey, AndroidMasterSecret); PushPayload payload = PushObjectUpdate(message, notificationType); client.SendPush(payload); } else { var clientIos = new JPushClient(IosAppKey, IosMasterSecret); var payload = PushAndroid_IosDocument(message, notificationType, tag, updateDocumentTypeId, updateCity, updateDocumentType, updateCityId); //PushPayload payload = PushIosObjectDocument(message, notificationType, tag, updateDocumentTypeId, updateCity, updateDocumentType, updateCityId); clientIos.SendPush(payload); //var clientAndroid = new JPushClient(AndroidAppKey, AndroidMasterSecret); //payload = PushAndroidObjectDocument(message, notificationType, tag, updateDocumentTypeId, updateCity, updateDocumentType, updateCityId); //clientAndroid.SendPush(payload); } } catch (Exception ex) { log4net.LogManager.GetLogger("PushMessageNew").Error(message, ex); throw; } }
public void testAddRemoveDevicesFromTagResult() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); TagListResult result = pushClient.getTagList(); Assert.IsTrue(result.tags.Contains("tag3")); }
/// <summary> /// 设置短信推送信息 /// </summary> /// <param name="message">推送内容</param> /// <param name="registrationIds">管理员的手机注册码</param> public static void PushMessage(string message, List <string> registrationIds) { JPushClient client = new JPushClient(AppKey, MasterSecret); PushPayload pushPayload = new PushPayload() { Platform = new List <string> { "android", "ios" }, Audience = new Audience() { RegistrationId = registrationIds }, Notification = new Notification { Alert = message, }, Options = new Options { //IsApnsProduction = true // 设置 iOS 推送生产环境。不设置默认为开发环境。 } }; var response = client.SendPush(pushPayload); NLog.LogManager.GetCurrentClassLogger().Info(response.Content); }
public string pushToDriver(string number, string title, string content, string type) { JPushClient client = new JPushClient(app_key_driver, master_secret_driver); PushPayload tags = JPushApi.PushObject_android_and_ios(number, title, content, type); //PushPayload tags = JPushApi.PushSendSmsMessage(); try { var result = client.SendPush(tags); //由于统计数据并非非是即时的,所以等待一小段时间再执行下面的获取结果方法 System.Threading.Thread.Sleep(10000); //如需查询上次推送结果执行下面的代码 var apiResult = client.getReceivedApi(result.msg_id.ToString()); var apiResultv3 = client.getReceivedApi_v3(result.msg_id.ToString()); //如需查询某个messageid的推送结果执行下面的代码 var queryResultWithV2 = client.getReceivedApi("1739302794"); var querResultWithV3 = client.getReceivedApi_v3("1739302794"); return("推送成功"); } catch (APIRequestException e) { System.Diagnostics.Debug.Write("Error response from JPush server. Should review and fix it. "); System.Diagnostics.Debug.Write("HTTP Status: " + e.Status); System.Diagnostics.Debug.Write("Error Code: " + e.ErrorCode); System.Diagnostics.Debug.Write("Error Message: " + e.ErrorMessage); return("推送失败"); } catch (APIConnectionException e) { return(e.message); } }
private bool SendPush(PushPayload pushOption) { try { JPushClient client = new JPushClient(appKey, masterSecret); var result = client.SendPush(pushOption); if (result.ResponseResult.responseCode != System.Net.HttpStatusCode.OK) { throw new ArgumentException(result.ResponseResult.exceptionString); } return(result.ResponseResult.responseCode == System.Net.HttpStatusCode.OK); } catch (APIRequestException ex) { new CustomException(string.Format("JPushHelper--SendPush--APIRequestException--Message:{0},ErrorMessage:{1},ErrorCode:{2},", ex.Message, ex.ErrorMessage, ex.ErrorCode)); } catch (APIConnectionException ex) { new CustomException(string.Format("JPushHelper--SendPush--APIConnectionException--Message:{0}", ex.Message)); } catch (Exception ex) { new CustomException("JPushHelper--SendPush--Exception--", ex); } return(false); }
public SpecialCharacterTest() { JPushClient jpushClient = new JPushClient(APP_KEY, MASTER_SECRET); var result = jpushClient.updateDeviceTagAlias(REGISTRATION_ID1, "special_c", null, null); Assert.IsTrue(result.isResultOK()); }
public static string JGPushing(JPushClient client, PushPayload payload) { var results = string.Empty; try { var result = client.SendPush(payload); //var result = client.SendPush("4422569071705780711"); //由于统计数据并非非是即时的,所以等待一小段时间再执行下面的获取结果方法 System.Threading.Thread.Sleep(1000); /*如需查询上次推送结果执行下面的代码*/ // var receive = client.getReceivedApi(result.msg_id.ToString()); //var apiResultv3 = client.getReceivedApi_v3(result.msg_id.ToString()); /*如需查询某个messageid的推送结果执行下面的代码*/ //var queryResultWithV2 = client.getReceivedApi("1739302794"); //var querResultWithV3 = client.getReceivedApi_v3("1739302794"); results = result.msg_id.ToString(); } catch (APIRequestException e) { results += "Error response from JPush server. Should review and fix it. "; results += "HTTP Status: " + e.Status; results += "Error Code: " + e.ErrorCode; results += "Error Message: " + e.ErrorCode; } return(results); }
/// <summary> /// 指定别名广播 /// </summary> /// <param name="title">标题</param> /// <param name="content">内容</param> /// <param name="json">推送内容</param> /// <param name="aliases">别名集合</param> /// <returns></returns> public static string JPushAliases(string title, string content, Dictionary <string, object> json, ArrayList aliases) { JPushClient jpushClient = new JPushClient(AppKey, Master_Secret); PushPayload payload = new PushPayload(); payload.Platform = "all"; Dictionary <string, ArrayList> audis = new Dictionary <string, ArrayList>(); audis.Add("alias", aliases); payload.Audience = audis; Notification noti = new Notification(); noti.Alert = title; noti.Android = new Android() { Title = title, Alert = content, Extras = json }; noti.IOS = new IOS() { Alert = content, Category = title, Extras = json }; payload.Notification = noti; Jiguang.JPush.Model.HttpResponse response = jpushClient.SendPush(payload); return(response.Content); }
//public static String TITLE = "Test from C# v3 sdk"; //public static String ALERT = "Test from C# v3 sdk - alert"; //public static String MSG_CONTENT = "Test from C# v3 sdk - msgContent"; //public static String REGISTRATION_ID = "0900e8d85ef"; //public static String TAG = "tag_api"; //public static String app_key = "17a5eb963edcbd8ef0d954e4"; //public static String master_secret = "4b6d3a888eba4ab44c12af36"; /// <summary> /// /// </summary> /// <param name="title">标题</param> /// <param name="alert">标题</param> /// <param name="msgcontent">内容</param> /// <param name="tag">tag 多条“,”隔开</param> /// <param name="alias">alias 多条“,”隔开</param> /// <param name="type">推送类型</param> public static int Main(string title, string alert, string alias, string activity = "", string app_key = "", string master_secret = "") { string REGISTRATION_ID = "0900e8d85ef"; //string app_key = "17a5eb963edcbd8ef0d954e4"; //string master_secret = "4b6d3a888eba4ab44c12af36"; //if(activity == MTConfig.ActivityName.教师拼单未开始) //{ // List<XUserModel> list = UserModel.Fetch("where User_Type = @0", MTConfig.UserType.Teacher); // alias = string.Join(",", list.Select(s => s.Id)); // if(string.IsNullOrEmpty(alias)) // { // alias = "0"; // } //} //if (activity == MTConfig.ActivityName.教师需求单未开始) //{ // List<XUserModel> list = UserModel.Fetch("where User_Type = @0", MTConfig.UserType.Teacher); // alias = string.Join(",", list.Select(s => s.Id)); // if (string.IsNullOrEmpty(alias)) // { // alias = "0"; // } //} JPushClient client = new JPushClient(app_key, master_secret); PushPayload payload = new PushPayload(); if (string.IsNullOrEmpty(alias)) { payload = PushObject_All_All_Alert(alert, title, "", activity); } else { payload = PushObject_All_All_Alert(alert, title, alias, activity); } try { var result = client.SendPush(payload); //由于统计数据并非非是即时的,所以等待一小段时间再执行下面的获取结果方法 System.Threading.Thread.Sleep(10000); /*如需查询上次推送结果执行下面的代码*/ var apiResult = client.getReceivedApi(result.msg_id.ToString()); var apiResultv3 = client.getReceivedApi_v3(result.msg_id.ToString()); /*如需查询某个messageid的推送结果执行下面的代码*/ var queryResultWithV2 = client.getReceivedApi("1739302794"); var querResultWithV3 = client.getReceivedApi_v3("1739302794"); return(1); } catch (APIRequestException e) { Console.WriteLine("Error response from JPush server. Should review and fix it. "); Console.WriteLine("HTTP Status: " + e.Status); Console.WriteLine("Error Code: " + e.ErrorCode); Console.WriteLine("Error Message: " + e.ErrorCode); return(e.ErrorCode); } }
public void PushNews(string t, string i) { JPushClient client = new JPushClient(AppKey, MasterSecret);//app_key, master_secret); PushPayload payload = PushObject_All_All_Alert(); payload.platform = Platform.all(); payload.audience = Audience.all(); payload.options.apns_production = true; try { string title = t; // Context.Request["t"]; string ID = i; // Context.Request["id"]; var notification = new Notification(); notification.IosNotification = new IosNotification().setAlert(title).setBadge(1).setSound("default").AddExtra("ID", ID); notification.AndroidNotification = new AndroidNotification().setAlert(title).AddExtra("ID", ID); payload.notification = notification; var result = client.SendPush(payload); Context.Response.Write("[{\"STATE\":\"SUCCESS\",\"MESSAGE\":\"" + result + "\"}]"); } catch (Exception ex) { Context.Response.Write("[{\"STATE\":\"ERROR\",\"MESSAGE\":\"" + ex.Message + "\"}]"); } }
/// <summary> /// 极光推送方法 /// </summary> /// <param name="model"></param> public static void PushMessage(JPushModel model) { try { string appKey = ""; string masterSecret = ""; if (model.TagId == 0) //C端 { appKey = "dce902893245e99461b9a5c8"; // Your App Key from JPush masterSecret = "fdc95d37d67c9472ad4e0e96"; // Your Master Secret from JPush } else if (model.TagId == 1) //B端 { appKey = "d794d51f2ffaf5de42001c4b"; // Your App Key from JPush masterSecret = "03f956afaaeb086481aa3b7c"; // Your Master Secret from JPush } JPushClient client = new JPushClient(appKey, masterSecret); Audience audience = null; if (model.PushType == 0) { //0:标签,因为一个应用只能有一个标签,现有支付已经使用,其它应用请使用别名 audience = Audience.s_alias(model.RegistrationId); model.ContentKey = "Content"; } if (model.PushType == 1) { //1:别名 audience = Audience.s_tag(model.RegistrationId); } PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.android_ios(); pushPayload.audience = audience; Notification notification = new Notification().setAlert(model.Alert);//不需要写弹出内容 notification.AndroidNotification = new AndroidNotification().setTitle(model.Title); notification.IosNotification = new IosNotification().setAlert(model.Alert).setBadge(1).setSound(string.Concat(model.ContentKey, ":", model.Content)); if (!string.IsNullOrEmpty(model.Content)) { //notification.IosNotification = new IosNotification().setAlert(model.Alert).setBadge(1).setSound("YourSound").AddExtra(model.ContentKey, model.Content); notification.AndroidNotification = new AndroidNotification().AddExtra(model.ContentKey, model.Content); } pushPayload.notification = notification.Check(); var response = client.SendPush(pushPayload); if (!response.isResultOK()) { LogHelper.LogWriter("推送失败", response.msg_id); } else { LogHelper.LogWriter("推送成功", response.msg_id); } } catch (Exception ex) { string parm = string.Concat("推送异常,参数:tagId", model.TagId, ",RegistrationId:", model.RegistrationId); LogHelper.LogWriter(ex, parm); } }
public bool Push(string type, string title, string platform, string message) { JPushClient client = new JPushClient(app_key, master_secret); PushPayload pushPayload = new PushPayload(); platform = platform.ToLower(); if ("1" == platform) { pushPayload.platform = Platform.all(); } else if ("2" == platform) { pushPayload.platform = Platform.ios(); } else if ("3" == platform) { pushPayload.platform = Platform.android(); } pushPayload.audience = Audience.all(); var notification = new Notification().setAlert(title); notification.IosNotification = new cn.jpush.api.push.notification.IosNotification(); notification.IosNotification.AddExtra("type", type); notification.IosNotification.AddExtra("message", message); notification.AndroidNotification = new cn.jpush.api.push.notification.AndroidNotification(); notification.AndroidNotification.AddExtra("type", type); notification.AndroidNotification.AddExtra("message", message); pushPayload.notification = notification; try { var result = client.SendPush(pushPayload); return(true); ////由于统计数据并非非是即时的,所以等待一小段时间再执行下面的获取结果方法 //System.Threading.Thread.Sleep(10000); ////如需查询上次推送结果执行下面的代码 //var apiResult = client.getReceivedApi(result.msg_id.ToString()); //var apiResultv3 = client.getReceivedApi_v3(result.msg_id.ToString()); ////如需查询某个messageid的推送结果执行下面的代码 //var queryResultWithV2 = client.getReceivedApi("1739302794"); //var querResultWithV3 = client.getReceivedApi_v3("1739302794"); } catch (Exception ex) { var logger = EngineContext.Current.Resolve <ILogger>(); logger.InsertLog(Domain.Logging.LogLevel.Error, ex.Message, ex.StackTrace, Domain.Logging.EventSource.Console); //Console.WriteLine("Error response from JPush server. Should review and fix it. "); //Console.WriteLine("HTTP Status: " + e.Status); //Console.WriteLine("Error Code: " + e.ErrorCode); //Console.WriteLine("Error Message: " + e.ErrorMessage); } return(false); }
public void testAddRemoveDevicesFromTag() { HashSet<String> toAddUsers = new HashSet<String>(); toAddUsers.Add(REGISTRATION_ID1); HashSet<String> toRemoveUsers = new HashSet<String>(); toRemoveUsers.Add(REGISTRATION_ID2); JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); DefaultResult result = pushClient.addRemoveDevicesFromTag("tag3", toAddUsers, toRemoveUsers); Assert.IsTrue(result.isResultOK()); }
public void testGetDeviceTagAlias_cleard() { testUpdateDeviceTagAlias_clear(); JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); TagAliasResult result = pushClient.getDeviceTagAlias(REGISTRATION_ID1); Assert.IsTrue(result.isResultOK()); Assert.AreEqual(null, result.alias); Assert.AreEqual( 0, result.tags.Count); }
public void test_empty_string() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); try { pushClient.SendPush(""); } catch (ArgumentException e) { Debug.WriteLine(e.Message); } }
public void testUpdateDeviceTagAlias_add_tags() { HashSet<String> tagsToAdd = new HashSet<String>(); tagsToAdd.Add("tag1"); tagsToAdd.Add("tag2"); tagsToAdd.Add("tag3"); tagsToAdd.Add("tag4"); JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); DefaultResult result = pushClient.updateDeviceTagAlias(REGISTRATION_ID1, "alias1", tagsToAdd, null); Assert.IsTrue(result.isResultOK()); }
public void test_validate() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); try { var result = pushClient.SendPush(PushPayload.AlertAll("alert")); Assert.IsTrue(result.isResultOK()); } catch (Exception e) { Debug.WriteLine(e.Message); } }
public void authenticationFail() { String masterSecret = "2b38ce69b1de2a7fa95706e2"; JPushClient client = new JPushClient(masterSecret, APP_KEY); PushPayload payload = PushPayload.AlertAll(ALERT); try { var result = _client.SendPush(payload); } catch (APIRequestException e) { Assert.AreEqual(AUTHENTICATION_FAIL, e.ErrorCode); } }
public void appKeyNotExist() { String appKey = "dd1066407b044738b6479274"; JPushClient client = new JPushClient(appKey, MASTER_SECRET); PushPayload payload = PushPayload.AlertAll(ALERT); try { var result = _client.SendPush(payload); } catch (APIRequestException e) { Assert.AreEqual(APPKEY_NOT_EXIST, e.ErrorCode); } }
public void testGetDeviceTagAlias_1() { testUpdateDeviceTagAlias_add_remove_tags(); JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); TagAliasResult result = pushClient.getDeviceTagAlias(REGISTRATION_ID1); Assert.IsTrue(result.isResultOK()); Assert.AreEqual("alias1", result.alias); Assert.IsTrue(result.tags.Contains("tag1")); Assert.IsTrue(result.tags.Contains("tag2")); Assert.IsTrue(!result.tags.Contains("tag3")); Assert.IsTrue(!result.tags.Contains("tag4")); }
public AudienceTest() { HashSet<String> tags1 = new HashSet<String>(); tags1.Add(TAG1); tags1.Add(TAG_ALL); HashSet<String> tags2 = new HashSet<String>(); tags2.Add(TAG2); tags2.Add(TAG_ALL); JPushClient jpushClient = new JPushClient(APP_KEY,MASTER_SECRET); var result = jpushClient.updateDeviceTagAlias(REGISTRATION_ID1, ALIAS1, MOBILE, tags1, null); Assert.IsTrue(result.isResultOK()); result = jpushClient.updateDeviceTagAlias(REGISTRATION_ID2, ALIAS2, MOBILE, tags2, null); Assert.IsTrue(result.isResultOK()); }
/*用户统计vip专用接口*/ public static void testGetUsers() { JPushClient jpushClient = new JPushClient(app_key, master_secret); try { var result = jpushClient.getReportUsers(TimeUnit.DAY, "2014-06-10", 3); Console.WriteLine("Got result - " + result.ToString()); } catch (APIRequestException e) { Console.WriteLine("Error response from JPush server. Should review and fix it. "); Console.WriteLine("HTTP Status: " + e.Status); Console.WriteLine("Error Code: " + e.ErrorCode); Console.WriteLine("Error Message: " + e.ErrorCode); } catch (APIConnectionException e) { Console.WriteLine(e.Message); } }
public static void Main(string[] args) { Console.WriteLine("*****开始发送******"); JPushClient client = new JPushClient(app_key, master_secret); PushPayload payload = PushObject_All_All_Alert(); try { var result = client.SendPush(payload); //由于统计数据并非非是即时的,所以等待一小段时间再执行下面的获取结果方法 System.Threading.Thread.Sleep(10000); //如需查询上次推送结果执行下面的代码 var apiResult = client.getReceivedApi(result.msg_id.ToString()); var apiResultv3 = client.getReceivedApi_v3(result.msg_id.ToString()); //如需查询某个messageid的推送结果执行下面的代码 var queryResultWithV2 = client.getReceivedApi("1739302794"); var querResultWithV3 = client.getReceivedApi_v3("1739302794"); } catch (APIRequestException e) { Console.WriteLine("Error response from JPush server. Should review and fix it. "); Console.WriteLine("HTTP Status: " + e.Status); Console.WriteLine("Error Code: " + e.ErrorCode); Console.WriteLine("Error Message: " + e.ErrorMessage); } catch (APIConnectionException e) { Console.WriteLine(e.Message); } //send smsmessage PushPayload pushsms = PushSendSmsMessage(); try { var result = client.SendPush(pushsms); //由于统计数据并非非是即时的,所以等待一小段时间再执行下面的获取结果方法 System.Threading.Thread.Sleep(10000); //如需查询上次推送结果执行下面的代码 var apiResult = client.getReceivedApi(result.msg_id.ToString()); var apiResultv3 = client.getReceivedApi_v3(result.msg_id.ToString()); //如需查询某个messageid的推送结果执行下面的代码 var queryResultWithV2 = client.getReceivedApi("1739302794"); var querResultWithV3 = client.getReceivedApi_v3("1739302794"); } catch (APIRequestException e) { Console.WriteLine("Error response from JPush server. Should review and fix it. "); Console.WriteLine("HTTP Status: " + e.Status); Console.WriteLine("Error Code: " + e.ErrorCode); Console.WriteLine("Error Message: " + e.ErrorMessage); } catch (APIConnectionException e) { Console.WriteLine(e.Message); } PushPayload payload_alias = PushObject_all_alias_alert(); try { var result = client.SendPush(payload_alias); //由于统计数据并非非是即时的,所以等待一小段时间再执行下面的获取结果方法 System.Threading.Thread.Sleep(10000); //如需查询上次推送结果执行下面的代码 var apiResult = client.getReceivedApi(result.msg_id.ToString()); var apiResultv3 = client.getReceivedApi_v3(result.msg_id.ToString()); //如需查询某个messageid的推送结果执行下面的代码 var queryResultWithV2 = client.getReceivedApi("1739302794"); var querResultWithV3 = client.getReceivedApi_v3("1739302794"); } catch (APIRequestException e) { Console.WriteLine("Error response from JPush server. Should review and fix it. "); Console.WriteLine("HTTP Status: " + e.Status); Console.WriteLine("Error Code: " + e.ErrorCode); Console.WriteLine("Error Message: " + e.ErrorMessage); } catch (APIConnectionException e) { Console.WriteLine(e.Message); } Console.WriteLine("*****结束发送******"); }
public ReportFunctionTests() { jpushClient = new JPushClient(APP_KEY, MASTER_SECRET); }
public void testGetAliasDeviceList_2() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); AliasDeviceListResult result = pushClient.getAliasDeviceList("alias2", null); Assert.IsTrue(result.registration_ids.Count == 0); }
public void testGetTagList_1() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); TagListResult result = pushClient.getTagList(); Assert.IsTrue(result.tags.Count>0); }
public void testIsDeviceInTag() { testAddRemoveDevicesFromTag(); JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); BooleanResult result = pushClient.isDeviceInTag("tag3", REGISTRATION_ID1); Assert.IsTrue( result.result); result = pushClient.isDeviceInTag("tag3", REGISTRATION_ID2); Assert.IsTrue( !result.result); }
public void test_invalid_json() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); pushClient.SendPush("{aaa:'a}"); }
public void testUpdateDeviceTagAlias_clear() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); DefaultResult result = pushClient.updateDeviceTagAlias(REGISTRATION_ID1, true, true); Assert.IsTrue(result.isResultOK()); }
public void testAddRemoveDevicesFromTagResult() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); TagListResult result = pushClient.getTagList(); Assert.IsTrue(result.tags.Contains("tag3")); }
public void testDeleteAlias() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); DefaultResult result = pushClient.deleteAlias("alias1", "android"); Assert.IsTrue(result.isResultOK()); }
public void testDeleteResult() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); TagListResult result = pushClient.getTagList(); Assert.IsTrue(result.isResultOK()); }
public SpecialCharacterTest() { JPushClient jpushClient = new JPushClient(APP_KEY,MASTER_SECRET); var result = jpushClient.updateDeviceTagAlias(REGISTRATION_ID1, "special_c", MOBILE, null, null); Assert.IsTrue (result.isResultOK()); }
public void testDeletetag2() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); DefaultResult result = pushClient.deleteTag("tag2", null); Assert.IsTrue(result.isResultOK()); }
public void testGetAliasDeviceList_1() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); AliasDeviceListResult result = pushClient.getAliasDeviceList("alias1", null); Assert.IsTrue(result.registration_ids.Contains(REGISTRATION_ID1)); }
public void testGetAliasDeviceList() { JPushClient pushClient = new JPushClient(APP_KEY, MASTER_SECRET); AliasDeviceListResult result = pushClient.getAliasDeviceList("alias1", "android"); Assert.IsTrue(result.isResultOK()); }