You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

55 lines
1.2 KiB

  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. * Material.php.
  12. *
  13. * @author allen05ren <allen05ren@outlook.com>
  14. * @copyright 2016 overtrue <i@overtrue.me>
  15. *
  16. * @see https://github.com/overtrue
  17. * @see http://overtrue.me
  18. */
  19. namespace EasyWeChat\ShakeAround;
  20. use EasyWeChat\Core\AbstractAPI;
  21. use EasyWeChat\Core\Exceptions\InvalidArgumentException;
  22. /**
  23. * Class Material.
  24. */
  25. class Material extends AbstractAPI
  26. {
  27. const API_MATERIAL_ADD = 'https://api.weixin.qq.com/shakearound/material/add';
  28. /**
  29. * Upload image material.
  30. *
  31. * @param string $path
  32. * @param string $type
  33. *
  34. * @return string
  35. *
  36. * @throws InvalidArgumentException
  37. */
  38. public function uploadImage($path, $type = 'icon')
  39. {
  40. if (!file_exists($path) || !is_readable($path)) {
  41. throw new InvalidArgumentException("File does not exist, or the file is unreadable: '$path'");
  42. }
  43. $type = strtolower($type);
  44. return $this->parseJSON('upload', [self::API_MATERIAL_ADD, ['media' => $path], [], ['type' => $type]]);
  45. }
  46. }