Url.php 1007 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the overtrue/wechat.
  4. *
  5. * (c) overtrue <i@overtrue.me>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. /**
  11. * Url.php.
  12. *
  13. * @author overtrue <i@overtrue.me>
  14. * @copyright 2015 overtrue <i@overtrue.me>
  15. *
  16. * @see https://github.com/overtrue
  17. * @see http://overtrue.me
  18. */
  19. namespace EasyWeChat\Url;
  20. use EasyWeChat\Core\AbstractAPI;
  21. /**
  22. * Class Url.
  23. */
  24. class Url extends AbstractAPI
  25. {
  26. const API_SHORTEN_URL = 'https://api.weixin.qq.com/cgi-bin/shorturl';
  27. /**
  28. * Shorten the url.
  29. *
  30. * @param string $url
  31. *
  32. * @return \EasyWeChat\Support\Collection
  33. */
  34. public function shorten($url)
  35. {
  36. $params = [
  37. 'action' => 'long2short',
  38. 'long_url' => $url,
  39. ];
  40. return $this->parseJSON('json', [self::API_SHORTEN_URL, $params]);
  41. }
  42. }