作者 zhl

去AI痕迹service

  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: zhl
  5 + * Date: 2025/5/20
  6 + * Time: 14:49
  7 + */
  8 +namespace App\Services;
  9 +
  10 +use Illuminate\Support\Facades\Http;
  11 +
  12 +/**
  13 + * AI去痕迹
  14 + * Class HumanizeAiTextService
  15 + * @package App\Services
  16 + */
  17 +class HumanizeAiTextService
  18 +{
  19 + /**
  20 + * 封装接口地址
  21 + */
  22 + const CMER_API = 'https://api.cmer.com/';
  23 +
  24 +
  25 + const DRIVER_HUMANIZE = 'humanize'; //3.9号停用 https://rapidapi.com/firdavscoder1/api/humanize1/playground/apiendpoint_4bdba3d9-c66a-4e3d-b1e9-ff307da08e96
  26 + const DRIVER_HUMANIZE_AI_TEXT = 'humanize-ai-text';
  27 +
  28 +
  29 +#=======================================================================================================================
  30 +#== AI生成内容 去除AI痕迹 ==
  31 +#== https://rapidapi.com/bilgisamapi-bilgisamapi-default/api/ai-content-detection-ai-detector-humanize-ai-text ==
  32 +#== https://rapidapi.com/firdavscoder1/api/humanize1/playground/apiendpoint_4bdba3d9-c66a-4e3d-b1e9-ff307da08e96 ==
  33 +#=======================================================================================================================
  34 +
  35 + /**
  36 + * 去AI痕迹 header
  37 + * @param $driver
  38 + * @return array
  39 + */
  40 + public function humanizeHeader($driver)
  41 + {
  42 + return [
  43 + 'apikey' => 'kWd7wQbEPUF0fr17dnt5NQLazfv44O9T',
  44 + 'X-CmerApi-Host' => $driver . '.p.cmer.com',
  45 + 'Content-Type' => 'application/json',
  46 + ];
  47 + }
  48 +
  49 + /**
  50 + * 去AI痕迹提交
  51 + * FIXME humanize:返回请求ID:request_id, 需要异步获取结果
  52 + * @param string $text
  53 + * @param string $lang
  54 + * @return array|mixed
  55 + */
  56 + public function humanizer($text, $lang)
  57 + {
  58 + $driver = env('HUMANIZE_AI_TEXT_DRIVER');
  59 + switch ($driver){
  60 + case self::DRIVER_HUMANIZE:
  61 + $action = 'humainzer/';
  62 + $readilibty = 'Marketing';
  63 + $mode = 'ENHANCED';
  64 + $params = compact('text', 'readilibty', 'mode');
  65 + $result = Http::withoutVerifying()->withHeaders($this->humanizeHeader($driver))->asForm()->post(self::CMER_API . $action, $params)->json();
  66 + break;
  67 + case self::DRIVER_HUMANIZE_AI_TEXT:
  68 + $action = 'humanizeContent?noqueue=1&language=' . $lang;
  69 + $params = compact('text');
  70 + $result = Http::withoutVerifying()->withHeaders($this->humanizeHeader($driver))->post(self::CMER_API . $action, $params)->json();
  71 + break;
  72 + default:
  73 + $result = [];
  74 + break;
  75 +
  76 + }
  77 + return $result;
  78 + }
  79 +
  80 + /**
  81 + * 去AI痕迹结果
  82 + * FIXME humanize:异步获取结果
  83 + * @param $request_id
  84 + * @return \Illuminate\Http\Client\Response
  85 + */
  86 + public function humanizerResult($request_id)
  87 + {
  88 + $action = 'result/';
  89 + $params = compact('request_id');
  90 + return Http::withoutVerifying()->withHeaders($this->humanizeHeader(self::DRIVER_HUMANIZE))->asForm()->post(self::CMER_API . $action, $params);
  91 + }
  92 +}