예제 #1
0
 /**
  * 功能统计总次数增加1
  * @param string $key 功能对应的tag字符值
  * @param string $map 备注
  */
 public function increase($key, $map)
 {
     $now = date('Y-m-d', time());
     try {
         $this->sql->beginTransaction();
         //检查表结构
         $sqlStm = "DESC `{$this->tag}` `{$key}`";
         //若无$key列则修改表结构
         $result = $this->sql->query($sqlStm);
         if ($result == null || count($result->fetchAll(\PDO::FETCH_ASSOC)) == 0) {
             $this->appendCol($key, $map);
         }
         //更新数据
         $sqlStm = "UPDATE `{$this->tag}` SET `{$key}` = `{$key}`+1 WHERE `date` = '{$now}'";
         //更新数据失败,则添加新的行
         if ($this->sql->exec($sqlStm) == 0) {
             $this->appendRow($key, $map, $now);
         }
         //检查数据是否需要更新备注
         $sqlStm = "SELECT `{$key}` FROM `{$this->tag}` WHERE `date` = '{$now}'";
         $result = $this->sql->query($sqlStm)->fetchAll(\PDO::FETCH_ASSOC);
         if (count($result) > 0 && intval($result[0][$key]) == 1) {
             $this->updateCol($key, $map);
         }
         $this->sql->commit();
     } catch (\PDOException $e) {
         $this->sql->rollBack();
         Log::e($e);
     }
 }
예제 #2
0
 private function cleanRetry()
 {
     $max = MAX_CACHE;
     try {
         $result = $this->db->query("SELECT `priority` FROM `{$this->tableRetry}` ORDER BY `priority` DESC LIMIT {$max}, 1");
         $result = $result->fetchAll(\PDO::FETCH_ASSOC);
         if (count($result) == 0) {
             return;
         }
         $maxTime = $result[0]['priority'];
         $this->db->exec("DELETE FROM `{$this->tableRetry}` WHERE `priority` <= {$maxTime}");
         return true;
     } catch (\PDOException $e) {
         Log::e($e);
         return false;
     }
 }
예제 #3
0
파일: Request.php 프로젝트: kavmors/Wlight
            /** 其他类型数据库暂不支持
                case 'others'
                **/
        /** 其他类型数据库暂不支持
            case 'others'
            **/
        default:
            $dbResult = support\DbDeployer::initMysql();
            break;
    }
    if ($dbResult) {
        resetCache();
    }
}
//全脚本结束,日志写入文件
Log::end();
function checkSignature()
{
    $signature = $_GET["signature"];
    $timestamp = $_GET["timestamp"];
    $nonce = $_GET["nonce"];
    $token = TOKEN;
    $tmpArr = array($token, $timestamp, $nonce);
    sort($tmpArr, SORT_STRING);
    $tmpStr = implode($tmpArr);
    $tmpStr = sha1($tmpStr);
    return $tmpStr == $signature;
}
function checkErrorCode($errorCode)
{
    if ($errorCode != 0) {
예제 #4
0
 private function reloadTicket()
 {
     $fp = fopen($this->file, "w");
     if (flock($fp, LOCK_EX)) {
         Log::i('Lock', 'JsapiTicket');
         try {
             $url = $this->url . "?access_token={$this->accessToken}&type=wx_card";
             $httpClient = new HttpClient($url);
             $httpClient->get();
             $stream = $httpClient->jsonToArray();
             if (isset($stream['ticket'])) {
                 //提取参数
                 $jsapi_ticket = $stream['ticket'];
                 $expires_in = $stream['expires_in'];
                 $expires_time = intval(time()) + intval($expires_in) - 60;
                 //60s超时缓冲
                 $file_stream = json_encode(array('expires_time' => $expires_time, 'jsapi_ticket' => $jsapi_ticket));
                 fwrite($fp, "<?php exit; ?>\n");
                 fwrite($fp, $file_stream);
                 Log::i('Unlock', 'JsapiTicket');
                 flock($fp, LOCK_UN);
                 fclose($fp);
                 @chmod($this->file, DEFAULT_PERMISSION);
                 return $jsapi_ticket;
             } else {
                 throw ApiException::throws(ApiException::ERROR_JSON_ERROR_CODE, 'response: ' . $httpClient->getResponse());
             }
         } catch (ApiException $e) {
             Log::i('Unlock', 'JsapiTicket');
             flock($fp, LOCK_UN);
             fclose($fp);
             throw $e;
             return false;
         }
     } else {
         fclose($fp);
         throw ApiException::throws(ApiException::FILE_LOCK_ERROR_CODE);
         return false;
     }
 }
예제 #5
0
 public function action()
 {
     if ($this->postClass == null) {
         return Response::EMPTY_RESPONSE;
     }
     //从排重缓存中获取超时缓存消息
     $retry = 7;
     while ($retry--) {
         $memCache = $this->cacheController->getRetry($this->cacheController->keyRetry($this->postClass));
         if (!empty($memCache)) {
             //返回字串执行结果
             Log::cancel();
             return $memCache;
         } elseif ($memCache === '') {
             //有键无值,首次执行还没结束,直接等待下一次请求
             Log::cancel();
             sleep(1);
         } else {
             break;
         }
     }
     if ($retry <= 0) {
         //超时等待下一次重连
         return '';
     }
     //在排重缓存中记录缓存值,防止第二次请求重新触发
     $this->cacheController->putRetry($this->postClass['CreateTime'], $this->cacheController->keyRetry($this->postClass), '');
     //在所有自动回复前hook
     if ($this->hook) {
         @$this->hook->onPreExecute($this->postClass);
     }
     $target = false;
     //先定空返回值
     $phps = $this->getFromCache();
     //针对有缓存情况执行,若[无缓存]或[缓存无效],返回$target==false
     $target = $this->ergodicPhps($phps);
     //没有缓存或缓存不符合(即旧缓存无效)
     if (empty($target)) {
         $list = $this->getFromList();
         //提取所有php文件
         if (is_array($phps)) {
             //有缓存但缓存无效
             //在所有php文件中删除,避免重复检验
             if (($listKey = array_search($phps[0], $list)) !== false) {
                 unset($list[$listKey]);
             }
         }
         //执行所有遍历
         $target = $this->ergodicPhps($list);
     }
     $this->callMessage($this->postClass);
     $result = $this->invokeTarget($target);
     $target = null;
     //在所有自动回复后hook
     if ($this->hook) {
         @$this->hook->onPostExecute($result);
     }
     //在排重缓存中记录已执行完成的结果值,在下次请求时直接返回
     $this->cacheController->putRetry($this->postClass['CreateTime'], $this->cacheController->keyRetry($this->postClass), $result);
     Log::response($result);
     return $result;
 }