| | |
| | | public class JPushManage |
| | | { |
| | | public static ToMessage mes = new ToMessage(); //定义全局返回信息对象 |
| | | private static JPushClient client = new JPushClient("自己的key", "自己的MasterSecret"); |
| | | private static JPushClient client = new JPushClient("502772cf67ff42b7b55c8a3f", "55f2881b7afde3e08e30da58"); //"自己的key", "自己的MasterSecret" |
| | | //List<string> registration_id, string title, string content |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | for (int i = 0; i < json.Count; i++) |
| | | { |
| | | List<string> registration_id = new List<string>(); |
| | | //List<string> registration_id = new List<string>(); |
| | | List<string> alias = new List<string>(); |
| | | string title = json[i].name.ToString(); //标题 |
| | | string content = "来自用户:" + username.ToString() + "内容:车间编号:【" + wkshpcode + "】,对应设备编号:【" + eqpcode + "】,时间" + DateTime.Now.ToString("yyyy/MM/ddhh:mm:ss") + "的消息通知!"; //内容 |
| | | registration_id = json[i].children.Select(x => x.rid).ToList(); //获取App集成SDK生成的Rid[ "111", "22" ] |
| | | //registration_id = json[i].children.Select(x => x.rid).Distinct().ToList(); //获取App集成SDK生成的Rid[ "111", "22" ] 去除重复 |
| | | alias = json[i].children.Select(x => x.alias).Distinct().ToList(); //获取别名[ "111", "22" ] 去除重复 |
| | | //audience : { "registration_id" : [ "111", "22" ]} 设备标识。一次推送最多 1000 个。 |
| | | var pushPayload = new PushPayload() |
| | | { |
| | | Platform = new List<string> { "android" }, //推送平台设置(必填) |
| | | Audience = "{\"registration_id\" :" + Newtonsoft.Json.JsonConvert.SerializeObject(registration_id) + "}", //推送设备指定(必填) |
| | | //Audience = "{\"registration_id\" :" + Newtonsoft.Json.JsonConvert.SerializeObject(registration_id) + "}", //推送设备指定(必填) |
| | | Audience = new { alias = alias.ToArray()}, //推送人员指定(必填) |
| | | Notification = new Notification |
| | | { |
| | | Android = new Android |
| | |
| | | }, |
| | | Options = new Options |
| | | { |
| | | TimeToLive = 864000//单位秒,最大值10天 |
| | | TimeToLive = 60//单位秒,最大值10天 |
| | | } |
| | | }; |
| | | |
| | | var response = client.SendPush(pushPayload); |
| | | mes.code = response.StatusCode.ToString(); |
| | | mes.Message = response.Content; |