void ClearQC()
        {
            ClassLoger.Info("ClearQCPicJob.ClearQC", "定时清理图片文件任务启动");

            string key = CacheKey.GetQrCodeKey(DateTime.Now.AddDays(-1));

            if (RedisBase.ContainsKey(key))
            {
                int i = 0;
                while (IsWork)
                {
                    List <string> qcimageList = RedisBase.List_GetList <string>(key, i, 1000);
                    foreach (string pathStr in qcimageList)
                    {
                        try
                        {
                            if (File.Exists(pathStr))
                            {
                                File.Delete(pathStr);
                            }
                        }
                        catch (Exception ex) { }
                    }
                    i++;
                    if (qcimageList == null || qcimageList.Count == 0)
                    {
                        break;
                    }
                }

                RedisBase.List_RemoveAll <string>(key);
            }

            ClassLoger.Info("ClearQCPicJob.ClearQC", "图片文件清理完毕");
        }
Ejemplo n.º 2
0
        // GET api/<controller>
        /// <summary>
        /// 线下客户端获取微信登录二维码
        /// </summary>
        /// <returns></returns>
        public JsonResult <string> Get(string lockCode)
        {
            JsonResult <string> result = new JsonResult <string>();

            result.code = 0;
            result.msg  = "OK";
            string uuid      = Utils.GetWeChatUUID();
            string long_url  = WeChateSiteHelper.getCRContent(uuid);
            string cqContent = WeChatAccessTokenAPI.GetShortURL(long_url);

            if (string.IsNullOrEmpty(cqContent))
            {
                cqContent = long_url;
            }
            string fileName = string.Format("{0}.png", uuid);
            string filePath = FileHelper.GetPicFilePath(fileName);

            if (QrCodeHelper.CreateImgCode(cqContent, filePath))
            {
                result.code      = 1;
                result.Result    = FileHelper.GetPicFileURL(fileName);
                result.ResultMsg = uuid;

                ThreadPool.QueueUserWorkItem(new WaitCallback(p => {
                    //图片记录进缓存,定期清理
                    string key = CacheKey.GetQrCodeKey(DateTime.Now);
                    RedisBase.List_Add <string>(key, filePath);
                    RedisBase.List_SetExpire(key, DateTime.Now.AddDays(2));

                    //记录日志
                    WeChatLogin login = new WeChatLogin();
                    login.State       = 0;
                    login.UUID        = uuid;
                    login.LoginData   = DateTime.Now.ToString("yyyy-MM-dd");
                    login.CreateTime  = DateTime.Now;
                    login.LockCode    = lockCode;
                    SaveWeChatLogin(login);
                }), null);
            }


            return(result);
        }
        public async Task <IHttpActionResult> BindingWeChartCQ()
        {
            JsonResult <string> result = new JsonResult <string>();

            result.code = 0;
            result.msg  = "OK";
            await Task.Run(() => {
                string uuid      = Utils.GetWeChatUUID();
                string long_url  = WeChateSiteHelper.getCRContent(uuid);
                string cqContent = WeChatAccessTokenAPI.GetShortURL(long_url);
                if (string.IsNullOrEmpty(cqContent))
                {
                    cqContent = long_url;
                }
                string fileName = string.Format("{0}.png", uuid);
                string filePath = FileHelper.GetPicFilePath(fileName);
                if (QrCodeHelper.CreateImgCode(cqContent, filePath))
                {
                    result.code      = 1;
                    result.Result    = FileHelper.GetPicFileURL(fileName);
                    result.ResultMsg = uuid;

                    //图片记录进缓存,定期清理
                    string key = CacheKey.GetQrCodeKey(DateTime.Now);
                    RedisBase.List_Add <string>(key, filePath);
                    RedisBase.List_SetExpire(key, DateTime.Now.AddDays(2));

                    ApiUserManager userManager = new ApiUserManager(ActionContext);
                    string bindkey             = string.Format("bind_{0}", uuid);
                    RedisBase.Item_Set(bindkey, userManager.User);
                    RedisBase.ExpireEntryAt(bindkey, DateTime.Now.AddHours(1));
                }
            });

            return(Ok(result));
        }