用“网筑”平台发手机短信的C#代码
Posted 肖尘
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用“网筑”平台发手机短信的C#代码相关的知识,希望对你有一定的参考价值。
这个是之前做项目的时候,用这个发手机短信,感觉还不错,就分析给大家。
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#代码的主要内容,如果未能解决你的问题,请参考以下文章