using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Mail; using CY.Config; using CY.Infrastructure.DESEncrypt; using CY.Infrastructure.Common; namespace CY.SendMessage { public static class SendMessge { private static CY.SendMessage.ServerSDK.LinkWS webService = null; static SendMessge() { if (webService == null) { webService = new CY.SendMessage.ServerSDK.LinkWS(); webService.Url = "http://mb345.com/WS/linkWS.asmx"; } } //短信帐号 //账号:YG00001 //密码:733955 #region 发送短信 /// /// 发送文本消息 - 异步 返回1表示成功,其它为错误信息 /// /// 手机号码字符串,请用半角逗号分隔(单次提交上限1000个) /// 短信内容,手机限70字,小灵通限54字,超长系统自动拆分 /// 发送时间(格式为:yyyy-mm-dd HH:mm),即时发送请传空值 /// public static bool SendSMS(string phones, string contents, string setTime) { string msg = ""; int result = webService.BatchSend(WebInfo.Instance.SMSLoginName.ToString2(), DESEncrypt.Decrypt(WebInfo.Instance.SMSPwd.ToString2()), phones, contents + "【川印】", "", setTime); switch (result) { case -1: msg = "帐号未注册"; break; case -2: msg = "其他错误"; break; case -3: msg = "密码错误"; break; case -4: msg = "手机号码格式不对"; break; case -5: msg = "余额不足"; break; case -6: msg = "定时发送时间不是有效时间格式"; break; case -7: msg = "内容为空或者超过上限(500)"; break; case -8: msg = "定时时间格式错误"; break; case 0: msg = "1";//成功 break; case 1: msg = "1";//成功 break; default: msg = "未知错误"; break; } if (msg == "1") return true; else { return false; //Common.ExceptionEx.MyExceptionLog.AddLogError(msg); } } #endregion public static string GetBalance() { string sa = webService.SelSum(WebInfo.Instance.SMSLoginName.ToString2(), DESEncrypt.Decrypt(WebInfo.Instance.SMSPwd.ToString2())).ToString(); return sa; } public static bool SendEmail(string subject, string content, string email) { try { MailMessage mailmessage = new MailMessage(); SmtpClient smtp = new SmtpClient(); smtp.Host = WebInfo.Instance.EmailServer.ToString2(); smtp.Port = Convert.ToInt32(WebInfo.Instance.EmailPort.ToString2()); smtp.UseDefaultCredentials = true; smtp.Credentials = new System.Net.NetworkCredential(WebInfo.Instance.Email.ToString2(), DESEncrypt.Decrypt(WebInfo.Instance.EmailPwd.ToString2())); smtp.EnableSsl = false; mailmessage.To.Clear(); mailmessage.To.Add(email); mailmessage.From = new MailAddress(WebInfo.Instance.Email.ToString2(), WebInfo.Instance.EmailLoginName.ToString2(), System.Text.Encoding.UTF8); mailmessage.Subject = subject; mailmessage.SubjectEncoding = System.Text.Encoding.UTF8; mailmessage.Body = content; mailmessage.IsBodyHtml = true; mailmessage.BodyEncoding = System.Text.Encoding.UTF8; mailmessage.Priority = MailPriority.High; smtp.Send(mailmessage); } catch (Exception ex) { return false; } return true; } public static bool SendEmailMemberTest(string subject, string content, string email, string emailsmtp, string emailname, string emailaddress, string emailpwd, string port) { try { MailMessage mailmessage = new MailMessage(); SmtpClient smtp = new SmtpClient(); smtp.Host = emailsmtp; smtp.Port = Convert.ToInt32(port); smtp.UseDefaultCredentials = true; smtp.Credentials = new System.Net.NetworkCredential(emailaddress, DESEncrypt.Decrypt(emailpwd)); smtp.EnableSsl = false; mailmessage.To.Clear(); mailmessage.To.Add(email); mailmessage.From = new MailAddress(emailaddress, emailname, System.Text.Encoding.UTF8); mailmessage.Subject = subject; mailmessage.SubjectEncoding = System.Text.Encoding.UTF8; mailmessage.Body = content; mailmessage.IsBodyHtml = true; mailmessage.BodyEncoding = System.Text.Encoding.UTF8; mailmessage.Priority = MailPriority.High; smtp.Send(mailmessage); } catch (Exception ex) { return false; } return true; } } }