class Program
{
static void Main(string[] args)
{
using (ServiceHost servericehost=new ServiceHost (typeof(Service1)))
{
servericehost.Opening += Servericehost_Opening;
servericehost.Opened += Servericehost_Opened;
servericehost.Open();
string str = GetMD5("13072362210");//d303568aec9670825402a265bc2c4472
//d303568aec9670825402a265bc2c4472
Console.WriteLine("短信查询模板结果为:");
Send();
Console.WriteLine("\n短信余额查询结果为:");
requestInfo();
//Console.WriteLine(str);
Console.ReadKey();
}
}
private static void Servericehost_Opened(object sender, EventArgs e)
{
Console.WriteLine("服务开启成功");
}
private static void Servericehost_Opening(object sender, EventArgs e)
{
Console.WriteLine("服务正在开启。。。。");
}
public static string GetMD5(string mgs)
{
byte[] bys = System.Text.Encoding.Default.GetBytes(mgs);
MD5 mdt = MD5.Create();
byte[] jmh = mdt.ComputeHash(bys);
string jmstr = BitConverter.ToString(jmh).Replace("-", "").ToLower();
return jmstr;
}
public static string MD5pwd(string password)
{
//创建一个md5对象
MD5 md5 = MD5.Create();
//将字符串转为字节组
Byte[] buffe = System.Text.Encoding.Default.GetBytes(password);
//调用MD5加密的方法
//返回加密后的方法
Byte[] md5buffe = md5.ComputeHash(buffe);
//由于将md5buffe中的每个元素进行ToString后,产生大量的字符串,而我们需要将这些大量的字符串拼接起来,并且返回
//所以我们创建StringBuilder对象
StringBuilder strbuilder = new StringBuilder();
for (int i = 0; i < md5buffe.Length; i++)
{
strbuilder.Append(md5buffe[i].ToString("x2"));
}
//解释ToString("X2")
//转化为16进制字符串。
//大写X:ToString("X2")即转化为大写的16进制。
//小写x:ToString("x2")即转化为小写的16进制。
//2表示输出两位,不足2位的前面补0,如 0x0A 如果没有2,就只会输出0xA
return strbuilder.ToString();
}
//获取请求信息
public async static void Send()
{
HttpClient client = new HttpClient();
string timestamp = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000).ToString();
//提供参数
List<KeyValuePair<string, string>> nameValueCollection = new List<KeyValuePair<string, string>>();
nameValueCollection.Add(new KeyValuePair<string, string>("accountSid", "647b0ddb79110d395f19423a5bddc4c9"));
nameValueCollection.Add(new KeyValuePair<string, string>("timestamp", timestamp));
nameValueCollection.Add(new KeyValuePair<string, string>("sig", MD5pwd("647b0ddb79110d395f19423a5bddc4c9" + "eacd7d6c88079bf693a17d7a5c41035d" + timestamp).ToLower()));
nameValueCollection.Add(new KeyValuePair<string, string>("templateid", "607981"));
HttpContent httpcount = new FormUrlEncodedContent(nameValueCollection);
HttpResponseMessage httprespance = await client.PostAsync("https://openapi.miaodiyun.com/distributor/smsTemplate/query", httpcount);
string rsult = await httprespance.Content.ReadAsStringAsync();
Console.WriteLine(rsult);
}
public async static void requestInfo()
{
HttpClient client = new HttpClient();
string timestamp = ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000).ToString();
//提供参数
List<KeyValuePair<string, string>> nameValueCollection = new List<KeyValuePair<string, string>>();
nameValueCollection.Add(new KeyValuePair<string, string>("accountSid", "647b0ddb79110d395f19423a5bddc4c9"));
nameValueCollection.Add(new KeyValuePair<string, string>("timestamp", timestamp));
nameValueCollection.Add(new KeyValuePair<string, string>("sig", MD5pwd("647b0ddb79110d395f19423a5bddc4c9" + "eacd7d6c88079bf693a17d7a5c41035d" + timestamp).ToLower()));
HttpContent httpcount = new FormUrlEncodedContent(nameValueCollection);
HttpResponseMessage httprespance = await client.PostAsync("https://openapi.miaodiyun.com/distributor/user/query", httpcount);
string rsult = await httprespance.Content.ReadAsStringAsync();
Console.WriteLine(rsult);
}
}
//需要认证,只能获取这些内容了。
信息接口尝试请求信息
于 2019-12-03 19:44:39 首次发布