private void SendSMS(string phone, string content) { if (string.IsNullOrEmpty(phone.Trim())) { return; } MG_DAL.MgoogpsWebClient mwc = new MG_DAL.MgoogpsWebClient(); mwc.RequestUrl = "https://api.miaodiyun.com/20150822/industrySMS/sendSMS"; //ACCOUNT SID +AUTH TOKEN + timestamp string ACCOUNTSID = "dba0b636a1b74391bb1503beaff97bfc"; string AUTHTOKEN = "76a183e571014f3ea04138bdb5387c24"; string timestamp = DateTime.Now.ToString("yyyyMMddHHmmss"); string sig = FormsAuthentication.HashPasswordForStoringInConfigFile(ACCOUNTSID + AUTHTOKEN + timestamp, "MD5").ToLower(); byte[] postdata = Encoding.UTF8.GetBytes(string.Format("accountSid={0}&smsContent={1}&to={2}×tamp={3}&sig={4}&respDataType=JSON", ACCOUNTSID, content, phone, timestamp, sig)); mwc.RequestContentType = "application/x-www-form-urlencoded"; mwc.RequestPostData = postdata; string reulst = mwc.RequestSend(); JavaScriptSerializer js = new JavaScriptSerializer(); Entity.SMSResult smsresult = js.Deserialize <Entity.SMSResult>(reulst); var logName = "PushedMessage" + DateTime.Now.ToString("yyyyMM") + ".log"; // Utils.log("UserID:" + UserID + ",phone:" + phone + ",DeviceName:" + DeviceName + ",MessageType:" + MessageType + ",smsresult.RespCode" + smsresult.RespCode, logName); if (smsresult.RespCode.Equals("00000")) { } // return smsresult.RespCode; }
public string SMSCodes(string phone) { try { string exist = Utils.GetCache <object>("SMS" + phone).toStringEmpty(); if (!exist.Equals(string.Empty)) { // HttpRuntime.Cache.Insert("SMS" + phone, exist, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero); // return string.Empty; } MG_DAL.MgoogpsWebClient mwc = new MG_DAL.MgoogpsWebClient(); mwc.RequestUrl = "https://api.miaodiyun.com/20150822/industrySMS/sendSMS"; //ACCOUNT SID +AUTH TOKEN + timestamp string ACCOUNTSID = "dba0b636a1b74391bb1503beaff97bfc"; string AUTHTOKEN = "76a183e571014f3ea04138bdb5387c24"; string timestamp = DateTime.Now.ToString("yyyyMMddHHmmss"); int SecurityCode = new Random().Next(100000, 999999); string smsContent = string.Format("【美谷科技】您的验证码是{0} ,{1}分钟输入有效。", SecurityCode, 10); string sig = FormsAuthentication.HashPasswordForStoringInConfigFile(ACCOUNTSID + AUTHTOKEN + timestamp, "MD5").ToLower(); byte[] postdata = Encoding.UTF8.GetBytes(string.Format("accountSid={0}&smsContent={1}&to={2}×tamp={3}&sig={4}&respDataType=JSON", ACCOUNTSID, smsContent, phone, timestamp, sig)); mwc.RequestContentType = "application/x-www-form-urlencoded"; mwc.RequestPostData = postdata; string reulst = mwc.RequestSend(); JavaScriptSerializer js = new JavaScriptSerializer(); Entity.SMSResult smsresult = js.Deserialize <Entity.SMSResult>(reulst); if (smsresult.RespCode.Equals("00000")) { HttpRuntime.Cache.Insert("SMS" + phone, SecurityCode, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero); return(""); } return(smsresult.RespCode); } catch (Exception ex) { return(ex.Message); } }