Image.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://think.ctolog.com
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/WeChatDeveloper
  12. // +----------------------------------------------------------------------
  13. namespace WeMini;
  14. use WeChat\Contracts\BasicWeChat;
  15. use WeChat\Exceptions\InvalidResponseException;
  16. /**
  17. * 小程序图像处理
  18. * Class Image
  19. * @package WeMini
  20. */
  21. class Image extends BasicWeChat
  22. {
  23. /**
  24. * 本接口提供基于小程序的图片智能裁剪能力
  25. * @param string $img_url 要检测的图片 url,传这个则不用传 img 参数。
  26. * @param string $img form-data 中媒体文件标识,有filename、filelength、content-type等信息,传这个则不用穿 img_url
  27. * @return array
  28. * @throws InvalidResponseException
  29. * @throws \WeChat\Exceptions\LocalCacheException
  30. */
  31. public function aiCrop($img_url, $img)
  32. {
  33. $url = "https://api.weixin.qq.com/cv/img/aicrop?access_token=ACCESS_TOCKEN";
  34. $this->registerApi($url, __FUNCTION__, func_get_args());
  35. return $this->callPostApi($url, ['img_url' => $img_url, 'img' => $img], true);
  36. }
  37. /**
  38. * 本接口提供基于小程序的条码/二维码识别的API
  39. * @param string $img_url 要检测的图片 url,传这个则不用传 img 参数。
  40. * @param string $img form-data 中媒体文件标识,有filename、filelength、content-type等信息,传这个则不用穿 img_url
  41. * @return array
  42. * @throws InvalidResponseException
  43. * @throws \WeChat\Exceptions\LocalCacheException
  44. */
  45. public function scanQRCode($img_url, $img)
  46. {
  47. $url = "https://api.weixin.qq.com/cv/img/qrcode?img_url=ENCODE_URL&access_token=ACCESS_TOCKEN";
  48. $this->registerApi($url, __FUNCTION__, func_get_args());
  49. return $this->callPostApi($url, ['img_url' => $img_url, 'img' => $img], true);
  50. }
  51. /**
  52. * 本接口提供基于小程序的图片高清化能力
  53. * @param string $img_url 要检测的图片 url,传这个则不用传 img 参数
  54. * @param string $img form-data 中媒体文件标识,有filename、filelength、content-type等信息,传这个则不用穿 img_url
  55. * @return array
  56. * @throws InvalidResponseException
  57. * @throws \WeChat\Exceptions\LocalCacheException
  58. */
  59. public function superresolution($img_url, $img)
  60. {
  61. $url = "https://api.weixin.qq.com/cv/img/qrcode?img_url=ENCODE_URL&access_token=ACCESS_TOCKEN";
  62. $this->registerApi($url, __FUNCTION__, func_get_args());
  63. return $this->callPostApi($url, ['img_url' => $img_url, 'img' => $img], true);
  64. }
  65. }