C# code for sending mobile phone text messages using the "net construction" platform

I have always used this platform to send text messages on my mobile phone. I used it today when I was doing a new project, but I couldn’t find it on the blog. I had to look through the previous source code for a long time before I found it. I wrote it down for backup:

 

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 = "There is no such user account";
                    break;
                case "-2":
                    s = "Incorrect key (not user password)";
                    break;
                case "-3":
                    s = "Insufficient number of SMS messages";
                    break;
                case "-11":
                    s = "The User is disabled";
                    break;
                case "-14":
                    s = "Illegal characters in the text message";
                    break;
                case "-4":
                    s = "The format of the phone number is incorrect";
                    break;
                case "-41":
                    s = "Mobile number is empty";
                    break;
                case "-42":
                    s = "SMS is empty";
                    break;
                default:
                    s = "Successfully sent" + str + "SMS";
                    break;
            }
            return s;
        }
        /// <summary>Send SMS
        ///
        /// < /summary>
        /// <param name="mobile">Mobile phone number, multiple mobile phone numbers are separated by .</param>
        /// <param name="body">SMS content</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;
            }
        }
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326117682&siteId=291194637