コード例 #1
0
        private Boolean DoSMS(InSMS inSMS)
        {
            Boolean result = true;
            ESMSLog smsLog = new ESMSLog();

            try
            {
                SMSManager smsManger = new SMSManager();

                SMSResult_API51 Response = smsManger.PostSMS_API51(inSMS, ref smsLog);
                if (Response.result == "0")
                {
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            catch (Exception ex)
            {
                smsLog.Exception += "DoSMS Error:" + ex.Message;
                smsLog.Exception += "DoSMS Inner Error:" + ex.InnerException.Message;
                result            = false;
            }
            using (PPContent db = new PPContent())
            {
                smsLog.IsSuccess = result;
                db.DBSMSLog.Add(smsLog);
                db.SaveChanges();
            }

            return(result);
        }
コード例 #2
0
        public void PostSMS_API51(InSMS inSMS)
        {
            string url = ConfigurationManager.AppSettings["IQBWX_SiteUrl"];

            url += "API/SMS/DoSMS";
            string data = "PhoneNumber=" + inSMS.PhoneNumber;

            data += "&Tpl_id=" + inSMS.Tpl_id;
            data += "&Sign=" + inSMS.Sign;
            data += "&Parameters=" + inSMS.Parameters;
            HttpHelper.RequestUrlSendMsg(url, HttpHelper.HttpMethod.Post, data, "application/x-www-form-urlencoded");
        }
コード例 #3
0
        private ESMSVerification SendSMSToUser(string Phone)
        {
            string VerifyCode        = StringHelper.GenerateVerifyCode();
            int    SMSMaxIntervalSec = Convert.ToInt32(ConfigurationManager.AppSettings["SMSMaxIntervalSec"]);

            InSMS inSMS = new InSMS();

            inSMS.Init();
            inSMS.Tpl_id      = Convert.ToInt32(SMSTemplate.NormalVerify).ToString();
            inSMS.PhoneNumber = Phone;
            inSMS.Parameters  = VerifyCode + "," + SMSMaxIntervalSec / 60;

            bool             sentResult = this.DoSMS(inSMS);
            ESMSVerification sms        = null;

            using (PPContent db = new PPContent())
            {
                sms = new ESMSVerification()
                {
                    VerifyCode  = VerifyCode,
                    MobilePhone = Phone,

                    SendDateTime    = DateTime.Now,
                    SMSVerifyStatus = SMSVerifyStatus.Sent,
                    SMSEvent        = SMSEvent.OO_Register,
                };
                if (sentResult == false)
                {
                    sms.SMSVerifyStatus = SMSVerifyStatus.SentFailure;
                }

                db.DBSMSVerification.Add(sms);
                db.SaveChanges();
            }
            return(sms);
        }
コード例 #4
0
        public SMSResult_API51 PostSMS_API51(InSMS InSMS, ref ESMSLog smsLog)
        {
            try
            {
                smsLog.APPName   = "API51";
                smsLog.UserPhone = InSMS.PhoneNumber;

                String          querys       = "";
                String          bodys        = "mobile={0}&params={1}&sign={2}&tpl_id={3}";
                String          url          = host + path;
                HttpWebRequest  httpRequest  = null;
                HttpWebResponse httpResponse = null;
                bodys = string.Format(bodys, InSMS.PhoneNumber, InSMS.Parameters, InSMS.Sign, InSMS.Tpl_id);

                smsLog.RequestMessage = bodys;

                if (0 < querys.Length)
                {
                    url = url + "?" + querys;
                }

                if (host.Contains("https://"))
                {
                    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                    httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
                }
                else
                {
                    httpRequest = (HttpWebRequest)WebRequest.Create(url);
                }
                httpRequest.Method = method;
                httpRequest.Headers.Add("Authorization", "APPCODE " + appcode);
                //根据API的要求,定义相对应的Content-Type
                httpRequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
                if (0 < bodys.Length)
                {
                    byte[] data = Encoding.UTF8.GetBytes(bodys);
                    using (Stream stream = httpRequest.GetRequestStream())
                    {
                        stream.Write(data, 0, data.Length);
                    }
                }
                try
                {
                    httpResponse = (HttpWebResponse)httpRequest.GetResponse();
                }
                catch (WebException ex)
                {
                    httpResponse = (HttpWebResponse)ex.Response;
                }


                Stream       st     = httpResponse.GetResponseStream();
                StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
                string       json   = reader.ReadToEnd();

                smsLog.ResponseMessage = json;
                smsLog.SendDateTime    = DateTime.Now;

                JsonSerializer  serializer = new JsonSerializer();
                StringReader    sr         = new StringReader(json);
                SMSResult_API51 result     = serializer.Deserialize <SMSResult_API51>(new JsonTextReader(sr));
                return(result);
            }
            catch (Exception ex)
            {
                smsLog.Exception += "SMSManager Post:" + ex.Message;
                throw ex;
            }
        }