PayWait.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. * $arguments 第一个参数默认$uid
  18. */
  19. public function __callStatic($name, $arguments)
  20. {
  21. if (!self::$_instatnce) {
  22. self::$_instatnce = new PayWait($arguments[0]);
  23. }
  24. array_shift($arguments);
  25. self::$_instatnce->$name(...$arguments);
  26. }
  27. public function __construct(int $uid)
  28. {
  29. $this->uid = $uid;
  30. }
  31. /**
  32. * 获取支付跳转地址
  33. * @param string $url 前端传入的阅读器地址
  34. */
  35. protected function getReaderWaitUrl(string $url)
  36. {
  37. if (strpos($url, '/reader') !== false) {
  38. preg_match('/bid=(\w+)/', $url, $matchs);
  39. $bid = Hashids::decode($matchs[1])[0];
  40. $record = ReadRecordService::getRecordByUidBid($this->uid, $bid);
  41. if ($record) {
  42. $cid = explode('_', $record)[0];
  43. $url = preg_replace('/cid=(\d+)/', 'cid=' . $cid, $url);
  44. } else {
  45. $url = preg_replace(['/bid=(\w+)/', '/\/reader\?/'], ['', '/catalog?id=' . $matchs[1] . '&'], $url);
  46. }
  47. Log::info('reader_url :' . $url);
  48. }
  49. return $url;
  50. }
  51. }