Exemple #1
0
        public void OCRFilter()
        {
            var Total     = ConfigurationUtil.TencentOCR_KingKey_Total;   //购买总数
            var Warning   = ConfigurationUtil.TencentOCR_KingKey_Warning; //预警次数
            var RedisKey  = ConfigurationUtil.TencentOCR_KingKey_RedisKey;
            var HashId    = ConfigurationUtil.TencentOCR_KingKey_HashId;
            var WarningHz = ConfigurationUtil.TencentOCR_KingKey_WarningHz;//预警频率

            PooledRedisClientHelper.SetEntryInHashIfNotExists(HashId, RedisKey, "0");
            var OCRUseCount = int.Parse(PooledRedisClientHelper.GetHashField(HashId, RedisKey)); //已用次数
            var Balance     = Total - OCRUseCount;                                               //剩余次数

            if (Balance <= 0)
            {
                Send($@"【余额不足】
 购买的OCR次数不足。
【已用次数】:{OCRUseCount}
【可用次数】:{Balance}
【总购买数】:{Total}");
                throw new Exception("余额不足");
            }

            if (Balance > 0 && Balance <= Warning && Balance % WarningHz == 0)//可用,次数小于预警,1000次提醒一次
            {
                Send($@"【警告】购买的OCR次数预警。
【已用次数】:{OCRUseCount}
【可用次数】:{Balance}
【总购买数】:{Total}");
            }
        }
Exemple #2
0
        public void SetHashIncr(int value)
        {
            var HashId   = "OCR";
            var redisKey = "Kingkey_UseCount";

            try
            {
                PooledRedisClientHelper.SetEntryInHashIfNotExists(HashId, redisKey, "0");
                PooledRedisClientHelper.SetHashIncr(HashId, redisKey, value);
            }
            catch (Exception ex)
            {
                Send($@"【操作Redis失败】 :
【HashId】:【 {HashId} 】
【redisKey】:【 {redisKey} 】
【异常消息】:【 {ex.Message} 】
【堆栈信息】:【 {ex.StackTrace} 】");

                throw new Exception("操作Redis失败");
            }
        }