AipImageCensor.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace addons\cms\library\aip;
  3. /*
  4. * Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. * use this file except in compliance with the License. You may obtain a copy of
  8. * the License at
  9. *
  10. * Http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. * License for the specific language governing permissions and limitations under
  16. * the License.
  17. */
  18. use addons\cms\library\aip\lib\AipBase;
  19. /**
  20. * 黄反识别
  21. */
  22. class AipImageCensor extends AipBase
  23. {
  24. /**
  25. * @var string
  26. */
  27. private $imageCensorUserDefinedUrl = 'https://aip.baidubce.com/rest/2.0/solution/v1/img_censor/v2/user_defined';
  28. /**
  29. * @var string
  30. */
  31. private $textCensorUserDefinedUrl = 'https://aip.baidubce.com/rest/2.0/solution/v1/text_censor/v2/user_defined';
  32. /**
  33. * @param string $image 图像
  34. * @return array
  35. */
  36. public function imageCensorUserDefined($image)
  37. {
  38. $data = array();
  39. $isUrl = substr(trim($image), 0, 4) === 'http';
  40. if (!$isUrl) {
  41. $data['image'] = base64_encode($image);
  42. } else {
  43. $data['imgUrl'] = $image;
  44. }
  45. return $this->request($this->imageCensorUserDefinedUrl, $data);
  46. }
  47. /**
  48. * @param string $text
  49. * @return array
  50. */
  51. public function textCensorUserDefined($text)
  52. {
  53. $data = array();
  54. $data['text'] = $text;
  55. return $this->request($this->textCensorUserDefinedUrl, $data);
  56. }
  57. }