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 ;
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 = md5(pwd1); Console.WriteLine(pwd.Length); string cOntent= " [阅信] 验证码 888888 ,请注意保密,以防泄露!"; //string cOntent= "123456"; 语音验证码内容 string url = " http://60.205.14.180: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","13000000000"); parameters.Add("subid",""); parameters.Add("mttime", mttime);
parameters.Add("rpttype", "1");
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 md5(String s) { MD5 md5 = new MD5CryptoServiceProvider(); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s); bytes = md5.ComputeHash(bytes); md5.Clear();
string ret = ""; for (int i = 0; i < bytes.Length; i++) { ret += Convert.ToString(bytes[i], 16).PadLeft(2, '0'); } return ret.PadLeft(32, '0'); } 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; }
}
更多语言的 DEMO 可以去阅信短信平台找他们要,测试了下还不错。 http://www.jinloushiji.cn
![]() | 1 Septembers 2017-04-18 14:56:26 +08:00 请发布时考虑读者感受 |
![]() | 2 jayong 2017-04-18 15:44:28 +08:00 同上 |
3 keller 2017-04-18 16:52:26 +08:00 同上 |
![]() | 4 imherer 2017-04-18 17:07:41 +08:00 这明显是广告啊 |
5 atnopc 2017-04-18 17:45:03 +08:00 写得不错,我选择阿里大鱼 |
7 Fx8m 2017-04-19 08:44:53 +08:00 真硬啊 |
![]() | 8 sipangzifu 2017-04-19 14:58:14 +08:00 好干的货 |