/// <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; } }