public override void WorkHandle() { if (!AppContent.IsMoReceive) { this.Stop(); } else { try { List <SmsEnterpriseInfo> users = config.GetEnterprise(); foreach (var item in users) { List <SmsMoInfo> smsMoInfos = new List <SmsMoInfo>(); SmsEnterpriseCfgInfo configmodel = config.GetModelWithKey("chinamobile", item.ID); string keyvalue = configmodel.CfgValue; foreach (int i in config.GetChannels(configmodel)) { smsMoInfos.AddRange(changeMos(ServicesFactory.Execute(i).GetMo(), users)); } configmodel = config.GetModelWithKey("union", item.ID); string ukeyvalue = configmodel.CfgValue; if (keyvalue != configmodel.CfgValue) { foreach (int i in config.GetChannels(configmodel)) { smsMoInfos.AddRange(changeMos(ServicesFactory.Execute(i).GetMo(), users)); } } configmodel = config.GetModelWithKey("cdma", item.ID); if (keyvalue != configmodel.CfgValue && ukeyvalue != configmodel.CfgValue) { foreach (int i in config.GetChannels(configmodel)) { smsMoInfos.AddRange(changeMos(ServicesFactory.Execute(i).GetMo(), users)); } } InsertMo(smsMoInfos); Thread.Sleep(AppContent.MoReceive); } } catch (Exception ex) { Print(ex.Message, ex); } } }
void Sendmt(object sender) { SmsBatchWaitInfo model = sender as SmsBatchWaitInfo; if (model != null) { if (model.Channels.Length == 0) { CompleteMt(model, 0, 0); return; } SmsEnterpriseCfgInfo configmodel = config.GetModelWithKey("smsprice", model.EnterPriseID); SmsEnterpriseInfo info = config.GetEnterpriseInfo(model.EnterPriseID); model.ExtendNum = info.ExtendNum; float smsprice = float.Parse(configmodel.CfgValue); int result = 3; int sendCount = 0; if ((SMSEnum)model.MsgType == SMSEnum.Group) {//群发 SMSGroupInfo gGroup = JsonConvert.DeserializeObject <SMSGroupInfo>(model.MsgPack); bool hasMoney = !(info.Capital * 1000 - smsprice * 10 * gGroup.groupInfos.Count < 0); foreach (string chanelid in model.Channels) { BaseService service = ServicesFactory.Execute(int.Parse(chanelid)); int count = service.MassCount(); for (int i = 0; i < (gGroup.groupInfos.Count / count + (gGroup.groupInfos.Count % count > 0 ? 1 : 0)); i++) { SMSSDKGroupInfo smssdkGroupInfo = new SMSSDKGroupInfo(); smssdkGroupInfo.groupInfos = new List <SDKGroupInfo>(); if (gGroup.groupInfos.Count - i * count >= count) { List <GroupInfo> groupInfos = gGroup.groupInfos.GetRange(i * count, count); foreach (GroupInfo smsDetial in groupInfos) { smssdkGroupInfo.groupInfos.Add(new SDKGroupInfo() { Phone = smsDetial.Phone, Content = smsDetial.Content }); } } else { List <GroupInfo> groupInfos = gGroup.groupInfos.GetRange(i * count, gGroup.groupInfos.Count - i * count); foreach (GroupInfo smsDetial in groupInfos) { smssdkGroupInfo.groupInfos.Add(new SDKGroupInfo() { Phone = smsDetial.Phone, Content = smsDetial.Content }); } } if (hasMoney) { result = service.SendSMS(smssdkGroupInfo.groupInfos, model.ExtendNum); if (result == 1) { sendCount += smssdkGroupInfo.groupInfos.Count; } } WriteBatchDetial(smssdkGroupInfo.groupInfos, (SendResultEnum)Enum.ToObject(typeof(SendResultEnum), result), model, chanelid); } } } else {//组发 SMSMassInfo mMass = JsonConvert.DeserializeObject <SMSMassInfo>(model.MsgPack); bool hasMoney = !(info.Capital * 1000 - smsprice * 10 * mMass.Phones.Count < 0); foreach (string chanelid in model.Channels) { BaseService service = ServicesFactory.Execute(int.Parse(chanelid)); int count = service.MassCount(); for (int i = 0; i < (mMass.Phones.Count / count + (mMass.Phones.Count % count > 0 ? 1 : 0)); i++) { List <string> readyphones = new List <string>(); if (mMass.Phones.Count - i * count >= count) { readyphones = mMass.Phones.GetRange(i * count, count); } else { readyphones = mMass.Phones.GetRange(i * count, mMass.Phones.Count - i * count); } if (hasMoney) { result = service.SendSMS(GetFromDetails(readyphones, mMass.Content), model.ExtendNum); if (result == 1) { sendCount += readyphones.Count; } } WriteBatchDetial(readyphones, mMass.Content, (SendResultEnum)Enum.ToObject(typeof(SendResultEnum), result), model, chanelid); } } } CompleteMt(model, smsprice, sendCount); lock (lockobj) SendingMtCount--; } }