|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the overtrue/wechat. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) overtrue <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace EasyWeChat\BasicService\ContentSecurity; |
|
13
|
|
|
|
|
14
|
|
|
use EasyWeChat\Kernel\BaseClient; |
|
15
|
|
|
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class Client. |
|
19
|
|
|
* |
|
20
|
|
|
* @author tianyong90 <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class Client extends BaseClient |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $baseUri = 'https://api.weixin.qq.com/wxa/'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Text content security check. |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $text |
|
33
|
|
|
* |
|
34
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
35
|
|
|
* |
|
36
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
37
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
|
38
|
|
|
*/ |
|
39
|
1 |
|
public function checkText(string $text) |
|
40
|
|
|
{ |
|
41
|
|
|
$params = [ |
|
42
|
1 |
|
'content' => $text, |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
1 |
|
return $this->httpPostJson('msg_sec_check', $params); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Image security check. |
|
50
|
|
|
* |
|
51
|
|
|
* @param string $path |
|
52
|
|
|
* |
|
53
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
54
|
|
|
* |
|
55
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
56
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function checkImage(string $path) |
|
59
|
|
|
{ |
|
60
|
1 |
|
return $this->httpUpload('img_sec_check', ['media' => $path]); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Media security check. |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $mediaUrl |
|
67
|
|
|
* @param string $mediaType |
|
68
|
|
|
* |
|
69
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
70
|
|
|
* |
|
71
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
72
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
|
73
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|
74
|
|
|
*/ |
|
75
|
|
|
public function checkMedia(string $mediaUrl, int $mediaType) |
|
76
|
|
|
{ |
|
77
|
|
|
/* |
|
78
|
|
|
* 1:音频;2:图片 |
|
79
|
|
|
*/ |
|
80
|
|
|
$mediaTypes = [1, 2]; |
|
81
|
|
|
if (!in_array($mediaType, $mediaTypes)) { |
|
82
|
|
|
throw new InvalidArgumentException('media type must be 1 or 2'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$params = [ |
|
86
|
|
|
'media_url' => $mediaUrl, |
|
87
|
|
|
'media_type' => $mediaType, |
|
88
|
|
|
]; |
|
89
|
|
|
|
|
90
|
|
|
return $this->httpPostJson('media_check_async', $params); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|