[C#]C#实现短信验证码接口示??/a> [C#]

来源:本网整理

this.Hide();隐藏当前窗体,Close的话会全部关闭。Form2 f=new Form2();f.Show();是隐藏而已,登陆窗体同样开着,占内存。你可以看这个。http://www.jb51.net/article/53593.htmwww.zgxue.com防采集请勿采集本网。

代码出处:阅??br/>网站地址:http://www.jinloushiji.cn scrolltotop.offset(100,120); scrolltotop.init();

[1].[代码] [C#]代码实现短信验证码接口示?? 跳至[1]

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Net; using System.IO; using System.IO.Compression; using System.Text.RegularExpressions; using System.Security.Cryptography;using System.Web;public class Test{ private static readonly string DefaultUserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"; private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return true; //总是接受 } static void Main(string[] args) { DateTime dt = DateTime.Now; string mttime = dt.ToString("yyyyMMddHHmmss"); string pwd1 = "*************"+mttime; string pwd = GetMD5(pwd1) string content = "【阅信】验证码888888,打死也不能告诉别人哦??; string url = "http://183.203.28.226:9000/HttpSmsMt"; Encoding encoding = Encoding.GetEncoding("utf-8"); IDictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("name", "****"); parameters.Add("pwd", pwd); parameters.Add("content",content); parameters.Add("phone","13381272353"); parameters.Add("subid",""); parameters.Add("mttime", mttime); HttpWebResponse response = CreatePostHttpResponse(url,parameters,encoding); //打印返回?? Stream stream = response.GetResponseStream(); //获取响应的字符串?? StreamReader sr = new StreamReader(stream); //创建一个stream读取?? string html = sr.ReadToEnd(); //从头读到尾,放到字符串html Console.WriteLine(html); } public static string GetMD5(string myString) { MD5 md5 = new MD5CryptoServiceProvider(); // byte[] fromData = System.Web.HttpUtility.UrlEncode.GetBytes(myString); byte[] fromData = Encoding.Default.GetBytes(myString); byte[] targetData = md5.ComputeHash(fromData); string byte2String = null; for(int i=0;i<targetData.Length;i++) { byte2String+= targetData[i].ToString("x"); } return byte2String; } public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary<string, string> parameters,Encoding charset) { HttpWebRequest request = null; //HTTPSQ请求 ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); request = WebRequest.Create(url) as HttpWebRequest; request.ProtocolVersion = HttpVersion.Version10; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.UserAgent = DefaultUserAgent; //如果需要POST数据 if (!(parameters == null || parameters.Count == 0)) { StringBuilder buffer = new StringBuilder(); int i = 0; foreach (string key in parameters.Keys) { if (i > 0) { buffer.AppendFormat("&{0}={1}", key, parameters[key]); } else { buffer.AppendFormat("{0}={1}", key, parameters[key]); } i++; } byte[] data = charset.GetBytes(buffer.ToString()); using (Stream stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } } return request.GetResponse() as HttpWebResponse; } } SyntaxHighlighter.autoloader( 'applescript/js/sh309/scripts/shBrushAppleScript.js?t=1451961936000', 'actionscript3 as3/js/sh309/scripts/shBrushAS3.js?t=1451961936000', 'bash shell/js/sh309/scripts/shBrushBash.js?t=1451961936000', 'coldfusion cf/js/sh309/scripts/shBrushColdFusion.js?t=1451961936000', 'cpp c/js/sh309/scripts/shBrushCpp.js?t=1451961936000', 'obj-c objc/js/sh309/scripts/shBrushObjC.js?t=1451961936000', 'c# c-sharp csharp/js/sh309/scripts/shBrushCSharp.js?t=1451961936000', 'css/js/sh309/scripts/shBrushCss.js?t=1451961936000', 'delphi pascal/js/sh309/scripts/shBrushDelphi.js?t=1451961936000', 'diff patch pas/js/sh309/scripts/shBrushDiff.js?t=1451961936000', 'erl erlang/js/sh309/scripts/shBrushErlang.js?t=1451961936000', 'groovy/js/sh309/scripts/shBrushGroovy.js?t=1451961936000', 'haxe hx/js/sh309/scripts/shBrushHaxe.js?t=1451961936000', 'java/js/sh309/scripts/shBrushJava.js?t=1451961936000', 'jfx javafx/js/sh309/scripts/shBrushJavaFX.js?t=1451961936000', 'js jscript javascript/js/sh309/scripts/shBrushJScript.js?t=1451961936000', 'perl pl/js/sh309/scripts/shBrushPerl.js?t=1451961936000', 'php/js/sh309/scripts/shBrushPhp.js?t=1451961936000', 'text plain/js/sh309/scripts/shBrushPlain.js?t=1451961936000', 'py python/js/sh309/scripts/shBrushPython.js?t=1451961936000', 'ruby rails ror rb/js/sh309/scripts/shBrushRuby.js?t=1451961936000', 'scala/js/sh309/scripts/shBrushScala.js?t=1451961936000', 'sql/js/sh309/scripts/shBrushSql.js?t=1451961936000', 'vb vbnet/js/sh309/scripts/shBrushVb.js?t=1451961936000', 'xml xhtml xslt html/js/sh309/scripts/shBrushXml.js?t=1451961936000' ); SyntaxHighlighter.all();

关于后台监听的问题,这个可以这样实现,首先,在程序中调用serialport的open方法,先将这个串口打开,然后在串口的DataReceived事件里面编写你的处理写入数据的代码就可以了。下面是我写的通过短信猫发送

调用Console.WriteLine(GoldbachConjecture(6,100,5,"{0}={1}+{2};哥德巴赫猜想public static string GoldbachConjecture(int startNumber,int endNumber,int maxLength,string formatString){StringBuilder result=new StringBuilder();List<int>primeNumbers=GetPrimeNumber(endNumber);排除e799bee5baa6e4b893e5b19e313333303266622的数字primeNumbers.RemoveAt(0);循环区间内的偶数int index=0;for(int i=Math.Max(6,startNumber);i;i+2){输出拆分后的结果foreach(int primeNumber in primeNumbers){两数相加超出范围时退出循环if((i-primeNumber))break;判断当前的偶数减去一个质数后,另一个值是否在质数列表中if!primeNumbers.Contains(i-primeNumber))continue;输出指定格式result.AppendFormat(formatString,i,primeNumber,i-primeNumber);只输出一次。如果要把所有可能都输出的话,请取消循环内第一行注释并注释下面这行。break;}每行输出 maxLength 个if(+index%maxLength=0){result.AppendLine();}}return result.ToString();}获取所有小于 endNumber的素数(质数)public static List<int>GetPrimeNumber(int endNumber){List<int>primeNumbers=new List();primeNumbers.Add(2);for(int i=3;i;i+2){bool isPrimeNumber=true;判断当前值之前的质数判断能否整除foreach(int primeNumber in primeNumbers){能整除则不是质数if(i%primeNumber=0){isPrimeNumber=false;break;}平方根判断,减少运算次数if(primeNumber>Math.Sqrt(i)){break;}}如果是质数if(isPrimeNumber){primeNumbers.Add(i);}}return primeNumbers;}内容来自www.zgxue.com请勿采集。

免责声明 - 关于我们 - 联系我们 - 广告联系 - 友情链接 - 帮助中心 - 频道导航
Copyright © 2017 www.zgxue.com All Rights Reserved