Security.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 Security
  19. * @package WeMini
  20. */
  21. class Security extends BasicWeChat
  22. {
  23. /**
  24. * 校验一张图片是否含有违法违规内容
  25. * @param string $media 要检测的图片文件,格式支持PNG、JPEG、JPG、GIF,图片尺寸不超过 750px x 1334px
  26. * @return array
  27. * @throws \WeChat\Exceptions\InvalidResponseException
  28. * @throws \WeChat\Exceptions\LocalCacheException
  29. */
  30. public function imgSecCheck($media)
  31. {
  32. $url = 'https://api.weixin.qq.com/wxa/img_sec_check?access_token=ACCESS_TOKEN';
  33. $this->registerApi($url, __FUNCTION__, func_get_args());
  34. return $this->callPostApi($url, ['media' => $media], true);
  35. }
  36. /**
  37. * 异步校验图片/音频是否含有违法违规内容
  38. * @param string $media_url
  39. * @param string $media_type
  40. * @return array
  41. * @throws InvalidResponseException
  42. * @throws \WeChat\Exceptions\LocalCacheException
  43. */
  44. public function mediaCheckAsync($media_url, $media_type)
  45. {
  46. $url = 'https://api.weixin.qq.com/wxa/media_check_async?access_token=ACCESS_TOKEN';
  47. $this->registerApi($url, __FUNCTION__, func_get_args());
  48. return $this->callPostApi($url, ['media_url' => $media_url, 'media_type' => $media_type], true);
  49. }
  50. /**
  51. * 检查一段文本是否含有违法违规内容
  52. * @param string $content
  53. * @return array
  54. * @throws InvalidResponseException
  55. * @throws \WeChat\Exceptions\LocalCacheException
  56. */
  57. public function msgSecCheck($content)
  58. {
  59. $url = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=ACCESS_TOKEN';
  60. $this->registerApi($url, __FUNCTION__, func_get_args());
  61. return $this->callPostApi($url, ['content' => $content], false);
  62. }
  63. }