|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: zhl
|
|
|
|
* Date: 2025/5/20
|
|
|
|
* Time: 14:49
|
|
|
|
*/
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AI去痕迹
|
|
|
|
* Class HumanizeAiTextService
|
|
|
|
* @package App\Services
|
|
|
|
*/
|
|
|
|
class HumanizeAiTextService
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 封装接口地址
|
|
|
|
*/
|
|
|
|
const CMER_API = 'https://api.cmer.com/';
|
|
|
|
|
|
|
|
|
|
|
|
const DRIVER_HUMANIZE = 'humanize'; //3.9号停用 https://rapidapi.com/firdavscoder1/api/humanize1/playground/apiendpoint_4bdba3d9-c66a-4e3d-b1e9-ff307da08e96
|
|
|
|
const DRIVER_HUMANIZE_AI_TEXT = 'humanize-ai-text';
|
|
|
|
|
|
|
|
|
|
|
|
#=======================================================================================================================
|
|
|
|
#== AI生成内容 去除AI痕迹 ==
|
|
|
|
#== https://rapidapi.com/bilgisamapi-bilgisamapi-default/api/ai-content-detection-ai-detector-humanize-ai-text ==
|
|
|
|
#== https://rapidapi.com/firdavscoder1/api/humanize1/playground/apiendpoint_4bdba3d9-c66a-4e3d-b1e9-ff307da08e96 ==
|
|
|
|
#=======================================================================================================================
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 去AI痕迹 header
|
|
|
|
* @param $driver
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function humanizeHeader($driver)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'apikey' => 'kWd7wQbEPUF0fr17dnt5NQLazfv44O9T',
|
|
|
|
'X-CmerApi-Host' => $driver . '.p.cmer.com',
|
|
|
|
'Content-Type' => 'application/json',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 去AI痕迹提交
|
|
|
|
* FIXME humanize:返回请求ID:request_id, 需要异步获取结果
|
|
|
|
* @param string $text
|
|
|
|
* @param string $lang
|
|
|
|
* @return array|mixed
|
|
|
|
*/
|
|
|
|
public function humanizer($text, $lang)
|
|
|
|
{
|
|
|
|
$driver = env('HUMANIZE_AI_TEXT_DRIVER');
|
|
|
|
switch ($driver){
|
|
|
|
case self::DRIVER_HUMANIZE:
|
|
|
|
$action = 'humainzer/';
|
|
|
|
$readilibty = 'Marketing';
|
|
|
|
$mode = 'ENHANCED';
|
|
|
|
$params = compact('text', 'readilibty', 'mode');
|
|
|
|
$result = Http::withoutVerifying()->withHeaders($this->humanizeHeader($driver))->asForm()->post(self::CMER_API . $action, $params)->json();
|
|
|
|
break;
|
|
|
|
case self::DRIVER_HUMANIZE_AI_TEXT:
|
|
|
|
$action = 'humanizeContent?noqueue=1&language=' . $lang;
|
|
|
|
$params = compact('text');
|
|
|
|
$result = Http::withoutVerifying()->withHeaders($this->humanizeHeader($driver))->post(self::CMER_API . $action, $params)->json();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$result = [];
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 去AI痕迹结果
|
|
|
|
* FIXME humanize:异步获取结果
|
|
|
|
* @param $request_id
|
|
|
|
* @return \Illuminate\Http\Client\Response
|
|
|
|
*/
|
|
|
|
public function humanizerResult($request_id)
|
|
|
|
{
|
|
|
|
$action = 'result/';
|
|
|
|
$params = compact('request_id');
|
|
|
|
return Http::withoutVerifying()->withHeaders($this->humanizeHeader(self::DRIVER_HUMANIZE))->asForm()->post(self::CMER_API . $action, $params);
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|