作者 李小龙

询盘文案接口

... ... @@ -10,6 +10,7 @@
use App\Http\Controllers\Controller;
use App\Models\SyncSubmitTask\SyncSubmitTask;
use App\Models\WebSetting\WebSetting;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
... ... @@ -27,6 +28,7 @@ class NoticeController extends Controller
const SUCCESS = 200;
const ERROR = 400;
const SERVERERROR = 500;
const FORBBIDEN = 401;
const TYPEVISIT = "visit";
const TYPEINQUIRY = "inquiry";
const TRAFFICZERO = 0;
... ... @@ -251,6 +253,72 @@ public function websiteHtml(Request $request)
}
/**
* 文案
* @param Request $request
*/
public function getRandInquiryText(Request $request){
//IP限流+验证参数
$this->limitIp($request);
try {
$requestUrl = "https://fob.ai.cc/api/get_inquiry_text";
$resStr = $this->httpGet($requestUrl);
} catch (\Exception $e) {
$resStr = $e->getMessage();
}
$this->response("ok",self::SUCCESS,$resStr);
return;
}
/**
* @param $url
* @return bool|string
*/
public function httpGet($url){
$ch1 = curl_init();
$timeout = 0;
curl_setopt($ch1, CURLOPT_URL, $url);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_ENCODING, '');
curl_setopt($ch1, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch1, CURLOPT_HTTPHEADER, array());
curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch1, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
$access_txt = curl_exec($ch1);
curl_close($ch1);
return $access_txt;
}
/**
* IP限流
* @param $request
*/
public function limitIp($request)
{
//同一ip 2秒内超过6次 限制1分钟
$ip = $request->ip();
$ip_limit_key = 'ip_limit_' . $ip;
$num_limit_key = 'num_limit_' . $ip;
if (Cache::has($ip_limit_key)) {
$this->response("error", self::FORBBIDEN, "请求频繁,请稍后再试");
}
if (Cache::has($num_limit_key)) {
$count = Cache::get($num_limit_key);
if ($count >= 6) {
Cache::put($ip_limit_key, 1, 60);
$this->response("error", self::FORBBIDEN, "请求频繁,请稍后再试");
}
Cache::increment($num_limit_key);
} else {
Cache::put($num_limit_key, 1, 2);
}
}
/**
* 网站html解压
* @param $zip_count
* @param $domain
... ...
... ... @@ -30,5 +30,7 @@
Route::any('/upload_amp_verify_file',[NoticeController::class, 'uploadAmpVerifyFile']);
//网站html处理
Route::any('/website_html_handle',[NoticeController::class, 'websiteHtml']);
//询盘文案
Route::any('/Hjoh59552',[NoticeController::class,'getRandInquiryText']);
});
... ...