Security.php 2.5 KB

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