/// <summary> /// 发送微信 /// </summary> /// <param name="push">系统消息推送</param> public static void SendWeixinMessage(SystemPushMongo push) { try { var title = push.Title; var content = push.Content; var wxCustomer = CusServer.GetModel(push.CustomerId); if (null == wxCustomer /*|| string.IsNullOrEmpty(wxCustomer.OpenId)*/) { throw new Exception("CustomerId=" + push.CustomerId + "的客户不存在"); } var openId = wxCustomer.OpenId; var sysConfig = SysConfigService.GetModel(Config.WeiXinKey); var accessToken = sysConfig.Value; // 获取消息模板 var datainfo = MessageTemplete(openId, title, content); GetPage("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token= " + accessToken, datainfo, "UTF-8"); } catch (Exception ex) { //LogHelper.Error("红包-发生改变微信通知出现异常", exception); throw ex; } }
/// <summary> /// 发送短信 /// </summary> /// <param name="push">系统消息推送</param> /// <returns></returns> public static string Send(SystemPushMongo push) { string result; try { Customer smsCustomer = CusServer.GetModel(push.CustomerId); string password = Security.Md5(Config.SmsAccount + Config.SmsPassword, false); var parameters = new NameValueCollection { { "sn", Config.SmsAccount }, { "pwd", password }, { "mobile", smsCustomer.Phone }, { "Content", push.Content }, { "Ext", "" }, { "stime", "" }, { "Rrid", "" }, { "msgfmt", "" } }; var client = new WebClient(); var ret = client.UploadValues(Config.SmsAddress, "POST", parameters); result = Encoding.Default.GetString(ret); } catch (Exception ex) { // ReSharper disable once PossibleIntendedRethrow throw ex; } return(result); }
/// <summary> /// 系统推送消息服务接口 /// </summary> public void Push() { // 1、获取未推送消息列表 string status = "01"; SystemPushRepository pushRepository = new SystemPushRepository(); List <SystemPushMongo> pushList = pushRepository.GetSystemPushList(status); //if (pushList.Count == 0) //{ // SystemPush pu = new SystemPush(); // pu.Title = "test"; // pu.Content = "测试内容"; // pu.CustomerId = 4194; // pu.Type = "04"; // pu.Status = "01"; // pu.CreateTime = DateTime.Now; // pushRepository.AddSystemPush(pu); // pushList = pushRepository.GetSystemPushList(status); //} for (int i = 0; i < pushList.Count; i++) { SystemPushMongo push = pushList[i]; // 写入消息队列 queue.Import(push); } }
/// <summary> /// 极光推送(ios和安卓) /// </summary> /// <param name="push">系统消息推送</param> /// <param name="platform"></param> public static void Jpush(SystemPushMongo push, Constants.DataType.Platform platform) { var customerId = push.CustomerId; var title = push.Title; var content = push.Content; var client = new JPushClient(Constants.Jpush.AppKey, Constants.Jpush.MasterSecret); var list = CusJpServer.GetListByCusId(customerId); // android -->01 iod -->02 var pushList = list.Where(en => en.Platform.Equals(EnumOperation.Description(platform))).ToArray(); if (!pushList.Any()) { return; } if (platform == Constants.DataType.Platform.Android) { var androidHashSet = new HashSet <string>(); foreach (var customerJPush in pushList) { androidHashSet.Add(customerJPush.RegId); } var payload = new PushPayload(Platform.android(), Audience.s_registrationId(androidHashSet), Notification.android(title, content)); client.SendPush(payload); } else { var iosHashSet = new HashSet <string>(); foreach (var customerJPush in pushList) { iosHashSet.Add(customerJPush.RegId); } #if DEBUG var payload = new PushPayload(Platform.ios(), Audience.s_registrationId(iosHashSet), Notification.ios(content), null, new Options()); #endif #if !DEBUG PushPayload payload = new PushPayload(Platform.ios(), Audience.s_registrationId(iosHashSet), Notification.ios(content)); #endif client.SendPush(payload); } }
public void MessagePushHandle(SystemPushMongo push) { try { // 1、向对应平台分发消息 switch (push.Type) { case "01": // 短信 SmsSend.Send(push); break; case "02": // ios AndroidAndIosPush.Jpush(push, Constants.DataType.Platform.Ios); break; case "03": // android AndroidAndIosPush.Jpush(push, Constants.DataType.Platform.Android); break; case "04": // 微信 WeiXinSend.SendWeixinMessage(push); break; default: //00 SmsSend.Send(push); AndroidAndIosPush.Jpush(push, Constants.DataType.Platform.Ios); AndroidAndIosPush.Jpush(push, Constants.DataType.Platform.Android); WeiXinSend.SendWeixinMessage(push); break; } // 修改消息状态为已推送 push.Status = "02"; _pushRepository.UpdateSystemPush(push); } catch (Exception) { // ignored } }
public void UpdateSystemPush(SystemPushMongo systemPush) { _customerPushRepository.Update(systemPush); }
public void AddSystemPush(SystemPushMongo systemPush) { _customerPushRepository.Add(systemPush); }
public void Import(SystemPushMongo model) { _userQueue.Enqueue(model); }