Exemple #1
0
        /// <summary>
        /// 华信短信发送方法
        /// </summary>
        /// <param name="mobile">手机号码</param>
        /// <param name="message">发送内容</param>
        /// <returns></returns>
        private static SubmitSMSResult HXSMS(string mobile, string message)
        {
            SubmitSMSResult SubmitSMSResult = new SubmitSMSResult();

            try
            {
                string Sign = "智策管家";
                message += string.Format("【{0}】", Sign);

                Encoding       myEncoding = Encoding.GetEncoding("UTF-8");
                string         param      = "action=send&userid=" + HttpUtility.UrlDecode("", myEncoding) + "&account=" + HttpUtility.UrlEncode(HXAccount, myEncoding) + "&password="******"&mobile=" + HttpUtility.UrlDecode(mobile, myEncoding) + "&content=" + HttpUtility.UrlEncode(message, myEncoding) + "&sendTime=";
                byte[]         postBytes  = Encoding.ASCII.GetBytes(param);
                HttpWebRequest req        = (HttpWebRequest)HttpWebRequest.Create("https://dx.ipyy.net/sms.aspx");
                req.Method        = "POST";
                req.ContentType   = "application/x-www-form-urlencoded;charset=UTF-8";
                req.ContentLength = postBytes.Length;
                using (Stream reqStream = req.GetRequestStream())
                {
                    reqStream.Write(postBytes, 0, postBytes.Length);
                }
                System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
                using (WebResponse wr = req.GetResponse())
                {
                    StreamReader           sr = new StreamReader(wr.GetResponseStream(), System.Text.Encoding.UTF8);
                    System.IO.StreamReader xmlStreamReader = sr;
                    xmlDoc.Load(xmlStreamReader);
                }
                if (xmlDoc == null)
                {
                    SubmitSMSResult.Code = 0;
                    SubmitSMSResult.Msg  = "短信提交失败";
                }
                else
                {
                    string ret    = xmlDoc.GetElementsByTagName("message").Item(0).InnerText.ToString();
                    string status = xmlDoc.GetElementsByTagName("returnstatus").Item(0).InnerText.ToString();
                    if ("Success".ToUpper().Equals(status.Trim().ToUpper()))
                    {
                        SubmitSMSResult.Code = 1;
                        SubmitSMSResult.Msg  = ret;
                    }
                    else
                    {
                        SubmitSMSResult.Code = 0;
                        SubmitSMSResult.Msg  = ret;
                    }
                }
            }
            catch
            {
                SubmitSMSResult.Code = 0;
                SubmitSMSResult.Msg  = "短信提交失败";
            }
            return(SubmitSMSResult);
        }
Exemple #2
0
        /// <summary>
        /// 华信短信平台
        /// </summary>
        /// <param name="mobile">手机号码</param>
        /// <param name="message">发送内容</param>
        /// <returns></returns>
        public static SubmitSMSResult Send(string mobile, string message)
        {
            SubmitSMSResult result = new SubmitSMSResult();

            switch (UseSms)
            {
            //华信短信平台
            case 1:
                result = HXSMS(mobile, message);
                break;

            default:
                result = new SubmitSMSResult {
                    Code = 0, Msg = "未找到提供的短信平台"
                };
                break;
            }
            return(result);
        }