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 = 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
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.