[C#]C#實現短信驗證碼接口示??/a> [C#]

來源:本網整理

this.Hide();隱藏當前窗體,Close的話會全部關閉。Form2 f=new Form2();f.Show();是隱藏而已,登陸窗體同樣開著,占內存。你可以看這個。http://www.jb51.net/article/53593.htmwww.anxorj.tw防采集請勿采集本網。

代碼出處:閱??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.anxorj.tw請勿采集。

免責聲明 - 關于我們 - 聯系我們 - 廣告聯系 - 友情鏈接 - 幫助中心 - 頻道導航
Copyright © 2017 www.anxorj.tw All Rights Reserved
陕西快乐10分下载