C # send SMS messages,

Source: Internet
Author: User

C # send SMS messages,

At present, many websites use the SMS sending function. How can this function be implemented. For webmasters, it is relatively cost-effective and simple to use the sms api. The steps are as follows:

1. Apply for an account from the Internet (http://sms.webchinese.cn/), remember the user name, the password will be sent to the phone, this is only the login password. After registration, five messages and three MMS messages will be sent.

2. view the sms api downstream interface (http://sms.webchinese.cn/api.shtml), and then get the key, is actually the encrypted login password. Start coding. The related code is as follows:

Using System; using System. collections. generic; using System. IO; using System. linq; using System. net; using System. text; using System. web; namespace Y_PostSms {public class YMethod {private string THE_UID = ""; // user name private string THE_KEY = ""; // interface key // <summary> return UTF-8-encoded sending interface address </summary> // <param name = "receivePhoneNumber"> destination phone number (use multiple phone numbers separated by commas) </param> /// <param name = "receiveSms"> the content of a text message. It can contain up to 400 characters. 70 characters/text message, 64 characters/text message, and billing </param> // <returns> </returns> public string GetPostUrl (string smsMob, string smsText) {string postUrl = "http://utf8.sms.webchinese.cn /? Uid = "+ THE_UID +" & key = "+ THE_KEY +" & smsMob = "+ smsMob +" & smsText = "+ smsText; return postUrl ;} /// <summary> send a text message to obtain the returned value </summary> public string PostSmsInfo (string url) {// you only need to pass the assembled URL to this function during the call. String strRet = null if (url = null | url. trim (). toString () = "") {return strRet;} 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); strRet = ser. readToEnd ();} catch (Exception ex) {strRet = null;} return strRet;} // <summary> confirm return information </summary> public string GetResult (string strRet) {int result = 0; try {result = int. parse (strRet); switch (result) {case-1: strRet = "this user account is not available"; break; case-2: strRet = "the interface key is incorrect, not the Account Login Password "; break; case-21: strRet =" MD5 interface key encryption is incorrect "; break; case-3: strRet =" insufficient SMS messages "; break; case-11: strRet = "This user is disabled"; break; case-14: strRet = "invalid characters in text message content"; break; case-4: strRet = "Incorrect Mobile Phone Number Format"; break; case-41: strRet = "Empty mobile phone number"; break; case-42: strRet = "Empty SMS content "; break; case-51: strRet = "the text message signature format is incorrect. The interface signature format is [Signature content]"; break; case-6: strRet = "IP limit "; break; default: strRet = "Number of sent messages:" + result; break ;}} catch (Exception ex) {strRet = ex. message;} return strRet ;}}}

 

3. Open the sending permission for online customer service and enter the signature as follows:

 

 

 

Source code: Y_PostSms.zip

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.