登录时,密码+CKEY密码验证

发布时间 2024-01-11 14:59:48作者: Rachel_Diary

读GCM配置,判定账号是否需要验证;需要验证,就拆分字符串,后六位+剩余部分;post请求去验证

1.AESUtil对称加密

2.HttpWebRequest、HttpWebResponse、StreamReader 

  • 创建请求,获取响应流;
  • 请求分get、post两种方式;(*)
  • 读取响应流信息,用到StreamReader ,string类型的(符合JSON格式的)
  • JSON格式、实体类(实体列表)之间的转化
        public static string HttpPost(string url, string jsonStr)
        {
            HttpWebRequest request = null;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3
                | (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((sender, certificate, chain, errors) => true);//验证服务器证书回调自动验证
            try
            {
                request = (HttpWebRequest)WebRequest.Create(url);//创建一个HTTP请求
            }
            catch (Exception ex)
            {
                Console.WriteLine("Http Post请求 创建失败!" + ex.Message);
                //throw new Exception("Http请求创建失败", ex);
                return null;
            }
            request.Method = "POST";//Post请求方式 
            request.ContentType = "application/json";//内容类型
            request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36";

            byte[] byteArray;//设置参数,并进行URL编码
            if (jsonStr == null)
            {
                jsonStr = "";
            }
            byteArray = System.Text.Encoding.UTF8.GetBytes(jsonStr);//将Json字符串转化为字节byte数组
            request.ContentLength = byteArray.Length;//设置请求的ContentLength
            Stream writer;
            try
            {
                writer = request.GetRequestStream();//获取用于写入请求数据的Stream对象
            }
            catch (Exception ex)
            {
                Console.WriteLine("获取Http请求写入流失败!" + ex.Message);
                return null;
            }
            writer.Write(byteArray, 0, byteArray.Length);//将请求参数写入流
            writer.Close();//关闭请求流
            HttpWebResponse response;
            try
            {
                response = (HttpWebResponse)request.GetResponse();//获得响应流
            }
            catch (WebException ex)
            {
                Console.WriteLine("获取Http响应流失败!" + ex.Message);
                return null;
            }
            Stream responseStream = response.GetResponseStream();
            StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding("UTF-8"));
            string postContent = streamReader.ReadToEnd();
            streamReader.Close();
            return postContent;//Post请求后服务器返回的数据
        }
    }

  

3.C#使用JavaScriptSerializer类实现序列化与反序列化

列表→JSON,序列化;JSON→列表,反序列化

C#使用JavaScriptSerializer类实现序列化与反序列化得到JSON_c# javascriptserializer-CSDN博客