C 번호는 애플릿 (+ asp.net 프런트 엔드 서버 측 코드)로 오픈 아이디 마이크로 채널 사용자 정보를 얻기

서버 측

사용하여 시스템;
사용 System.Collections.Generic 단계;
사용 을 System.Linq 단계;
사용 System.Web 단계;
사용 System.Web.Services 단계; 

사용 System.Web.Script.Serialization 단계;
사용 System.Web.Script.Services 단계;
사용 System.Runtime.Serialization.Json 단계;
사용 System.Data 단계;
사용 System.Text 단계;
사용 System.IO 단계;
사용 System.Net 단계;
사용 Newtonsoft.Json 단계;
사용 Newtonsoft.Json.Linq 단계; 

///  <요약> 
/// API的摘要说明
 ///  </ 요약>
[WebService에 (네임 스페이스는 = " http://tempuri.org/ " )] 
[WebServiceBinding (conformsTo = WsiProfiles.BasicProfile1_1)]
 // 이 스크립트에서 ASP.NET AJAX 웹 서비스의 사용을 허용 호출하려면 다음 줄의 주석 . 
[System.Web.Script.Services.ScriptService]
 공공  클래스 API 다음 System.Web.Services.WebService 
{ 
    [의 WebMethod] 
    공공  무효 오픈 ID ( 문자열 코드) 
    { 
        // 임시 로그인 자격 증명 SESSION_KEY 코드 수집 및 오픈 ID 
        문자열 js_code = 코드;
         / / 여기에 자신의 비밀 APPID을 작성하고 애플릿 
        문자열 serviceAddress = "https://api.weixin.qq.com/sns/jscode2session?appid=appid&secret=secret&js_code= " + js_code + " 및 grant_type = authorization_code " ; 
        
        HttpWebRequest를 요청 = (HttpWebRequest를)이 WebRequest.Create (serviceAddress) 
        request.Method = " GET " ; 
        request.ContentType = " textml; 문자셋 = UTF-8 " ; 
        HttpWebResponse 클래스 응답 = (HttpWebResponse 클래스)를 request.GetResponse () 
        스트림 myResponseStream = response.GetResponseStream을 (); 
        는 StreamReader myStreamReader을= 새로운 새 상기에서는 StreamReader (myResponseStream, Encoding.UTF8)
         문자열 jsonData = myStreamReader.ReadToEnd (); 
        myStreamReader.Close (); 
        myResponseStream.Close (); 

        문자열 JSONString = jsonData; 
        jobject를 JSON = JObject.Parse (JSONString)를,
         문자열 오픈 ID = JSON [ " 오픈 ID " ]로 .toString (); 

        context.Response.Write (해서 getJSON (오픈 아이디)); 
    } 

    # 지역   표적 서열 JSON 문자열
     ///  <요약> 
    /// 표적 서열 JSON 문자열 
     / //  </ 요약> 
    /// <이름 = "T"typeparam> 개체 유형 </ typeParam> 
    ///  <PARAM NAME = "OBJ"> 개체 개체 </ PARAM> 
    ///  <반품> json으로 문자열 </ 반품> 
    공공  정적  문자열 해서 getJSON <T > (T OBJ) 
    { 
        // 참조 System.ServiceModel.Web을 추가해야합니다 
        / * * 
         위의 참조를 추가하지 않을 경우, System.Runtime.Serialization.Json *; JSON를 잘 작성하지 아 
         * * / 
        DataContractJsonSerializer JSON = 새로운 새로운 DataContractJsonSerializer ( 대해서 typeof (T))
         은 USING (MS = MemoryStream을 새로운 신규  MemoryStream을 ())
        {
            json.WriteObject (MS, OBJ); 
            문자열 szJson = Encoding.UTF8.GetString (ms.ToArray ());
            반환 szJson을; 
        } 
    } 
    #endregion 
}

추천

출처www.cnblogs.com/dujian123/p/11184781.html