zoukankan      html  css  js  c++  java
  • C# 获取微信小程序access_token

     1 /// <summary>
     2 /// 获取access_token
     3 /// </summary>
     4 /// <returns></returns>
     5 public static string GetAccessToken()
     6 {
     7     string token = string.Empty;
     8     try
     9     {
    10         # 微信小程序接口
    11         string wechatapi = ConfigurationManager.AppSettings["wechatapi"].ToString();
    12         string appID = ConfigurationManager.AppSettings["AppID"].ToString();
    13         string appSecret = ConfigurationManager.AppSettings["AppSecret"].ToString();
    14         //获取微信token
    15         string token_url = "cgi-bin/token?grant_type=client_credential&appid=" + appID + "&secret=" + appSecret;
    16 
    17         var operateResult = LzWebAPICaller.Get<obxxxxject>(wechatapi token_url).ToString();
    18         HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(token_url);
    19         //请求方式
    20         myRequest.Method = "GET";
    21         HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
    22         StreamReader reader = new StreamReader(myResponse.GetResponseStream() Encoding.UTF8);
    23         string content = reader.ReadToEnd();
    24         myResponse.Close();
    25         reader.Dispose();
    26         javascriptSerializer serializer = new javascriptSerializer();
    27         token = serializer.Deserialize<string>(content);
    28 
    29 
    30     }
    31     catch (Exception ex)
    32     {
    33         token = "";
    34         ExceptionPolicy.HandleException(ex LZExceptionType.System
    35           "获取token失败!源:Lz.Product.LJXQJGF.BLL.Resident.ResidentLogic.GetAccessToken方法出错 ");
    36     }
    37     return token;
    38 }
    有道无术,术尚可求,有术无道,止于术
  • 相关阅读:
    NS2仿真:公交车移动周期模型及性能分析
    oracle 列行转换
    oracle dmp文件导出与导入
    fire workflow总结
    install mysql on centos7
    java反射机构应用
    table行颜色设置
    maven无法下依赖jar文件的解决方案
    windows环境jprofiler配置监控tomcat
    CAS tomcat6搭建
  • 原文地址:https://www.cnblogs.com/qinaqina/p/11610346.html
Copyright © 2011-2022 走看看