下面我们来实现一下如何发送以及接收验证码的案例,首先你得在网上注册一个个人账号例如在互亿无线短信平台上注册,注册成功后你会得到50到100条的免费注册短信(不同的短信平台送的短信条数都不一样哦),然后你需要在controller层调用它。注(该Controller调用方法代码为借鉴代码)
Controller调用的代码:
public void Page_Load(string ShouJiHaoMa)
{
string account = "C27042";//用户名是登录用户中心->验证码、通知短信->帐户及签名设置->APIID
string password = "1171786ebbaf7146282803b6c240e"; //密码是请登录用户中心->验证码、通知短信->帐户及签名设置->APIKEY
string mobile = ShouJiHaoMa;
Random rad = new Random();
int mobile_code = rad.Next(1000, 10000);
string content = "您的验证码是:" + mobile_code + " 。请不要把验证码泄露给其他人。";
string postStrTpl = "account={0}&password={1}&mobile={2}&content={3}";
UTF8Encoding encoding = new UTF8Encoding();
byte[] postData = encoding.GetBytes(string.Format(postStrTpl, account, password, mobile, content));
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.