Skip to content

Commit

Permalink
新增云敏感词 #1
Browse files Browse the repository at this point in the history
  • Loading branch information
TennousuAthena committed May 5, 2020
1 parent 9ee3c80 commit 1110c91
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions danmaku.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

require 'vendor/cos-php-sdk-v5/vendor/autoload.php';
require 'config.php';
require 'vendor/tencentcloud-sdk-php/TCloudAutoLoader.php';

use TencentCloud\Common\Credential;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Cms\V20190321\CmsClient;
use TencentCloud\Cms\V20190321\Models\TextModerationRequest;

//初始化
$cosClient = new Qcloud\Cos\Client(array('region' => $region,
Expand All @@ -10,7 +18,38 @@
'secretKey' => $secret_key)));

//敏感词
function aword($str){
function aword($str, $cms=false){
if(!$str){
return false;
}
if($cms){
try {
$cred = new Credential($secret_id, $secret_key);
$httpProfile = new HttpProfile();
$httpProfile->setEndpoint("cms.tencentcloudapi.com");

$clientProfile = new ClientProfile();
$clientProfile->setHttpProfile($httpProfile);
$client = new CmsClient($cred, "ap-guangzhou", $clientProfile);

$req = new TextModerationRequest();

$params = json_encode(["Content"=>base64_encode($str)]);
// var_dump($params);
$req->fromJsonString($params);


$resp = $client->TextModeration($req);

$result = json_decode($resp->toJsonString());
var_dump($result);
}
catch(TencentCloudSDKException $e) {
echo $e;
}
if($result->Data->EvilFlag)
return true;
}
$list = require("aword.php");
for ($i=0; $i<count($list); $i++ ){
$content = substr_count($str, base64_decode($list[$i]));
Expand Down Expand Up @@ -83,8 +122,10 @@ function main_handler($event, $context) {
$danmakuContent = file_get_contents($danmakuFile);
var_dump($danmakuContent);
$key = "tmp/".$body->id.".json";
$reqid = (array)$event['headers'];
$reqid = $reqid['x-api-requestid'];
$danmaku = ["code"=>0, "data"=>[[
$body->time, $body->type, $body->color, md5(time()), $body->text
$body->time, $body->type, $body->color, $reqid, $body->text
]]]; //随便生成一个
if(!$danmakuContent){
//创建临时文件
Expand Down

0 comments on commit 1110c91

Please sign in to comment.