1 /// <要約> 2 /// 获取access_tokenは 3 /// </要約> 4 /// <戻る> </戻り> 5 パブリック 静的 文字列GetAccessToken() 6 { 7 列トークン= ストリング.Empty。 8 試みる 9 { 10 #微信小程序接口 11 列 wechatapi = ConfigurationManager.AppSettings [ " wechatapi " ] .ToString(); 12 文字列 appIDが= ConfigurationManager.AppSettings [ "AppIDの" ] .ToString(); 13 列 appSecret = ConfigurationManager.AppSettings [ " AppSecret " ] .ToString(); 14 // 获取微信トークン 15 列 token_url = " CGIビン/トークンgrant_type = client_credential&APPID = " + appIDが+ " &秘密= " + 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リーダー= 新しいStreamReaderを(myResponse.GetResponseStream()Encoding.UTF8)。 23 列コンテンツ= reader.ReadToEnd()。 24 myResponse.Close()。 25 reader.Dispose()。 26 javascriptSerializerシリアライザ= 新しいjavascriptSerializer()。 27 トークン= serializer.Deserialize < ストリング > (コンテンツ)。 28 29 30 } 31は、 キャッチ(例外EX) 32 { 33は =トークン"" ; 34である ExceptionPolicy.HandleException(EX LZExceptionType.System 35 " Lz.Product.LJXQJGF.BLL.Resident.ResidentLogic.GetAccessToken方法エラー:障害のトークンのソースを入手します!" ); 36 } 37 リターントークン; 38です }