コード例 #1
0
ファイル: JSSDK.cs プロジェクト: FuChuan7/WeiXin-ASP.NET-MVC3
        /// <summary>
        /// 获取ApiTicket
        /// </summary>
        /// <returns>ApiTicket</returns>
        private string GetJsApiTicket(AccessToken accesstoken)
        {
            var ticket = this._cache.GetCache(CACHE_TICKET_KEY);
            if (ticket != null)
                return ticket.ToString();
            try
            {
                string result = HttpGet(string.Format(URL_FORMAT_TICKET, accesstoken.access_token));
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                Dictionary<string, object> jsonObj = serializer.Deserialize<dynamic>(result);
                if (jsonObj.ContainsKey("ticket"))
                {
                    ticket = jsonObj["ticket"].ToString();
                    this._cache.SetCache(CACHE_TICKET_KEY, ticket.ToString(), 7000);
                }
                else
                {
                    //为了程序正常运行,不抛出错误,可以记录日志
                    ticket = jsonObj["errmsg"];
                }
            }
            catch
            {
                //为了程序正常运行,不抛出错误,可以记录日志
                ticket = "there_is_an_error_when_getting_apiticket";
            }

            return ticket.ToString();
        }
コード例 #2
0
 public String CreateMenu(AccessToken AccessToken)
 {
     String url = " https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + AccessToken.access_token;
     String menuData = ReadMenuFile("menu.txt");
     Console.WriteLine(menuData);
     RequestSimulator request = new RequestSimulator();
     return request.Post(url,menuData);
 }