1234567891011121314151617181920212223242526272829303132 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Bear
- * Date: 2019/12/12
- * Time: 下午3:37
- */
- namespace app;
- class Limit
- {
- public static function checkLimit()
- {
- $uri = $_SERVER['REQUEST_URI'] ?? '';
- if (preg_match('/\\/api\\/wechat\\/mpapi\\/appid\\/(\w+)/', $uri, $match)) {
- $appid = $match[1];
- $cachefile = sys_get_temp_dir() . '/TPL_CALLBACK_' . $appid;
- if (file_exists($cachefile)) {
- $content = trim(file_get_contents($cachefile));
- if (time() - (int)$content < 10) {
- echo json_encode(['err' => 1, 'msg' => 'appid limited']);
- exit;
- } else {
- @unlink($cachefile);
- }
- }
- }
- }
- }
- Limit::checkLimit();
|