예제 #1
0
 /// <summary>
 /// 更新AccessToken
 /// </summary>
 /// <param name="config"></param>
 /// <returns></returns>
 private Config updateAccessToken(Config config, bool force = false)
 {
     lock (obj)
     {
         if (force || config.accessTokenDate == null || config.accessTokenDate < DateTime.Now.AddMinutes(-100))
         {
             string           res = HttpWebResponseUtility.CreateGetHttpResponse(Const.access_token + String.Format("?grant_type=client_credential&appid={0}&secret={1}", config.AppID, config.AppSecret), 5000, null, null);
             AccessTokenModel accessTokenModel = JsonConvert.DeserializeObject <AccessTokenModel>(res);
             if (!accessTokenModel.errcode.HasValue)
             {
                 config.accessToken     = accessTokenModel.access_token;
                 config.accessTokenDate = DateTime.Now;
             }
         }
     }
     return(config);
 }
예제 #2
0
        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <returns></returns>
        public string DeleteMenu(string AppID = "", int count = 3)
        {
            Config config = getConfig(AppID);
            string res    = "";

            do
            {
                try
                {
                    res   = HttpWebResponseUtility.CreateGetHttpResponse(Const.menu_delete + config.accessToken, 5000, null, null);
                    count = 0;
                }
                catch (Exception ex)
                {
                    config = getConfig(AppID, true);
                }
            }while (count-- > 0);
            return(res);
        }
예제 #3
0
        /// <summary>
        /// 创建菜单
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public string CreateMenu(MenuModal menu, string AppID = "", int count = 3)
        {
            Config config = getConfig(AppID);
            string res    = "";

            do
            {
                try
                {
                    res   = HttpWebResponseUtility.CreatePostDataResponse(Const.menu_create + config.accessToken, JsonConvert.SerializeObject(menu));
                    count = 0;
                }
                catch (Exception ex)
                {
                    config = getConfig(AppID, true);
                }
            }while (count-- > 0);
            return(res);
        }
예제 #4
0
        /// <summary>
        /// 发送模板消息
        /// </summary>
        /// <param name="message"></param>
        public ResTemplateMessageModel sendTemplateMessage(object obj, string AppID = "", int count = 3)
        {
            Config config = getConfig(AppID);
            ResTemplateMessageModel templateMessageModel = new ResTemplateMessageModel();
            string res = "";

            do
            {
                try
                {
                    res = HttpWebResponseUtility.CreatePostDataResponse(Const.template_message + config.accessToken, JsonConvert.SerializeObject(obj));
                    templateMessageModel = JsonConvert.DeserializeObject <ResTemplateMessageModel>(res);
                    if (CheckSuccess(templateMessageModel.errcode))
                    {
                        count = 0;
                    }
                }
                catch (Exception)
                {
                    config = getConfig(AppID, true);
                }
            } while (count-- > 0);
            return(templateMessageModel);
        }