interceptor.php 975 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace refill;
  3. use mtopcard;
  4. class interceptor
  5. {
  6. private $mTurns;
  7. public function __construct()
  8. {
  9. $this->mTurns = [];
  10. }
  11. public function load()
  12. {
  13. $intercept = rkcache('refill-intercept');
  14. $this->mTurns = unserialize($intercept) ?? [];
  15. }
  16. public function isIntercept($quality,$card_type,$region)
  17. {
  18. $key = "{$quality}-{$card_type}";
  19. if(!empty($this->mTurns) && array_key_exists($key,$this->mTurns))
  20. {
  21. //数据中存储的值,0 为拦截,1为打开
  22. $turns = $this->mTurns[$key];
  23. if($turns[-1] === 0) { //key = -1,表示全国.
  24. return true;
  25. }
  26. elseif(array_key_exists($region,mtopcard\ProvinceList) && $turns[$region] === 0) {
  27. return true;
  28. }
  29. else {
  30. return false;
  31. }
  32. }
  33. else {
  34. return false;
  35. }
  36. }
  37. }