PayWait.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Modules\Trade\Pay;
  3. use App\Modules\User\Services\ReadRecordService;
  4. use Hashids;
  5. use Log;
  6. /**
  7. * 充值等待
  8. *
  9. * @property int $uid
  10. * @method static string getReaderWaitUrl(int $uid, string $url) 获取支付跳转地址
  11. */
  12. class PayWait
  13. {
  14. private $uid;
  15. private static $_instatnce;
  16. /**
  17. *
  18. *@param array $arguments 第一个参数默认$uid
  19. */
  20. public static function __callStatic($name, $arguments)
  21. {
  22. if (!self::$_instatnce) {
  23. self::$_instatnce = new PayWait($arguments[0]);
  24. }
  25. array_shift($arguments);
  26. return self::$_instatnce->$name(...$arguments);
  27. }
  28. public function __construct(int $uid)
  29. {
  30. $this->uid = $uid;
  31. }
  32. /**
  33. * 获取支付跳转地址
  34. * @param string $url 前端传入的阅读器地址
  35. */
  36. protected function getReaderWaitUrl(string $url)
  37. {
  38. if (strpos($url, '/reader') !== false) {
  39. preg_match('/bid=(\w+)/', $url, $matchs);
  40. $bid = Hashids::decode($matchs[1])[0];
  41. $record = ReadRecordService::getRecordByUidBid($this->uid, $bid);
  42. if ($record) {
  43. $cid = explode('_', $record)[0];
  44. $url = preg_replace('/cid=(\d+)/', 'cid=' . $cid, $url);
  45. } else {
  46. $url = preg_replace(['/bid=(\w+)/', '/\/reader\?/'], ['', '/catalog?id=' . $matchs[1] . '&'], $url);
  47. }
  48. Log::info('reader_url :' . $url);
  49. }
  50. return $url;
  51. }
  52. }