关于一般发送短信和验证码之类的短信,需要先跟运营商尽心购买,运行商会提供访问的用户名和密码以及开发所用的接口文档。本文以江苏电信企信通为例,基于http短信接口进行开发。
public string SendMessage()
{
string message = "当前要发送的信息内容";
string loginname = "登录名";
string LoginPwd = "密码";
string tel = "手机号";
//在当前运营商的接口访问中密码采用MD5加密
LoginPwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(LoginPwd, "MD5").ToUpper();
//这是短信调用接口的地址,通过这个地址,把短信发送到手机上
string url = "http://www.zgdxt.com/Modules/Interface/http/Iservices.aspx?flag=sendsms&loginname=" + loginname
+ "&password=" + LoginPwd + "&p=" + tel + "&c=" + message;
WebRequest wRequest = WebRequest.Create(url);
WebResponse wResponse = wRequest.GetResponse();
Stream stream = wResponse.GetResponseStream();
StreamReader reader = new StreamReader(stream,
System.Text.Encoding.GetEncoding("gb2312"));
string r = reader.ReadToEnd();//短信发送成功返回信息
wResponse.Close();
return r;
}
该方法只是提供了接口的访问方式。具体返回信息需要咨询短信运营商。
阿弥陀佛么么哒