微信开发一获取用户授权(静默授权方式)

   /// <summary>
        /// 获取用户授权返回json序列化为UserAuthorizeInfo
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static UserAuthorizeInfo GetDicUserAuthorize(string code)
        {
            string url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + Common.Config.APPID + "&secret=" + Common.Config.APPSCRECT + "&code=" + code + "&grant_type=authorization_code";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Method = "Get";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream responsestream = response.GetResponseStream();
            StreamReader reader = new StreamReader(responsestream, Encoding.GetEncoding("utf-8"));
            string json = reader.ReadToEnd();
            reader.Close();
            responsestream.Close();
            //JavaScriptSerializer serializer = new JavaScriptSerializer();
            //Dictionary<string, object> DicUserAuthorize = serializer.Deserialize<Dictionary<string, object>>(json);
         
            //return DicUserAuthorize;

            DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(UserAuthorizeInfo));

            using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
            {
                UserAuthorizeInfo obj = js.ReadObject(ms) as UserAuthorizeInfo;
                return obj;
            }
        }

  

微信开发一获取用户授权(静默授权方式)

上一篇:微信公众号开发模型WeChat


下一篇:DCloud旗下的uni-app如何判断是否安装腾讯QQ微信微博支付宝淘宝客户端