//发送短信 private void _LoopForSendSms() { SendSms_CircleThread = ThreadAdapter.DoCircleTask(() => { string strUrl, strToken, strNodeId; foreach (var item in smsPointDic) { strUrl = item.Value.Url; strToken = item.Value.Token; strNodeId = item.Value.NodeId; HttpAdapter.getSyncTo(strUrl + "/Pub/SmsSendService/QueuedUnSendSms", null, new { ApplicationId = "CS001", Token = strToken, NodeId = strNodeId }.ToStringObjectDictionary(), (smsret, smsres) => { if ((bool)smsret.Success) { StringObjectDictionary sod; IDictionary <string, object> dic; string strItem = ""; DateTime scheduleTime = DateTime.Now; foreach (var row in smsret.rows) { sod = new StringObjectDictionary(); dynamic list = new ExpandoObject(); DynamicAdapter.Parse(list, System.Xml.Linq.XElement.Parse(row.ToString())); dic = list.StringObjectDictionary; strItem = e0571.web.core.Utils.TypeConverter.ChangeString(dic["SendCatalog"]); if (strItem == "0") { sod = sod.Union2(txtDictionary.ToStringObjectDictionary()); } strItem = e0571.web.core.Utils.TypeConverter.ChangeString(dic["Mobiles"]); if (string.IsNullOrEmpty(strItem)) { continue; } //跳过 sod.Add("UserNumber", strItem); //是否有预约时间 是-转化yyyyMMddHHmmss;否-空 strItem = e0571.web.core.Utils.TypeConverter.ChangeString(dic["ScheduleTime"], ""); sod.Add("ScheduleTime", strItem); if (!string.IsNullOrEmpty(strItem)) { if (DateTime.TryParse(strItem, out scheduleTime)) { sod["ScheduleTime"] = scheduleTime.ToString("yyyyMMddHHmmss"); } } strItem = e0571.web.core.Utils.TypeConverter.ChangeString(dic["SendContent"]); sod.Add("MessageContent", HttpUtility.UrlEncode(strItem, Encoding.GetEncoding("GBK"))); //批次号 strItem = e0571.web.core.Utils.TypeConverter.ChangeString(dic["BatchNum"]); sod.Add("SerialNumber", strItem); //发送HttpAdapter.postSyncAsForm Common.postSyncAsForm(smsEndPoint + "/Send.do", sod, null, (ret, res) => { Dictionary <string, string> retdict = Common.StrToDictionary(ret, '&'); if (retdict["result"] == "0") { this.Invoke(new Action <string, string>((p1, p2) => { lb_Send.Items.Add("[" + p1 + "] 成功发送 [" + p2 + "]"); }), new object[] { sod["UserNumber"], HttpUtility.UrlDecode((string)sod["MessageContent"], Encoding.GetEncoding("GBK")) }); //需要回执的短信 StringObjectDictionary sod2; if (!sendSmsDic.TryGetValue(strItem, out sod2)) { sod2 = new { SmsNodeId = strNodeId, SmsToken = strToken, SmsUrl = strUrl }.ToStringObjectDictionary(); sendSmsDic.TryAdd(strItem, sod2); } //更新成功发送数据 UpdateSmsSendStatus(new { Status = 1, Mobiles = ((string)sod["UserNumber"]), BatchNum = sod["SerialNumber"] }.ToStringObjectDictionary(), strUrl, strToken, strNodeId, 0); //发送成功 检查是否有发送失败数据 if (!string.IsNullOrEmpty(retdict["faillist"])) { string[] strMobiles = retdict["faillist"].Split(','); string mobiles = "'" + string.Join("','", strMobiles.Where(s => !string.IsNullOrEmpty(s))) + "'"; this.Invoke(new Action <string>(p1 => { lb_Send.Items.Add("[" + p1 + "] 无效号码"); }), new object[] { retdict["faillist"] }); UpdateSmsSendStatus(new { Status = 2, Mobiles = mobiles, BatchNum = sod["SerialNumber"] }.ToStringObjectDictionary(), strUrl, strToken, strNodeId, 0); } } else { this.Invoke(new Action <string, string>((p1, p2) => { lb_Send.Items.Add("[" + p1 + "] 发送失败[" + (smsRetCodeDic.ContainsKey(p2) ? smsRetCodeDic[p2] : "发送异常") + "]"); }), new object[] { (string)sod["UserNumber"], retdict["result"] }); //发送失败 UpdateSmsSendStatus(new { Status = 2, Mobiles = ((string)sod["UserNumber"]), BatchNum = sod["SerialNumber"] }.ToStringObjectDictionary(), strUrl, strToken, strNodeId, 0); } }); //回执 } } }); } }, 5000, () => { return(false); },//永远不停止 () => { return(!(smsPointDic.Count > 0)); }//未获取到节点时跳过 ); }