作者 赵彬吉
<?php
/**
* @remark :
* @name :AiBlogTask.php
* @author :lyh
* @method :post
* @time :2025/2/14 11:14
*/
namespace App\Console\Commands\AiBlog;
use App\Models\Ai\AiBlog;
use App\Models\Project\ProjectAiSetting;
use App\Services\AiBlogService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use App\Models\Project\AiBlogTask as AiBlogTaskModel;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use function Symfony\Component\String\s;
class AiBlogTask extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'save_ai_blog';
/**
* The console command description.
*
* @var string
*/
protected $description = '查询ai_blog是否已经生成';
public function handle(){
$aiBlogTaskModel = new AiBlogTaskModel();
while (true){
$info = $aiBlogTaskModel->where('status',1)->orderBy('id','asc')->first();
if($info === false){
sleep(20);
continue;
}
$info = $info->toArray();
echo '开始->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
//获取配置
$aiSettingInfo = $this->getSetting($info['project_id']);
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
$aiBlogService->key = $aiSettingInfo['key'];
$aiBlogService->task_id = $info['task_id'];
$result = $aiBlogService->getDetail();
if($result['status'] != 200){
sleep(10);
continue;
}
//修改任务状态
$aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]);
//保存当前项目ai_blog数据
ProjectServer::useProject($info['project_id']);
$aiBlogModel = new AiBlog();
$aiBlogModel->edit(['new_title'=>$result['data']['title'] ?? '','text'=>$result['data']['text'] ?? '','status'=>2],['task_id'=>$info['task_id']]);
DB::disconnect('custom_mysql');
echo '结束->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
}
return true;
}
/**
* @remark :获取项目配置
* @name :getSetting
* @author :lyh
* @method :post
* @time :2025/2/14 11:27
*/
public function getSetting($project_id){
$ai_cache = Cache::get('ai_blog_'.$project_id);
if($ai_cache){
return $ai_cache;
}
$projectAiSettingModel = new ProjectAiSetting();
$aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
Cache::put('ai_blog_'.$project_id,$aiSettingInfo,3600);
return $aiSettingInfo;
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2025/2/13
* Time: 16:45
*/
namespace App\Console\Commands\Inquiry;
use App\Helper\Translate;
use App\Models\Inquiry\InquiryInfo;
use App\Services\InquiryRelayService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class SyncInquiryRelay extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sync_inquiry_relay';
/**
* The console command description.
*
* @var string
*/
protected $description = '同步询盘信息:站群询盘,';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
public function handle()
{
$this->getInquiryForm();
$this->getInquirySzcm();
}
/**
* 获取表单系统中询盘信息
* message_sign唯一值:md5(name+email+phone+ip+time)
*/
public function getInquiryForm()
{
$service = new InquiryRelayService();
$result = $service->getInquiryRelay();
if (isset($result['status']) && $result['status'] == 200) {
$data = $result['data'] ?? [];
foreach ($data as $item) {
$this->saveDate($item, $item['source_type']);
}
}
}
/**
* 获取秋哥asp采集询盘信息
* type固定4
* message_sign唯一值:md5(name+email+phone+ip+time)
* 先查数据库最大origin_key,再获取数据
*/
public function getInquirySzcm()
{
$max_origin_key = InquiryInfo::where('type', 4)->orderBy('origin_key', 'desc')->value('origin_key');
if ($max_origin_key) {
$start_id = $max_origin_key + 1;
} else {
$start_id = 65029;
}
$service = new InquiryRelayService();
while ($start_id > 0) {
$result = $service->getInquirySzcm($start_id);
if ($result) {
$this->saveDate($result, 4);
$start_id += 1;
} else {
$start_id = 0;
}
}
}
public function saveDate($data, $type)
{
$model = new InquiryInfo();
$message_sign = md5($data['name'] . $data['email'] . $data['phone'] . $data['ip'] . $data['time']);
$inquiry_info = $model->where('message_sign', $message_sign)->first();
if (!$inquiry_info) {
//没有IP,根据submit_country获取
if (empty($data['ip']) && isset($data['submit_country']) && $data['submit_country']) {
$chinese_name = DB::table('gl_world_country_city')->where('pid', 0)->where('iso2', $data['submit_country'])->value('chinese_name');
$data['ip'] = $this->getIpData($chinese_name);
}
//获取country
$country = '';
if ($data['ip']) {
$country = file_get_contents("http://ip.globalso.com?ip=" . $data['ip']);
}
//翻译message
$message_cn = '';
$re_message_trans = Translate::translate($data['message'], 'zh');
if (isset($re_message_trans[0]['code']) && $re_message_trans[0]['code'] == 200) {
$message_cn = $re_message_trans[0]['texts'];
}
//获取页面上title和keywords
$html = curl_c($data['refer'], false);
if (empty($data['title'])) {
preg_match_all('/<title>([\w\W]*?)<\/title>/', $html, $matches);
if (!empty($matches[1])) {
$data['title'] = substr($matches[1][0], 0, 255);
}
}
$keywords = '';
preg_match_all('/<meta\s+[^>]*?name=[\'|\"]keywords[\'|\"]\s+[^>]*?content=[\'|\"]([\w\W]*?)[\'|\"]/', $html, $matches);
if (!empty($matches[1])) {
$keywords = substr($matches[1][0], 0, 255);
}
if (empty($data['origin_key'])) {
$data['origin_key'] = 0;
}
if (empty($data['image'])) {
$data['image'] = '';
}
$model->createInquiry($data['name'], $data['phone'], $data['email'], $data['ip'], $country, $data['message'], $message_cn, $type, $data['time'], $data['refer'], $data['title'], $keywords, $message_sign, $data['origin_key'], $data['image']);
}
}
/**
* 获取国家随机ip
* @param $country_name
* @return mixed|string
* @author Akun
* @date 2025/02/14 14:19
*/
public function getIpData($country_name)
{
// 有国家 通过国家查询, 如果没有获取到就随机获取
$where = [];
$country_name && $where['ip_area'] = $country_name;
$ip = DB::table('gl_xunpan_ipdata')->where($where)->inRandomOrder()->value('ip');
if (empty($ip_data)) {
$ip = DB::table('gl_xunpan_ipdata')->inRandomOrder()->value('ip');
}
return $ip;
}
}
... ...
... ... @@ -2,9 +2,14 @@
namespace App\Http\Controllers\Bside\Ai;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Ai\AiBlogLogic;
use App\Http\Requests\Bside\Ai\AiBlogRequest;
use App\Models\Ai\AiBlog;
use App\Services\AiBlogService;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
class AiBlogController extends BaseController
{
... ... @@ -20,4 +25,36 @@ class AiBlogController extends BaseController
$aiBlogLogic->blogSave();
$this->response('success');
}
/**
* @remark :获取ai博客列表
* @name :getAiBlog
* @author :lyh
* @method :post
* @time :2025/2/14 13:59
*/
public function getAiBlog(AiBlog $aiBlog){
$lists = $aiBlog->lists($this->map,$this->page,$this->row,'id',['id','new_title','task_id','status','created_at','updated_at']);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :发布任务
* @name :sendTask
* @author :lyh
* @method :post
* @time :2025/2/14 10:25
*/
public function sendTask(AiBlogLogic $aiBlogLogic){
$this->request->validate([
'keyword'=>['required'],
'type'=>['required']
],[
'keyword.required' => '关键字不能为空',
'type.required' => '场景不能为空',
]);
//获取当前项目的ai_blog设置
$result = $aiBlogLogic->sendTask();
$this->response('success',Code::SUCCESS,$result);
}
}
... ...
... ... @@ -662,7 +662,7 @@ class ProductController extends BaseController
'product_id.required' => 'product_id不能为空',
]);
$productInfo = $product->read(['id' => $this->param['product_id']]);
if (empty($productInfo)) {
if ($productInfo == false) {
$this->fail('请选择有效产品信息!');
}
$productInfo = $this->handleParam($productInfo);
... ...
... ... @@ -12,6 +12,7 @@ namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Helper\PayStripeApi;
use App\Http\Logic\Bside\News\NewsLogic;
use App\Models\Ai\AiBlog;
use App\Models\Channel\Channel;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\CustomModule\CustomModuleContent;
... ... @@ -21,24 +22,38 @@ use App\Models\ExtentModule\ExtensionModuleValue;
use App\Models\Manage\ManageHr;
use App\Models\Project\CountAllProject as AllProject;
use App\Models\Project\Project;
use App\Models\Project\ProjectAiSetting;
use App\Models\RouteMap\RouteMap;
use App\Services\AiBlogService;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
class TestController extends BaseController
{
/**
* @remark :非6.0拉取数据
* @name :NoSixProject
* @remark :创建项目
* @name :createProject
* @author :lyh
* @method :post
* @time :2024/11/11 14:51
* @time :2025/2/13 16:34
*/
public function ceshi(){
$pay = new PayStripeApi();
$data = $pay->createPaymentIntent(5000,'cny');
$this->response('success',Code::SUCCESS,$data);
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = '100008';
$aiBlogService->key = '8a9c925bdcca';
$result = $aiBlogService->createTask('apple');
if($result['status'] == 200){
$param = [
'keywords'=>'apple',
'status'=>$result['data']['status'],
'task_id'=>$result['data']['task_id'],
'project_id'=>1,
];
ProjectServer::useProject(1);
$aiBlogModel = new AiBlog();
$aiBlogModel->add($param);
DB::disconnect('custom_mysql');
}
$this->response('success',Code::SUCCESS,$param);
}
}
... ...
... ... @@ -30,6 +30,7 @@ use App\Models\Project\InquiryFilterConfig;
use App\Models\Project\MinorLanguages;
use App\Models\Project\Payment;
use App\Models\Project\Project;
use App\Models\Project\ProjectAiSetting;
use App\Models\Project\ProjectKeyword;
use App\Models\Project\ProjectRenew;
use App\Models\Project\WebTrafficConfig;
... ... @@ -43,6 +44,7 @@ use App\Models\User\ProjectMenu;
use App\Models\User\ProjectRole;
use App\Models\User\User as UserModel;
use App\Models\WebSetting\WebLanguage;
use App\Services\AiBlogService;
use App\Services\ProjectServer;
use App\Services\SyncService;
use App\Utils\LogUtils;
... ... @@ -158,6 +160,8 @@ class ProjectLogic extends BaseLogic
$this->setServers($this->param['serve_id'],$this->param['id']);
//保存项目信息
$this->saveProject($this->param);
//ai_blog
$this->setAiBlog($this->param['id'],$this->param['main_lang_id'],$this->param['is_ai_blog'],$this->param['title']);
//保存建站部署信息
$this->saveProjectDeployBuild($this->param['deploy_build']);
//保存付费信息
... ... @@ -184,6 +188,59 @@ class ProjectLogic extends BaseLogic
}
/**
* @remark :开启AI博客后
* @name :setAiBlog
* @author :lyh
* @method :post
* @time :2025/2/13 16:02
*/
public function setAiBlog($project_id,$main_lang_id,$is_ai_blog,$title){
if(empty($main_lang_id) || empty($is_ai_blog)){
return true;
}
$projectModel = new Project();
$projectInfo = $projectModel->read(['id'=>$project_id],['is_ai_blog','main_lang_id']);
//获取项目主语种
$languageModel = new WebLanguage();
$languageInfo = $languageModel->read(['id'=>$main_lang_id],['short']);
if($languageInfo == false){
return true;
}
$aiSettingModel = new ProjectAiSetting();
$aiSettingInfo = $aiSettingModel->read(['project_id'=>$project_id]);
if($aiSettingInfo === false){
$aiBlogService = new AiBlogService();
$result = $aiBlogService->createProject($title,$languageInfo['short'],$projectInfo['company']);
if($result['status'] == 200){
//查看当前项目是否已有记录
$resData = [
'project_id'=>$project_id,
'mch_id'=>$result['data']['mch_id'],
'key'=>$result['data']['key'],
];
$aiSettingModel->add($resData);
}
}else{
//有信息更新
if(($projectInfo['title'] != $title) || ($projectInfo['main_lang_id'] != $main_lang_id)){
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
$aiBlogService->key = $aiSettingInfo['key'];
$result = $aiBlogService->updatedProject($title,$languageInfo['short']);
if($result['status'] == 200){
$resData = [
'mch_id'=>$result['data']['mch_id'],
'key'=>$result['data']['key'],
];
$aiSettingModel = new ProjectAiSetting();
$aiSettingModel->edit($resData,['project_id'=>$project_id]);
}
}
}
return true;
}
/**
* @remark :选择服务器后双向绑定
* @name :setServers
* @author :lyh
... ...
... ... @@ -4,6 +4,10 @@ namespace App\Http\Logic\Bside\Ai;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Ai\AiBlog;
use App\Models\Project\AiBlogTask;
use App\Models\Project\Project;
use App\Models\Project\ProjectAiSetting;
use App\Services\AiBlogService;
class AiBlogLogic extends BaseLogic
{
... ... @@ -29,4 +33,35 @@ class AiBlogLogic extends BaseLogic
}
return $this->success();
}
/**
* @remark :发布任务
* @name :sendTask
* @author :lyh
* @method :post
* @time :2025/2/14 10:28
*/
public function sendTask(){
$projectAiSettingModel = new ProjectAiSetting();
$aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$this->user['project_id']]);
if($aiSettingInfo === false){
$this->fail('请先联系管理员开启Ai博客');
}
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
$aiBlogService->key = $aiSettingInfo['key'];
$result = $aiBlogService->createTask($this->param['keyword'],$this->param['type']);
if($result['status'] == 200){
try {
$aiBlogTaskModel = new AiBlogTask();
$aiBlogTaskModel->addReturnId(['project_id'=>$this->user['project_id'],'task_id'=>$result['data']['task_id'],'status'=>$result['data']['status']]);
$aiBlogModel = new AiBlog();
$aiBlogModel->addReturnId(['keyword'=>$this->param['keyword'], 'status'=>$result['data']['status'], 'task_id'=>$result['data']['task_id'],'project_id'=>$this->user['project_id'],
]);
}catch (\Exception $e){
$this->fail('请求ai_blog失败,请联系管理员');
}
}
return $this->success();
}
}
... ...
... ... @@ -34,6 +34,9 @@ class AiCommandLogic extends BaseLogic
if(strpos($prompt, '{keyword}') !== false) {
$prompt = str_replace('{keyword}', $this->param['keywords'], $prompt);
}
if(strpos($prompt, '{topic}') !== false) {
$prompt = str_replace('{topic}', $this->param['keywords'], $prompt);
}
if(strpos($prompt, '{company introduction}') !== false) {
$company_introduction = $this->getDeployOptimize('company_en_description');
$prompt = str_replace('{company introduction}', $company_introduction, $prompt);
... ...
... ... @@ -46,10 +46,10 @@ class CustomTemplateLogic extends BaseLogic
*/
public function customTemplateInfo(){
$info = $this->model->read(['id'=>$this->param['id']]);
$info['image'] = getImageUrl($info['image'],$this->user['storage_type'],$this->user['project_location']);
if($info === false){
$this->fail('当前数据不存在');
}
$info['image'] = getImageUrl($info['image'],$this->user['storage_type'],$this->user['project_location']);
if($info['is_visualization'] == 0 || $info['is_visualization'] == 1){
$template_id = $this->getTemplateId();
$html = $this->getTemplateComHtml($info['html'],$info['html_style'],$template_id);
... ...
... ... @@ -12,6 +12,12 @@ use App\Models\Base;
*/
class InquiryInfo extends Base
{
/**
* @var string 数据表
*/
protected $table = 'gl_inquiry_info';
// TODO 之前的状态, 留下可以找到之前的程序
const STATUS_ZERO = 0;//未转发
const STATUS_ONE = 1;//无效
... ... @@ -21,5 +27,87 @@ class InquiryInfo extends Base
const STATUS_FOUR = 4;//延时转发中
protected $table = 'gl_inquiry_info';
const STATUS_INIT = 0;
const STATUS_FINISH = 1;
const STATUS_INVALID = 2;
const STATUS_FAIL = 9;
const TYPE_SITE_GROUP = 1;
const TYPE_ADS = 2;
const TYPE_AI_SITE_GROUP = 3;
const TYPE_SPIDER = 4;
/**
* 状态映射
* @return array
*/
public function statusMap()
{
return [
self::STATUS_INIT => '未处理',
self::STATUS_FINISH => '已处理',
self::STATUS_INVALID => '无效数据',
self::STATUS_FAIL => '失败数据',
];
}
/**
* 类型映射
* @return array
*/
public function typeMap()
{
return [
self::TYPE_SITE_GROUP => '站群询盘',
self::TYPE_ADS => 'ads采集站询盘',
self::TYPE_AI_SITE_GROUP => 'AI站群询盘',
self::TYPE_SPIDER => '蜘蛛询盘',
];
}
/**
* 创建新盘信息
* @param $name
* @param $phone
* @param $email
* @param $ip
* @param $country
* @param $message
* @param $message_cn
* @param $type
* @param $inquiry_date
* @param $url
* @param $url_title
* @param $url_keyword
* @param $message_sign
* @param $origin_key
* @param string $image
* @return bool
*/
public function createInquiry($name, $phone, $email, $ip, $country, $message, $message_cn, $type, $inquiry_date, $url, $url_title, $url_keyword, $message_sign, $origin_key, $image = '')
{
try {
$self = new self();
$self->name = $name;
$self->phone = $phone;
$self->email = $email;
$self->ip = $ip;
$self->country = $country;
$self->message = $message;
$self->message_cn = $message_cn;
$self->type = $type;
$self->inquiry_date = $inquiry_date;
$self->url = $url;
$self->url_title = $url_title;
$self->url_keyword = $url_keyword;
$self->image = $image;
$self->origin_key = $origin_key;
$self->message_sign = $message_sign;
$self->save();
return true;
} catch (\Exception $e) {
return false;
}
}
}
... ...
<?php
/**
* @remark :
* @name :AiBlogTask.php
* @author :lyh
* @method :post
* @time :2025/2/14 11:03
*/
namespace App\Models\Project;
use App\Models\Base;
class AiBlogTask extends Base
{
protected $table = 'gl_ai_blog_task';
}
... ...
<?php
/**
* @remark :
* @name :ProjectAiSetting.php
* @author :lyh
* @method :post
* @time :2025/2/13 16:53
*/
namespace App\Models\Project;
use App\Models\Base;
/**
* @remark :项目ai_blog设置
* @name :ProjectAiSetting
* @author :lyh
* @method :post
* @time :2025/2/13 16:53
*/
class ProjectAiSetting extends Base
{
protected $table = 'gl_project_ai_setting';
}
... ...
<?php
/**
* @remark :
* @name :AiBlogService.php
* @author :lyh
* @method :post
* @time :2025/2/13 14:15
*/
namespace App\Services;
class AiBlogService
{
public $url = 'https://ai-extend.ai.cc/';
public $mch_id = 1;//默认配置
public $sign = '';//签名
public $key = 'b3e4c722b821';//默认key
public $webhook = 'https://develop.globalso.com/api/ai_webhook';//回调地址
public $task_id = '';//任务id
/**
* @remark :创建项目
* @name :createProject
* @author :lyh
* @method :post
* @time :2025/2/13 14:28
*/
public function createProject($project_name,$language = 'en',$profile){
$request_url = $this->url.'api/project/create';
$param = [
'mch_id'=>$this->mch_id,
'title'=>$project_name,
'language'=>$language,
'profile'=>$profile
];
$this->sign = $this->generateSign($param,$this->key);
$param['sign'] = $this->sign;
$result = http_post($request_url,json_encode($param,true));
return $result;
}
/**
* @remark :更新项目
* @name :updatedProject
* @author :lyh
* @method :post
* @time :2025/2/13 14:35
*/
public function updatedProject($project_name,$language = 'en'){
$request_url = $this->url.'api/project/save';
$param = [
'mch_id'=>$this->mch_id,
'title'=>$project_name,
'language'=>$language
];
$this->sign = $this->generateSign($param,$this->key);
$param['sign'] = $this->sign;
$result = http_post($request_url,json_encode($param,true));
return $result;
}
/**
* @remark :创建任务
* @name :createTask
* @author :lyh
* @method :post
* @time :2025/2/13 14:39
* @param :type=(1作者2文章) keyword=关键词 subtype=blog url=回调url
*/
public function createTask($keyword,$type = 1,$subtype = 'Blog',$template_id = 1){
$request_url = $this->url.'api/task/create';
$param = [
'mch_id'=>$this->mch_id,
'keyword'=>$keyword,
'type'=>$type,
'subtype'=>$subtype,
'url'=>$this->webhook,
'template_id'=>$template_id
];
$this->sign = $this->generateSign($param,$this->key);
$param['sign'] = $this->sign;
$result = http_post($request_url,json_encode($param,true));
return $result;
}
/**
* @remark :创建作者
* @name :createAuthor
* @author :lyh
* @method :post
* @time :2025/2/13 14:43
*/
public function createAuthor(){
$request_url = $this->url.'api/author/create';
$param = [
'mch_id'=>$this->mch_id,
'sign'=>$this->sign,
];
$result = http_post($request_url,json_encode($param,true));
return $result;
}
/**
* @remark :计算签名
* @name :generateSign
* @author :lyh
* @method :post
* @time :2025/2/13 15:07
*/
public function generateSign($params, $key)
{
// 去除数组中所有值为空的项
array_filter($params);
// 按照key值的ASCII码从小到大排序
ksort($params);
// 生成URL的查询字符串
$string = http_build_query($params);
// 生成签名
$sign = md5($string . $key);
// 转换成大写
$sign = strtoupper($sign);
return $sign;
}
/**
* @remark :获取文章详情
* @name :getDetail
* @author :lyh
* @method :post
* @time :2025/2/14 11:23
*/
public function getDetail(){
$request_url = $this->url.'api/result/detail';
$param = [
'mch_id'=>$this->mch_id,
'task_id'=>$this->task_id,
];
$this->sign = $this->generateSign($param,$this->key);
$param['sign'] = $this->sign;
$result = http_post($request_url,json_encode($param,true));
return $result;
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2025/2/13
* Time: 11:01
*/
namespace App\Services;
use Illuminate\Support\Facades\Log;
/**
* Class InquiryRelayService
* @package App\Services
*/
class InquiryRelayService
{
/**
* 获取询盘
* @return mixed|string
*/
public function getInquiryRelay()
{
$date = date('Y-m-d');
$token = md5($date . 'qqs');
$url = 'https://form.globalso.com/api/external-interface/echo_inquriy/d1483a8e57cb485a?date=' . $date . '&token=' . $token . '&type=2';
$result = http_get($url);
return $result;
}
/**
* 获取询盘
* @param $id
* @return array|bool
*/
public function getInquirySzcm($id)
{
try {
// 获取数据
$url = "https://api.szcmapi.com/get_inquiry.aspx?id=".$id;
$json = $this->szcmCurl($url);
// 兼容过去到的数据, 比较乱
$json = trim(str_replace("\r\n", '\n', (string) $json));
$json = str_replace('3/4"','3/4',$json);
$json = str_replace('"Steklopribor"','Steklopribor',$json);
$json = str_replace('"Net30 days"','Net30 days',$json);
$json = trim($json);
$json = str_replace("\n",'',$json);
$array = json_decode($json,true);
if (empty($array))
return false;
// 整合最终数据
$title = base64_decode($array['title']);
$title = str_replace("'",'',$title);
$title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
$title = str_replace("'",'',$title);
$message = html_entity_decode(addslashes(base64_decode($array['Message'])), ENT_QUOTES, 'UTF-8');
$message = str_replace("'",'',$message);
$email = trim($array['Email']);
$name = html_entity_decode($array['Name'], ENT_QUOTES, 'UTF-8');
$name = str_replace("'",'',$name);
$result = [
'image' => $array['image'] ?: '',
'time' => $array['submit_time'] ?: date('Y-m-d H:i:s'),
'name' => $name,
'email' => $email,
'phone' => $array['Phone'] ?: '',
'refer' => $array['refer'] ?: '',
'message' => $message,
'ip' => $array['submit_ip'] ?: '',
'source_address' => 'api.szcmapi.com',
'title' => $title,
'submit_country' => $array['submit_country'] ?: '',
'origin_key' => $array['Id'],
];
return $result;
} catch (\Exception $e) {
Log::error('获取询盘: getInquirySzcm : ' . $id . ', error: ' . $e->getMessage());
return false;
}
}
/**
* @param $url
* @return bool|string
*/
public function szcmCurl($url)
{
$agent = 'ChuangMao_API_Bot';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 'all');
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}
\ No newline at end of file
... ...
... ... @@ -153,7 +153,9 @@ Route::middleware(['bloginauth'])->group(function () {
Route::prefix('ai')->group(function () {
//ai
Route::any('/news/', [\App\Http\Controllers\Bside\Ai\AiNewsController::class, 'save'])->name('ai_news_save');
Route::any('/blog/', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'save'])->name('ai_blog_save');
Route::any('/blog/getAiBlog', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getAiBlog'])->name('ai_blog_getAiBlog');
Route::any('/blog/save', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'save'])->name('ai_blog_save');
Route::any('/blog/sendTask', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'sendTask'])->name('ai_blog_sendTask');
Route::any('/product/', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'save'])->name('ai_product_save');
Route::any('/product/productList', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'productList'])->name('ai_product_productList');
Route::any('/product/productCateList', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'productCateList'])->name('ai_product_productCateList');
... ...