作者 李宇航

合并分支 'lyh-server' 到 'master'

Lyh server



查看合并请求 !1998
... ... @@ -13,16 +13,19 @@ use App\Console\Commands\Domain\DomainInfo;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Models\Ai\AiBlogAuthor;
use App\Models\Com\NoticeLog;
use App\Models\Com\V6WeeklyReport;
use App\Models\Project\AiBlogTask;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\Project\OnlineCheck;
use App\Models\Project\Project;
use App\Models\Project\ProjectAiSetting;
use App\Models\ProjectAssociation\ProjectAssociation;
use App\Models\RouteMap\RouteMap;
use App\Models\Visit\Visit;
use App\Models\WebSetting\WebLanguage;
use App\Models\WebSetting\WebSetting;
use App\Models\Workchat\MessagePush;
use App\Services\AiBlogService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
... ... @@ -46,117 +49,168 @@ class lyhDemo extends Command
protected $description = '更新路由';
public function handle(){
$projectIds = DB::table('gl_project_ai_setting_copy1')
->whereIn('mch_id', function ($query) {
$query->select('mch_id')
->from('gl_project_ai_setting_copy1')
->groupBy('mch_id')
->havingRaw('COUNT(*) > 1');
})
->pluck('project_id');
$projectIds[] = 811;
$projectIds[] = 1367;
$projectIds[] = 1370;
$projectIds[] = 2201;
$projectIds[] = 2260;
$projectIds[] = 2259;
// $aiSettingModel = new ProjectAiSetting();
// foreach ($projectIds as $item){
// $info = $aiSettingModel->read(['project_id'=>$item]);
// if($info === false){
// echo '项目id:'.$item.PHP_EOL;
// }else{
// $this->createAuthor($item,$info['mch_id'],$info['key']);
// }
// }
// return true;
$aiSettingModel = new ProjectAiSetting();
$aiSettingModel->del(['project_id'=>['in',$projectIds]]);
$projectModel = new Project();
$logic = new ProjectLogic();
$lists = $projectModel->list(['delete_status' => 0,'extend_type'=>0,'id'=>['in',$projectIds]], 'id', ['id']);
$title = [];
foreach ($lists as $val) {
//清空作者
ProjectServer::useProject($val['id']);
AiBlogAuthor::truncate();
$routeMapModel = new RouteMap();
$routeMapModel->del(['source'=>$routeMapModel::SOURCE_AI_BLOG_AUTHOR]);
DB::disconnect('custom_mysql');
//重新创建项目拉取作者
$info = $logic->getProjectInfo($val['id']);
$title[] = $info['company']?:$info['title'];
if(empty($info['main_lang_id'])){
$info['main_lang_id'] = 1;
}
if(empty($info['is_ai_blog'])){
$info['is_ai_blog'] = 1;
}
// try {
$this->setAiBlog($info['id'],$info['main_lang_id'],$info['is_ai_blog'] ?? 0,
$info['company']??"", $info['deploy_optimize']['company_en_name'] ?? '',
$info['deploy_optimize']['company_en_description'] ?? '',$info['is_ai_video'] ?? 0,$info['is_related_video'] ?? 0);
// }catch (\Exception $e){
// continue;
// }
$projectArr = [3257,1835,1834];
$v6WeekModel = new V6WeeklyReport();
foreach ($projectArr as $item){
$projectModel = new Project();
$latest = $v6WeekModel->formatQuery(['project_id'=>$item])->orderBy('id', 'desc')->first();
$list = $projectModel->read(['delete_status'=>0,'id'=>$item],['id','title','is_weekly_report','main_lang_id']);
$latest['main_lang_id'] = $list['main_lang_id'];
$latest['is_weekly_report'] = $list['is_weekly_report'];
$latest['title'] = $list['title'];
$this->workChatMessage($latest,$item);
}
return true;
}
public function setAiBlog($project_id,$main_lang_id,$is_ai_blog,$company,$company_en_name,$company_en_description,$is_ai_video = 0,$is_related_video = 0){
if(empty($main_lang_id) || (empty($is_ai_blog) && empty($is_ai_video))){
echo '创建失败:'.$project_id.PHP_EOL;
}
$this->model = new Project();
$projectInfo = $this->model->read(['id'=>$project_id],['title','main_lang_id','company']);
$projectOptimize = DeployOptimize::where('project_id', $project_id)->first();
//获取项目主语种
$languageModel = new WebLanguage();
$languageInfo = $languageModel->read(['id'=>$main_lang_id],['short']);
if($languageInfo == false){
echo '创建失败:'.$project_id.PHP_EOL;
}
$aiSettingModel = new ProjectAiSetting();
$aiSettingInfo = $aiSettingModel->read(['project_id'=>$project_id]);
if($aiSettingInfo === false){
$aiBlogService = new AiBlogService();
$result = $aiBlogService->createProject($projectInfo['company']?:$projectInfo['title'],$languageInfo['short'],$company_en_description,$company_en_name,$is_related_video);
if(isset($result['status']) && $result['status'] == 200){
//查看当前项目是否已有记录
$resData = [
'project_id'=>$project_id,
'mch_id'=>$result['data']['mch_id'],
'key'=>$result['data']['key'],
];
$aiSettingModel->add($resData);
$this->createAuthor($project_id,$result['data']['mch_id'],$result['data']['key']);
public function workChatMessage($data,$project_id){
$arr = [];
//项目是否有绑定群
$friend_id = ProjectAssociation::where('project_id', $project_id)
->where('status', ProjectAssociation::STATUS_NORMAL)
->where('binding_app', ProjectAssociation::ENTERPRISE_WECHAT)
->value('friend_id');
if(!$friend_id){
echo date('Y-m-d H:i:s') . '没有绑定企微群:'.$project_id . PHP_EOL;
return false;
}
$content = '';
$content1 = '';
if(!empty($data['inquiry_total'])){
$content1 .= '项目共计已收到询盘 '.$data['inquiry_total'].'条,';
if(!empty($data['week_inquiry_total'])){
$content1 .= '本周新收 '.$data['week_inquiry_total'].' 封询盘。';
}
if(!empty($data['inquiry_country'])){
$data['inquiry_country'] = json_decode($data['inquiry_country'],true);
arsort($data['inquiry_country']);
$data['inquiry_country'] = array_slice($data['inquiry_country'], 0, 4, true);
$country = '';
foreach ($data['inquiry_country'] as $k => $v){
$country .= $k.',';
};
$country = trim($country,',');
if(!empty($country)){
$content1 .= '询盘主要来源于'.$country.'等国家地区。';
}
}
$content1 .= '如有高质量客户,请您密切关注与跟进;';
}
if(!empty($content1)){
$arr[] = $content1;
}
$content2 = '';
if(!empty($data['google_indexed_num']) || !empty($data['google_links_num']) || !empty($data['keyword_home_num']) || !empty($data['keyword_three_num']) || !empty($data['keyword_five_num']) || !empty($data['keyword_ten_num']) || !empty($data['daily_average_num'])){
$content2 .= '项目截止目前';
if($data['main_lang_id'] == 8){
$title = 'Yandex';
}else{
echo '创建失败:'.$project_id.PHP_EOL;
$title = '谷歌';
}
if(!empty($data['google_indexed_num'])){
$content2 .= $title.'收录量:'.$data['google_indexed_num'].'条,';
}
if(!empty($data['google_links_num'])){
//获取上一次的外链数
$latestRecord = V6WeeklyReport::where(['project_id'=>$project_id])->orderBy('id', 'desc')->first();
if(!empty($latestRecord)){
if($latestRecord['google_links_num'] != $data['google_links_num']){
$content2 .= '外链量:'.$data['google_links_num'].'条,';
}
}else{
$content2 .= '外链量:'.$data['google_links_num'].'条,';
}
}
if(!empty($data['keyword_home_num']) || !empty($data['keyword_three_num']) || !empty($data['keyword_five_num']) || !empty($data['keyword_ten_num'])){
$content2 .= $title.'搜索排名';
if(!empty($data['keyword_home_num'])){
$content2 .= '首页关键词数量为:'.$data['keyword_home_num'].'个,';
}
if(!empty($data['keyword_three_num'])){
$content2 .= '前三页关键词数量为:'.$data['keyword_three_num'].'个,';
}
if(!empty($data['keyword_five_num'])){
$content2 .= '前五页关键词数量为:'.$data['keyword_five_num'].'个,';
}
if(!empty($data['keyword_ten_num'])){
$content2 .= '前十页关键词数量为:'.$data['keyword_ten_num'].'个,';
}
}
}else{
//有信息更新
if(($projectInfo['company'] != $company) || ($projectInfo['main_lang_id'] != $main_lang_id)
|| ($projectOptimize['company_en_name'] != $company_en_name) || ($projectOptimize['company_en_description'] != $company_en_description)){
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
$aiBlogService->key = $aiSettingInfo['key'];
$aiBlogService->updatedProject($projectInfo['company']?:$projectInfo['title'],$languageInfo['short'],$company_en_description,$company_en_name,$is_related_video);
if(!empty($data['daily_average_num'])){
$content2 .= '本周日均访客量:'.$data['daily_average_num'].'+。';
}
$content2 .= PHP_EOL.'全球搜建议用户持续分析、选择、添加企业、产品、服务等相关关键词进行优化和监控,以覆盖更多相关排名和流量;';
}
return true;
}
public function createAuthor($project_id,$mch_id,$key){
//查看当前项目是否已经创建了作者
$aiBlogTaskModel = new AiBlogTask();
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $mch_id;
$aiBlogService->key = $key;
$result = $aiBlogService->createAuthor();
if($result['status'] == 200){
//查看当前是否已有未执行的
$aiBlogTaskModel->add(['project_id'=>$project_id,'status'=>1,'type'=>1]);
if(!empty($content2)){
$arr[] = $content2;
}
$content3 = '';
if(!empty($data['product_num']) || !empty($data['news_num']) || !empty($data['week_product_num']) || !empty($data['week_news_num'])){
if(!empty($data['product_num']) || !empty($data['news_num'])){
$content3 .= '项目截止目前';
if(!empty($data['product_num'])){
$content3 .= '发布产品:'.$data['product_num'].'条,';
}
if(!empty($data['news_num'])){
$content3 .= '发布新闻:'.$data['news_num'].'条。';
}
}
if(!empty($data['week_product_num']) || !empty($data['week_news_num'])){
$content3 .= '本周新增';
if(!empty($data['week_product_num'])){
$content3 .= '产品:'.$data['week_product_num'].'条,';
}
if(!empty($data['week_news_num'])){
$content3 .= '新闻:'.$data['week_news_num'].'条。';
}
}
$content3 .= PHP_EOL.'全球搜建议用户保持网站内容的持续更新与完善,可参考谷歌关于创建实用、可靠、以用户为中心的内容的相关建议:https://developers.google.com/search/docs/fundamentals/creating-helpful-content?hl=zh-cn;';
}
if(!empty($content3)){
$arr[] = $content3;
}
$content4 = '';
if(!empty($data['main_update_num'])){
$content4 .= '网站加载速度维护及主站页面更新'.$data['main_update_num'].'次。';
}
if(!empty($data['aggregation_update_num'])){
$content4 .= '聚合页主站页面更新'.$data['aggregation_update_num'].'次。';
}
if(!empty($data['minor_update_num'])){
$content4 .= '小语种站页面更新'.$data['minor_update_num'].'次。';
}
if(!empty($data['aggregation_minor_update_num'])){
$content4 .= '聚合页小语种站页面'.$data['aggregation_minor_update_num'].'次。';
}
if(!empty($content4)){
$content4 = PHP_EOL.'本周主要优化工作包括:TDK、H标签、Img标签等优化设置排查与进一步完善,Sitemap更新与网页收录提交,外链新增与排查。'.$content4;
}
if(!empty($content4)){
$arr[] = $content4;
}
if(empty($arr)){
return true;
}
foreach ($arr as $key => $val){
$content .= ($key+1).','.$val.PHP_EOL.PHP_EOL;
}
$tomorrowNineAM = date('Y-m-d 09:00:00', time());
if(empty($content)){
return true;
}
$tips = 'Tips:'.PHP_EOL.'1、全球搜V6.0系统提供网页TDK、H标签、Img标签等用户自定义编辑接口且辅以AI创作工具,用户可进一步对相关优化设置进行精细化优化与调整;'.PHP_EOL.'2、全球搜V6.0系统提供小语种页面精准校对翻译功能,用户可进一步对已翻译小语种页面进行人工翻译校对;'.PHP_EOL.'3、全球搜V6.0系统支持绑定Facebook、LinkedIn、X(原Twitter)等社媒账号,可一键同步转发网站上发布的产品和新闻至社媒账号动态,建议用户用起来哦;'.PHP_EOL.'4、如用户有较丰富的企业、产品、服务相关视频素材,全球搜建议用户及时创建YouTube主页,并在YouTube和网站相关网页上同步发布视频;';
$message = "【全球搜V6.0周报】" . PHP_EOL . $content . PHP_EOL . $tips;
$param = [
'project_id'=>$project_id,
'friend_id'=>$friend_id,
'type'=>MessagePush::TYPE_WEEK,
'content'=> $message,
'ref_ids'=>'',
'send_time'=>$tomorrowNineAM,
'status'=>0,
];
//写入一条推送消息 自动消费
$messagePushModel = new MessagePush();
$messagePushModel->add($param);
return true;
}
}
... ...
... ... @@ -11,6 +11,7 @@ use App\Models\Inquiry\InquiryData;
use App\Models\Manage\Manage;
use App\Models\User\User;
use App\Models\WebSetting\WebLanguage;
use App\Services\HumanizeAiTextService;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Hash;
... ... @@ -160,5 +161,23 @@ class IndexController extends BaseController
$this->response('success',Code::SUCCESS,['dynamic_password'=>$dynamic_password]);
}
/**
* @remark :去ai痕迹
* @name :notAiHumanizer
* @author :lyh
* @method :post
* @time :2025/5/21 9:08
*/
public function notAiHumanizer(){
$this->request->validate([
'text'=>'required',
'lang'=>'required'
],[
'text.required' => '文本text不能为空',
'lang.required' => '语种不能为空',
]);
$service = new HumanizeAiTextService();
$data = $service->humanizer($this->param['text'],$this->param['lang']);
$this->response('success', Code::SUCCESS, $data);
}
}
... ...
... ... @@ -1214,4 +1214,5 @@ class ProjectController extends BaseController
$lists = $model->list(['status' => 1], 'id', ['id', 'industry_name'], 'asc');
$this->response('success', Code::SUCCESS, $lists);
}
}
... ...
<?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 = self::DRIVER_HUMANIZE_AI_TEXT;
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);
}
}
... ...
... ... @@ -17,6 +17,7 @@ Route::middleware(['aloginauth'])->group(function () {
Route::any('/sendNotify', [Aside\Com\CNoticeController::class, 'sendNotify'])->name('admin.sendNotify');
Route::any('/getCountry', [Aside\Com\CNoticeController::class, 'getCountry'])->name('admin.getCountry');
Route::any('/getDynamicPassword', [Aside\Com\IndexController::class, 'getDynamicPassword'])->name('admin.getDynamicPassword');
Route::any('/notAiHumanizer', [Aside\Com\IndexController::class, 'notAiHumanizer'])->name('admin.notAiHumanizer');
//会员相关
Route::prefix('user')->group(function () {
//会员管理
... ...