信息接口尝试请求信息

 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);
        } 
    }
    //需要认证,只能获取这些内容了。
 

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你的美,让我痴迷

你的好,我会永远记住你的。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值