Limit.php 804 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Bear
  5. * Date: 2019/12/12
  6. * Time: 下午3:37
  7. */
  8. namespace app;
  9. class Limit
  10. {
  11. public static function checkLimit()
  12. {
  13. $uri = $_SERVER['REQUEST_URI'] ?? '';
  14. if (preg_match('/\\/api\\/wechat\\/mpapi\\/appid\\/(\w+)/', $uri, $match)) {
  15. $appid = $match[1];
  16. $cachefile = sys_get_temp_dir() . '/TPL_CALLBACK_' . $appid;
  17. if (file_exists($cachefile)) {
  18. $content = trim(file_get_contents($cachefile));
  19. if (time() - (int)$content < 10) {
  20. echo json_encode(['err' => 1, 'msg' => 'appid limited']);
  21. exit;
  22. } else {
  23. @unlink($cachefile);
  24. }
  25. }
  26. }
  27. }
  28. }
  29. Limit::checkLimit();