Security.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/WeChatDeveloper
  12. // +----------------------------------------------------------------------
  13. namespace WeMini;
  14. use WeChat\Contracts\BasicWeChat;
  15. /**
  16. * 小程序内容安全
  17. * Class Security
  18. * @package WeMini
  19. */
  20. class Security extends BasicWeChat
  21. {
  22. /**
  23. * 校验一张图片是否含有违法违规内容
  24. * @param string $media 要检测的图片文件,格式支持PNG、JPEG、JPG、GIF,图片尺寸不超过 750px x 1334px
  25. * @return array
  26. * @throws \WeChat\Exceptions\InvalidResponseException
  27. * @throws \WeChat\Exceptions\LocalCacheException
  28. */
  29. public function imgSecCheck($media)
  30. {
  31. $url = 'https://api.weixin.qq.com/wxa/img_sec_check?access_token=ACCESS_TOKEN';
  32. return $this->callPostApi($url, ['media' => $media], false);
  33. }
  34. /**
  35. * 异步校验图片/音频是否含有违法违规内容
  36. * @param string $media_url
  37. * @param string $media_type
  38. * @return array
  39. * @throws \WeChat\Exceptions\InvalidResponseException
  40. * @throws \WeChat\Exceptions\LocalCacheException
  41. */
  42. public function mediaCheckAsync($media_url, $media_type)
  43. {
  44. $url = 'https://api.weixin.qq.com/wxa/media_check_async?access_token=ACCESS_TOKEN';
  45. return $this->callPostApi($url, ['media_url' => $media_url, 'media_type' => $media_type], true);
  46. }
  47. /**
  48. * 检查一段文本是否含有违法违规内容
  49. * @param string $content
  50. * @return array
  51. * @throws \WeChat\Exceptions\InvalidResponseException
  52. * @throws \WeChat\Exceptions\LocalCacheException
  53. */
  54. public function msgSecCheck($content)
  55. {
  56. $url = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=ACCESS_TOKEN';
  57. return $this->callPostApi($url, ['content' => $content], true);
  58. }
  59. }