public void SendSMS(PlainSMS sms) { try { string post = ""; string send = string.Join(",", sms.Number); string content = sms.Signature + sms.Content; post = "act=sendmsg&unitid=" + _config.UserId + "&username="******"&passwd=" + _config.Password + "&phone=" + send + "&msg=" + content + "&port=&sendtime=" + DateTime.Now.ToString(); string t = HTTPRequest.PostWebRequest(sendUrl, post, Encoding.GetEncoding("GBK")); Console.WriteLine("发送字符串 " + post); //状态,批号,说明 bool ok = true; string rmsg = "短信提交成功"; string[] rt = t.Split(','); int rok = 0; int r = 1;//原来默认0 ,应为1 by lmw 1 代表已发送 if (int.TryParse(rt[0], out rok) && rok == 1) { } else { rmsg = GetErrorMsg(rok); Console.WriteLine(rmsg); LogClient.LogHelper.LogInfo("JCSY", "Connect Error ->", rmsg); ok = false; r = 99; } int i = 0; foreach (string number in sms.Number) { SMS s = new SMS(); s.Account = sms.Account; s.Audit = sms.Audit; s.Channel = sms.Channel; s.Content = sms.Content; s.Filter = sms.Filter; s.Level = sms.Level; s.Number = new List <string> { number }; s.SendTime = sms.SendTime; s.SerialNumber = sms.SerialNumber; s.StatusReport = sms.StatusReport; s.Signature = sms.Signature; s.SPNumber = sms.SPNumber; s.WapURL = sms.WapURL; i++; SendEventArgs se = new SendEventArgs(s, rt[1] + i.ToString().PadLeft(5, '0'), ok, (ushort)(2000 + r), rmsg, 1, 1); if (SendEvent != null) { SendEvent(this, se); } //string result = JsonSerialize.Instance.Serialize<SendEventArgs>(se); //Console.WriteLine("短信发送结果:" + result); ExSendEventArgs ese = new ExSendEventArgs(se); if (ok) { lock (locker) { sends.Add(se.SerialNumber, ese); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); LogClient.LogHelper.LogInfo("JCSY", "SendSMS Error ->", ex.Message); } }
private void _cm_ExpireCache(List <List <SMS> > caches) { if (sendProcess) { return; } sendProcess = true; Console.WriteLine("缓存过期条数 " + caches.Count); try { string post = ""; for (int i = 0; i < caches.Count; i++) { List <string> ss = new List <string>(); foreach (SMS s in caches[i]) { ss.AddRange(s.Number); } Console.WriteLine("第 " + i + " 条包含短信数量 " + caches[i].Count); string send = ""; foreach (string s in ss) { send += s + ","; } send = send.Substring(0, send.Length - 1); string content = caches[i][0].Content + caches[i][0].Signature; post = "act=sendmsg&unitid=" + _config.UserId + "&username="******"&passwd=" + _config.Password + "&phone=" + send + "&msg=" + content + "&port=&sendtime=" + DateTime.Now.ToString(); string t = HTTPRequest.PostWebRequest(sendUrl, post, Encoding.UTF8); Console.WriteLine("发送字符串 " + post); //状态,批号,说明 bool ok = true; string rmsg = "短信提交成功"; string[] rt = t.Split(','); int rok = 0; int.TryParse(rt[0], out rok); if (rok < 0) { rmsg = GetErrorMsg(rok); Console.WriteLine(rmsg); LogClient.LogHelper.LogInfo("JCSY", "Connect Error ->", rmsg); ok = false; } int r = 1;//原来默认0 ,应为1 by lmw 1 代表已发送 if (!ok) { // r = 101; r = 99;//提交失败 错误码应该在100以内吧 by lmw } foreach (SMS s in caches[i]) { SendEventArgs se = new SendEventArgs(s, rt[1] + s.Number[0], ok, (ushort)(2000 + r), rmsg, 1, 1); //string result = JsonSerialize.Instance.Serialize<SendEventArgs>(se); //Console.WriteLine("短信发送结果:" + result); ExSendEventArgs ese = new ExSendEventArgs(se); if (ok) { sends.Add(se.SerialNumber, ese); //LogClient.LogHelper.LogInfo("JCSY", "SendSMS OK ->", result); } else { //LogClient.LogHelper.LogInfo("JCSY", "SendSMS Fail ->", result); } if (SendEvent != null) { SendEvent(this, se); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); LogClient.LogHelper.LogInfo("JCSY", "SendSMS Error ->", ex.Message); } sendProcess = false; }