100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > C# asp.net手机验证码登录 获取验证码(网页版)

C# asp.net手机验证码登录 获取验证码(网页版)

时间:2019-12-16 09:53:16

相关推荐

C# asp.net手机验证码登录 获取验证码(网页版)

接口版登录。/wybshyy/article/details/103121796

//phone.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="phone.aspx.cs" Inherits="旅游图文.phone" %>

<!DOCTYPE html>

<html xmlns="/1999/xhtml">

<head runat="server">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

</div>

</form>

</body>

</html>

//phone.aspx.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Drawing;

using System.Text;

using System.Threading.Tasks;

using System.IO;

using ;

using ponentModel;

namespace 旅游图文

{

public partial class phone : System.Web.UI.Page

{

//从/申请账号,获得密钥,它会送5条免费短信,

//这是我看到的多个网址中不用实名认证,不用充钱的,如果只是自己随便搞搞的,可以用这个网站

private string uid = "用户名";

private string key = "密钥";

protected void Page_Load(object sender, EventArgs e)

{

string number = "接受短信的手机号";

string smsText = "【签名】你的验证码是123456[签名]";//签名必须有

string postUrl = GetPostUrl(number,smsText);

string result = PostSmsInfo(postUrl);

string t = GetResult(result);

}

private string GetPostUrl(string smsMob,string smsText)

{

//uid为用户名,key为密钥

string postUrl = "http://utf8./?Uid="+uid+"&key="+key+"&smsMob="+smsMob+"&smsText="+smsText;

return postUrl;

}

public string PostSmsInfo(string url)

{

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;MISE 6.0;Window 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;

}

public string GetResult(string strRet)

{

int result = 0;

try

{

result = int.Parse(strRet);

switch(result)

{

case -1:

strRet = "没有该用户账户";

break;

case -2:

strRet = "接口密钥不正确,不是账户登陆密码";

break;

case -21:

strRet = "MDS接口密钥加密不正确";

break;

case -3:

strRet = "短信数量不足";

break;

case -11:

strRet = "该用户被禁用";

break;

case -14:

strRet = "短信内容出现非法字符";

break;

case -4:

strRet = "手机格式不正确";

break;

case -41:

strRet = "手机号码为空";

break;

case -42:

strRet = "短信内容为空";

break;

case -51:

strRet = "短信签名格式不正确,接口签名格式为:【签名内容】";

break;

case -6:

strRet = "IP限制";

break;

default:

strRet = "发送短信数量:" + result;

break;

}

}

catch(Exception ex)

{

strRet = ex.Message;

}

TextBox1.Text = strRet.ToString();

return strRet;

}

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。