用“網建”平台發手機簡訊的C#代碼

來源:互聯網
上載者:User

標籤:msm   break   def   throw   namespace   字元   article   xxxxxx   搜尋   

一直都用這個平台發手機簡訊的,今天做新項目的時候用到了,但是上來部落格搜尋不到,只好翻以前的原始碼翻了好久才找到了,先記下來,以作備用:


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;

namespace Niunan.CardShop.Web.Code
{
    public class SendMobile
    {

        /// <summary>返回傳送簡訊的狀態說明
        ///
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string GetMobileMSMStatus(string str)
        {
            string s = "";
            switch (str)
            {
                case "-1":
                    s = "沒有該使用者賬戶";
                    break;
                case "-2":
                    s = "密鑰不正確(不是使用者密碼)";
                    break;
                case "-3":
                    s = "簡訊數量不足";
                    break;
                case "-11":
                    s = "該使用者被禁用";
                    break;
                case "-14":
                    s = "簡訊內容出現非法字元";
                    break;
                case "-4":
                    s = "手機號格式不正確";
                    break;
                case "-41":
                    s = "手機號碼為空白";
                    break;
                case "-42":
                    s = "簡訊內容為空白";
                    break;
                default:
                    s = "成功發送" + str + "條簡訊";
                    break;
            }
            return s;
        }
        /// <summary>傳送簡訊
        ///
        /// </summary>
        /// <param name="mobile">手機號碼,多個手機號以,號相隔</param>
        /// <param name="body">簡訊內容</param>
        public static string SendMobileMSM(string mobile, string body)
        {
 
            string url = "http://utf8.sms.webchinese.cn/?Uid=xxxxxx&Key=xxxxxx&smsMob=" + mobile + "&smsText=" + body;
            string targeturl = url.Trim().ToString();
            try
            {
                HttpWebRequest hr = (HttpWebRequest)WebRequest.Create(targeturl);
                hr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
                hr.Method = "GET";
                hr.Timeout = 30 * 60 * 1000;
                WebResponse hs = hr.GetResponse();
                Stream sr = hs.GetResponseStream();
                StreamReader ser = new StreamReader(sr, Encoding.Default);
                return GetMobileMSMStatus(ser.ReadToEnd());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}

用“網建”平台發手機簡訊的C#代碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.