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 //获取微信token15 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.System35 "获取token失败!源:Lz.Product.LJXQJGF.BLL.ResIDent.ResIDentLogic.GetAccesstoken方法出错 ");36 }37 return token;38 }总结
以上是内存溢出为你收集整理的C# 获取微信小程序access_token全部内容,希望文章能够帮你解决C# 获取微信小程序access_token所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)