ASP.NET_ call micro-channel JS_SDK

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Threading.Tasks;


namespace wechat_test
{
    /// <summary>
    /// test 的摘要说明
    /// </summary>
    public class test : IHttpHandler
    {
        public class tokenObj
        {
            public string access_token { get; set; }
            public string expires_in { get; set; }
        }
        public class jsapiTicketObj
        {
            public string errcode { get; set; }
            public string errmsg { get; set; }
            public string ticket { get; set; }
            public string expires_in { get; SET ;} 
        } 

        public  void the ProcessRequest (the HttpContext context) 
        { 
            context.Response.ContentType = " text / Plain " ;
             String grant_type = " client_credential " ; // Get access_token fill client_credential    
            String AppId = " wx07b6790c0b49731a " ; // third party user The only evidence   
            String Secret = " 8fe8a582e16436e89256f74b2b7c5275 " ; //The only third-party user credential key that appsecret   
                                         // the url link addresses and parameters are not changed   
            String url = " https://api.weixin.qq.com/cgi-bin/token?grant_type= " + + grant_type " AppID = & " + AppId + " & Secret = " + Secret;
             // String = JsonConvert.SerializeObject JSON (RequestUrl (URL)); 
            tokenObj JsonConvert.DeserializeObject T_O = <tokenObj> (RequestUrl (URL)); 

            // String = Ticket" "; 

            String the access_token = t_o.access_token; 

            String URL2 = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token= " + the access_token + " & JSAPI type = " ; // this url link parameters can not be changed and   
            jsapiTicketObj j_t_o = JsonConvert.DeserializeObject <jsapiTicketObj> (RequestUrl (URL2)); 
            context.Response.Write (j_t_o.ticket); 
        } 
        #region request Url, no data is transmitted
         ///  <Summary> 
        /// request Url, no data is transmitted
         ///  </ Summary> 
        public  static  String RequestUrl ( String URL) 
        { 
            return RequestUrl (URL, " the GET "); 
        } 
        #Endregion 

        #region request Url, no data is transmitted
         ///  <Summary> 
        /// request Url, no data is transmitted
         ///  </ Summary> 
        public  static  String RequestUrl ( String URL, String Method) 
        { 
            // set parameters of 
            the HttpWebRequest the WebRequest.Create = Request (URL) AS the HttpWebRequest; 
            the CookieContainer CookieContainer = new new the CookieContainer (); 
            request.CookieContainer = CookieContainer; 
            request.AllowAutoRedirect =to true ; 
            request.method = Method; 
            request.ContentType = " text / HTML " ; 
            request.Headers.Add ( " charset " , " UTF-. 8 " ); 

            // send the request and obtain the corresponding response data 
            HttpWebResponse response = request.GetResponse () AS HttpWebResponse;
             // until request.GetResponse () program began landing page to send a request to the Post 
            Stream responseStream = response.GetResponseStream (); 
            StreamReader SR = new newThe StreamReader (responseStream, Encoding.UTF8);
             // returns the results page (html) Code 
            String Content = sr.ReadToEnd ();
             return Content; 
        } 
        #endregion 
        public  BOOL the IsReusable 
        { 
            GET 
            { 
                return  to false ; 
            } 
        } 
    } 
}

 

Guess you like

Origin www.cnblogs.com/imPedro/p/11018512.html
Recommended