手机发送验证码—.net代码

注册过程中,短信发送验证码流程如下:

(1).用户提交手机号码,申请湖区验证码

(2).网站按照预制规则生成验证码

(3).网站将用户手机号码和验证码发送到短信平台

(4).将制定内容发送到制定手机号码

(5).用户收到验证码后,提交验证

(6).判断,提交表单

接口代码如下:

<span style="font-size:18px;">try{
Encoding myEncoding = Encoding.GetEncoding("UTF-8");
string param = "action=send&userid=" + userid + "&account=" + HttpUtility.UrlEncode(account, myEncoding) + "&password=" + HttpUtility.UrlEncode(password, myEncoding) + "&mobile=13012317839,13210910291&content=" + HttpUtility.UrlEncode(content, myEncoding) + "&sendTime=" + HttpUtility.UrlEncode(sendTime, myEncoding) + "&mobilenumber=2&countnumber=2&telephonenumber=0";
byte[] postBytes = Encoding.ASCII.GetBytes(param);
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://xtx.telhk.cn:8888/sms.aspx");
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
req.ContentLength = postBytes.Length;
using (Stream reqStream = req.GetRequestStream())
{
reqStream.Write(postBytes, 0, postBytes.Length);
}
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
using (WebResponse wr = req.GetResponse())
{
StreamReader sr = new StreamReader(wr.GetResponseStream(), System.Text.Encoding.UTF8);
System.IO.StreamReader xmlStreamReader = sr;
xmlDoc.Load(xmlStreamReader);
}
if (xmlDoc == null)
{
MessageBox.Show("请求发生异常" );
}
else {
String message = xmlDoc.GetElementsByTagName("message").Item(0).InnerText.ToString();
if(message =="ok"){
MessageBox.Show("发送成功" );
}
else {
MessageBox.Show(message );
}
}
}
catch (System.Net.WebException WebExcp)
{
MessageBox.Show("网络错误,无法连接到服务器!" );
}
</span>
其中,userid 是企业id, account是发送用户账号,password是发送账号的密码, 这些都来自短信接口运营商

content是发送内容,sendTime是定时发送,当为空时,表示立即发送 action是发送任务命令 checkcontent是检查内容包含非法关键字 taskName是任务名称,countnumber号码总数量,mobilenumber是说及号码数量,telephonenumber是小灵通或座机号码数。

通过短信运营商的短信接口,实现发送短信的任务。在content中,设置想发送的内容,通常是验证码,在发送成功后,同时把发送的验证码存入数据库,或者存在session中,以便用户提交后,进行判断验证码是否正确。都判断通过后,方可实现各种功能。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值