Skip to content

Commit ed9feda

Browse files
authored
文本审核 (#215)
* 文本审核
1 parent 3be3deb commit ed9feda

File tree

4 files changed

+354
-1
lines changed

4 files changed

+354
-1
lines changed

sample/detectText.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
require dirname(__FILE__) . '/../vendor/autoload.php';
4+
5+
$secretId = "SECRETID"; //"云 API 密钥 SecretId";
6+
$secretKey = "SECRETKEY"; //"云 API 密钥 SecretKey";
7+
$region = "ap-beijing"; //设置一个默认的存储桶地域
8+
$cosClient = new Qcloud\Cos\Client(
9+
array(
10+
'region' => $region,
11+
'schema' => 'https', //协议头部,默认为http
12+
'credentials'=> array(
13+
'secretId' => $secretId ,
14+
'secretKey' => $secretKey)));
15+
try {
16+
// start --------------- 文本内容审核 ----------------- //
17+
$content = '约炮';
18+
$result = $cosClient->detectText(array(
19+
'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID
20+
'Input' => array(
21+
'Content' => base64_encode($content) // 文本需base64_encode
22+
),
23+
'Conf' => array(
24+
'DetectType' => 'Porn,Terrorism,Politics,Ads',
25+
'BizType' => '',
26+
),
27+
));
28+
// 请求成功
29+
print_r($result);
30+
// end --------------- 文本内容审核 ----------------- //
31+
32+
// start --------------- 存储桶文本文件审核 ----------------- //
33+
$result = $cosClient->detectText(array(
34+
'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID
35+
'Input' => array(
36+
'Object' => 'test01.txt'
37+
),
38+
'Conf' => array(
39+
'DetectType' => 'Porn,Terrorism,Politics,Ads',
40+
'Callback' => 'https://example.callback.com/test/', // 回调URL
41+
'BizType' => '',
42+
),
43+
));
44+
// 请求成功
45+
print_r($result);
46+
// end --------------- 存储桶文本文件审核 ----------------- //
47+
} catch (\Exception $e) {
48+
// 请求失败
49+
echo($e);
50+
}
51+

src/Qcloud/Cos/Client.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
* @method object GetBucketGuetzli (array $arg)
9292
* @method object DeleteBucketGuetzli (array $arg)
9393
* @method object GetObjectSensitiveContentRecognition (array $arg)
94+
* @method object DetectText (array $arg)
9495
*/
9596
class Client extends GuzzleClient {
9697
const VERSION = '2.2.3';
@@ -221,6 +222,7 @@ public function commandToRequestTransformer(CommandInterface $command)
221222
$request = $transformer->md5Transformer($command, $request);
222223
$request = $transformer->specialParamTransformer($command, $request);
223224
$request = $transformer->ciParamTransformer($command, $request);
225+
$request = $transformer->cosDomain2CiTransformer($command, $request);
224226
return $request;
225227
}
226228

src/Qcloud/Cos/CommandToRequestTransformer.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,34 @@ public function ciParamTransformer( CommandInterface $command, $request ) {
216216
return $request;
217217
}
218218

219+
public function cosDomain2CiTransformer($command, $request) {
220+
$action = $command->getName();
221+
if ($action == 'DetectText') {
222+
$bucketname = $command['Bucket'];
223+
$appId = $this->config['appId'];
224+
if ( $appId != null && endWith( $bucketname, '-'.$appId ) == False ) {
225+
$bucketname = $bucketname.'-'.$appId;
226+
}
227+
$command['Bucket'] = $bucketname;
228+
$domain_type = '.ci.';
229+
$origin_host = $bucketname . $domain_type . $this->config['region'] . '.' . $this->config['endpoint'];
230+
$host = $origin_host;
231+
if ( $this->config['ip'] != null ) {
232+
$host = $this->config['ip'];
233+
if ( $this->config['port'] != null ) {
234+
$host = $this->config['ip'] . ':' . $this->config['port'];
235+
}
236+
}
237+
$path = $this->config['schema'].'://'. $host . '/text/auditing';
238+
$uri = new Uri( $path );
239+
$query = $request->getUri()->getQuery();
240+
$uri = $uri->withQuery( $query );
241+
$request = $request->withUri( $uri );
242+
$request = $request->withHeader( 'Host', $origin_host );
243+
}
244+
return $request;
245+
}
246+
219247
public function __destruct() {
220248
}
221249

src/Qcloud/Cos/Service.php

Lines changed: 273 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3443,7 +3443,59 @@ public static function getService() {
34433443
'sentAs' => 'biz-type'
34443444
)
34453445
),
3446-
)
3446+
),
3447+
// 文本审核
3448+
'DetectText' => array(
3449+
'httpMethod' => 'POST',
3450+
'uri' => '/{Bucket}text/auditing',
3451+
'class' => 'Qcloud\\Cos\\Command',
3452+
'responseClass' => 'DetectTextOutput',
3453+
'responseType' => 'model',
3454+
'data' => array(
3455+
'xmlRoot' => array(
3456+
'name' => 'Request',
3457+
),
3458+
),
3459+
'parameters' => array(
3460+
'Bucket' => array(
3461+
'required' => true,
3462+
'type' => 'string',
3463+
'location' => 'uri',
3464+
),
3465+
'Input' => array(
3466+
'location' => 'xml',
3467+
'type' => 'object',
3468+
'properties' => array(
3469+
'Content' => array(
3470+
'type' => 'string',
3471+
'location' => 'xml',
3472+
),
3473+
'Object' => array(
3474+
'type' => 'string',
3475+
'location' => 'xml',
3476+
),
3477+
),
3478+
),
3479+
'Conf' => array(
3480+
'location' => 'xml',
3481+
'type' => 'object',
3482+
'properties' => array(
3483+
'DetectType' => array(
3484+
'type' => 'string',
3485+
'location' => 'xml',
3486+
),
3487+
'Callback' => array(
3488+
'type' => 'string',
3489+
'location' => 'xml',
3490+
),
3491+
'BizType' => array(
3492+
'type' => 'string',
3493+
'location' => 'xml',
3494+
),
3495+
),
3496+
),
3497+
),
3498+
),
34473499
),
34483500
'models' => array(
34493501
'AbortMultipartUploadOutput' => array(
@@ -6198,6 +6250,226 @@ public static function getService() {
61986250
),
61996251
)
62006252
),
6253+
'DetectTextOutput' => array(
6254+
'type' => 'object',
6255+
'additionalProperties' => true,
6256+
'properties' => array(
6257+
'RequestId' => array(
6258+
'type' => 'string',
6259+
'location' => 'header',
6260+
'sentAs' => 'x-ci-request-id',
6261+
),
6262+
'ContentType' => array(
6263+
'type' => 'string',
6264+
'location' => 'header',
6265+
'sentAs' => 'Content-Type',
6266+
),
6267+
'ContentLength' => array(
6268+
'type' => 'numeric',
6269+
'minimum'=> 0,
6270+
'location' => 'header',
6271+
'sentAs' => 'Content-Length',
6272+
),
6273+
'JobsDetail' => array(
6274+
'type' => 'object',
6275+
'location' => 'xml',
6276+
'properties' => array(
6277+
'JobId' => array(
6278+
'type' => 'string',
6279+
),
6280+
'State' => array(
6281+
'type' => 'string',
6282+
),
6283+
'CreationTime' => array(
6284+
'type' => 'string',
6285+
),
6286+
'Content' => array(
6287+
'type' => 'string',
6288+
),
6289+
'Result' => array(
6290+
'type' => 'string',
6291+
),
6292+
'SectionCount' => array(
6293+
'type' => 'string',
6294+
),
6295+
'PornInfo' => array(
6296+
'type' => 'object',
6297+
'location' => 'xml',
6298+
'properties' => array(
6299+
'HitFlag' => array(
6300+
'type' => 'integer',
6301+
),
6302+
'Count' => array(
6303+
'type' => 'integer',
6304+
),
6305+
),
6306+
),
6307+
'TerrorismInfo' => array(
6308+
'type' => 'object',
6309+
'location' => 'xml',
6310+
'properties' => array(
6311+
'HitFlag' => array(
6312+
'type' => 'integer',
6313+
),
6314+
'Count' => array(
6315+
'type' => 'integer',
6316+
),
6317+
),
6318+
),
6319+
'PoliticsInfo' => array(
6320+
'type' => 'object',
6321+
'location' => 'xml',
6322+
'properties' => array(
6323+
'HitFlag' => array(
6324+
'type' => 'integer',
6325+
),
6326+
'Count' => array(
6327+
'type' => 'integer',
6328+
),
6329+
),
6330+
),
6331+
'AdsInfo' => array(
6332+
'type' => 'object',
6333+
'location' => 'xml',
6334+
'properties' => array(
6335+
'HitFlag' => array(
6336+
'type' => 'integer',
6337+
),
6338+
'Count' => array(
6339+
'type' => 'integer',
6340+
),
6341+
),
6342+
),
6343+
'IllegalInfo' => array(
6344+
'type' => 'object',
6345+
'location' => 'xml',
6346+
'properties' => array(
6347+
'HitFlag' => array(
6348+
'type' => 'integer',
6349+
),
6350+
'Count' => array(
6351+
'type' => 'integer',
6352+
),
6353+
),
6354+
),
6355+
'AbuseInfo' => array(
6356+
'type' => 'object',
6357+
'location' => 'xml',
6358+
'properties' => array(
6359+
'HitFlag' => array(
6360+
'type' => 'integer',
6361+
),
6362+
'Count' => array(
6363+
'type' => 'integer',
6364+
),
6365+
),
6366+
),
6367+
'Section' => array(
6368+
'type' => 'array',
6369+
'location' => 'xml',
6370+
'items' => array(
6371+
'type' => 'object',
6372+
'properties' => array(
6373+
'StartByte' => array(
6374+
'type' => 'string',
6375+
),
6376+
'PornInfo' => array(
6377+
'type' => 'object',
6378+
'location' => 'xml',
6379+
'properties' => array(
6380+
'HitFlag' => array(
6381+
'type' => 'integer',
6382+
),
6383+
'Score' => array(
6384+
'type' => 'integer',
6385+
),
6386+
'Keywords' => array(
6387+
'type' => 'string',
6388+
),
6389+
),
6390+
),
6391+
'TerrorismInfo' => array(
6392+
'type' => 'object',
6393+
'location' => 'xml',
6394+
'properties' => array(
6395+
'HitFlag' => array(
6396+
'type' => 'integer',
6397+
),
6398+
'Score' => array(
6399+
'type' => 'integer',
6400+
),
6401+
'Keywords' => array(
6402+
'type' => 'string',
6403+
),
6404+
),
6405+
),
6406+
'PoliticsInfo' => array(
6407+
'type' => 'object',
6408+
'location' => 'xml',
6409+
'properties' => array(
6410+
'HitFlag' => array(
6411+
'type' => 'integer',
6412+
),
6413+
'Score' => array(
6414+
'type' => 'integer',
6415+
),
6416+
'Keywords' => array(
6417+
'type' => 'string',
6418+
),
6419+
),
6420+
),
6421+
'AdsInfo' => array(
6422+
'type' => 'object',
6423+
'location' => 'xml',
6424+
'properties' => array(
6425+
'HitFlag' => array(
6426+
'type' => 'integer',
6427+
),
6428+
'Score' => array(
6429+
'type' => 'integer',
6430+
),
6431+
'Keywords' => array(
6432+
'type' => 'string',
6433+
),
6434+
),
6435+
),
6436+
'IllegalInfo' => array(
6437+
'type' => 'object',
6438+
'location' => 'xml',
6439+
'properties' => array(
6440+
'HitFlag' => array(
6441+
'type' => 'integer',
6442+
),
6443+
'Score' => array(
6444+
'type' => 'integer',
6445+
),
6446+
'Keywords' => array(
6447+
'type' => 'string',
6448+
),
6449+
),
6450+
),
6451+
'AbuseInfo' => array(
6452+
'type' => 'object',
6453+
'location' => 'xml',
6454+
'properties' => array(
6455+
'HitFlag' => array(
6456+
'type' => 'integer',
6457+
),
6458+
'Score' => array(
6459+
'type' => 'integer',
6460+
),
6461+
'Keywords' => array(
6462+
'type' => 'string',
6463+
),
6464+
),
6465+
),
6466+
),
6467+
),
6468+
),
6469+
),
6470+
),
6471+
),
6472+
),
62016473
)
62026474
);
62036475
}

0 commit comments

Comments
 (0)