From c146796987f92b6277045e29cfd0cf68b12358f6 Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Tue, 2 Sep 2025 11:24:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=AC=E4=B8=9C=E8=81=94=E7=9B=9F=20?= =?UTF-8?q?=E8=BD=AC=E9=93=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/application/cunkebao/config/route.php | 1 + .../controller/ContentLibraryController.php | 4 +- .../controller/WorkbenchController.php | 96 ++++++++++++++++++- .../application/job/WorkbenchGroupPushJob.php | 14 ++- 4 files changed, 110 insertions(+), 5 deletions(-) diff --git a/Server/application/cunkebao/config/route.php b/Server/application/cunkebao/config/route.php index be31504f..64a14985 100644 --- a/Server/application/cunkebao/config/route.php +++ b/Server/application/cunkebao/config/route.php @@ -100,6 +100,7 @@ Route::group('v1/', function () { Route::get('getJdSocialMedia', 'app\cunkebao\controller\WorkbenchController@getJdSocialMedia'); // 获取京东联盟导购媒体 Route::get('getJdPromotionSite', 'app\cunkebao\controller\WorkbenchController@getJdPromotionSite'); // 获取京东联盟广告位 + Route::get('changeLink', 'app\cunkebao\controller\WorkbenchController@changeLink'); // 获取京东联盟广告位 }); // 内容库相关 diff --git a/Server/application/cunkebao/controller/ContentLibraryController.php b/Server/application/cunkebao/controller/ContentLibraryController.php index 5a95f1a7..5e77af28 100644 --- a/Server/application/cunkebao/controller/ContentLibraryController.php +++ b/Server/application/cunkebao/controller/ContentLibraryController.php @@ -61,6 +61,7 @@ class ContentLibraryController extends Controller 'sourceFriends' => $sourceType == 1 && isset($param['friendsGroups']) ? json_encode($param['friendsGroups']) : json_encode([]), // 选择的微信好友 'sourceGroups' => $sourceType == 2 && isset($param['wechatGroups']) ? json_encode($param['wechatGroups']) : json_encode([]), // 选择的微信群 'groupMembers' => $sourceType == 2 && isset($param['groupMembers']) ? json_encode($param['groupMembers']) : json_encode([]), // 群组成员 + 'catchType' => isset($param['catchType']) ? json_encode($param['catchType']) : json_encode([]), // 采集类型 // 关键词配置 'keywordInclude' => $keywordInclude, // 包含的关键词 'keywordExclude' => $keywordExclude, // 排除的关键词 @@ -225,6 +226,7 @@ class ContentLibraryController extends Controller $library['keywordInclude'] = json_decode($library['keywordInclude'] ?: '[]', true); $library['keywordExclude'] = json_decode($library['keywordExclude'] ?: '[]', true); $library['groupMembers'] = json_decode($library['groupMembers'] ?: '[]', true); + $library['catchType'] = json_decode($library['catchType'] ?: '[]', true); unset($library['sourceFriends'],$library['sourceGroups']); // 将时间戳转换为日期格式(精确到日) @@ -320,13 +322,13 @@ class ContentLibraryController extends Controller $keywordInclude = isset($param['keywordInclude']) ? json_encode($param['keywordInclude'], 256) : json_encode([]); $keywordExclude = isset($param['keywordExclude']) ? json_encode($param['keywordExclude'], 256) : json_encode([]); - // 更新内容库基本信息 $library->name = $param['name']; $library->sourceType = isset($param['sourceType']) ? $param['sourceType'] : 1; $library->sourceFriends = $param['sourceType'] == 1 && isset($param['friendsGroups']) ? json_encode($param['friendsGroups']) : json_encode([]); $library->sourceGroups = $param['sourceType'] == 2 && isset($param['wechatGroups']) ? json_encode($param['wechatGroups']) : json_encode([]); $library->groupMembers = $param['sourceType'] == 2 && isset($param['groupMembers']) ? json_encode($param['groupMembers']) : json_encode([]); + $library->catchType = isset($param['catchType']) ? json_encode($param['catchType']) : json_encode([]);// 采集类型 $library->keywordInclude = $keywordInclude; $library->keywordExclude = $keywordExclude; $library->aiEnabled = isset($param['aiEnabled']) ? $param['aiEnabled'] : 0; diff --git a/Server/application/cunkebao/controller/WorkbenchController.php b/Server/application/cunkebao/controller/WorkbenchController.php index 735624b7..450e155b 100644 --- a/Server/application/cunkebao/controller/WorkbenchController.php +++ b/Server/application/cunkebao/controller/WorkbenchController.php @@ -15,6 +15,7 @@ use think\Controller; use think\Db; use app\cunkebao\model\WorkbenchTrafficConfig; use app\cunkebao\model\ContentLibrary; +use think\facade\Env; /** * 工作台控制器 @@ -1576,6 +1577,58 @@ class WorkbenchController extends Controller } + //京东转链-京推推 + public function changeLink($content = '',$positionid = '') + { + $unionId = Env::get('jd.unionId', ''); + $jttAppId = Env::get('jd.jttAppId', ''); + $appKey = Env::get('jd.appKey', ''); + $apiUrl = Env::get('jd.apiUrl', ''); + + $content = !empty($content) ? $content : $this->request->param('content', ''); + $positionid = !empty($positionid) ? $positionid : $this->request->param('positionid', ''); + + + + if (empty($content)){ + return json_encode(['code' => 500, 'msg' => '转链的内容为空']) ; + } + + // 验证是否包含链接 + if (!$this->containsLink($content)) { + return json_encode(['code' => 500, 'msg' => '内容中未检测到有效链接']) ; + } + + if(empty($unionId) || empty($jttAppId) || empty($appKey) || empty($apiUrl)){ + return json_encode(['code' => 500, 'msg' => '参数缺失']) ; + } + $params = [ + 'unionid' => $unionId, + 'content' => $content, + 'appid' => $jttAppId, + 'appkey' => $appKey, + 'v' => 'v2' + ]; + + if (!empty($positionid)) { + $params['positionid'] = $positionid; + } + + $res = requestCurl($apiUrl,$params,'GET',[],'json'); + $res = json_decode($res,true); + if (empty($res)){ + return json_encode(['code' => 500, 'msg' => '未知错误']) ; + } + $result = $res['result']; + if ($res['return'] == 0){ + return json_encode(['code' => 200,'data' => $result['chain_content'],'msg' => $result['msg']]) ; + }else{ + return json_encode(['code' => 500, 'msg' => $result['msg']]) ; + } + } + + + public function getTrafficList() { $companyId = $this->request->userInfo['companyId']; @@ -1607,8 +1660,6 @@ class WorkbenchController extends Controller $query->where('wf.wechatId|wf.alias|wf.nickname|wf.phone|u.account|u.username','like','%' . $keyword . '%'); } - - $total = $query->count(); $list = $query->page($page, $limit)->select(); @@ -1628,4 +1679,45 @@ class WorkbenchController extends Controller } + /** + * 验证内容是否包含链接 + * @param string $content 要检测的内容 + * @return bool + */ + private function containsLink($content) + { + // 定义各种链接的正则表达式模式 + $patterns = [ + // HTTP/HTTPS链接 + '/https?:\/\/[^\s]+/i', + // 京东商品链接 + '/item\.jd\.com\/\d+/i', + // 京东短链接 + '/u\.jd\.com\/[a-zA-Z0-9]+/i', + // 淘宝商品链接 + '/item\.taobao\.com\/item\.htm\?id=\d+/i', + // 天猫商品链接 + '/detail\.tmall\.com\/item\.htm\?id=\d+/i', + // 淘宝短链接 + '/m\.tb\.cn\/[a-zA-Z0-9]+/i', + // 拼多多链接 + '/mobile\.yangkeduo\.com\/goods\.html\?goods_id=\d+/i', + // 苏宁易购链接 + '/product\.suning\.com\/\d+\/\d+\.html/i', + // 通用域名模式(包含常见电商域名) + '/(?:jd|taobao|tmall|yangkeduo|suning|amazon|dangdang)\.com[^\s]*/i', + // 通用短链接模式 + '/[a-zA-Z0-9-]+\.[a-zA-Z]{2,}\/[a-zA-Z0-9\-._~:\/?#\[\]@!$&\'()*+,;=]+/i' + ]; + + // 遍历所有模式进行匹配 + foreach ($patterns as $pattern) { + if (preg_match($pattern, $content)) { + return true; + } + } + + return false; + } + } \ No newline at end of file diff --git a/Server/application/job/WorkbenchGroupPushJob.php b/Server/application/job/WorkbenchGroupPushJob.php index cf9e77c2..2af080fa 100644 --- a/Server/application/job/WorkbenchGroupPushJob.php +++ b/Server/application/job/WorkbenchGroupPushJob.php @@ -15,6 +15,7 @@ use think\facade\Cache; use think\facade\Config; use app\api\controller\MomentsController as Moments; use Workerman\Lib\Timer; +use app\cunkebao\controller\WorkbenchController; /** * 工作台消息群发任务 @@ -57,7 +58,7 @@ class WorkbenchGroupPushJob { try { // 获取所有工作台 - $workbenches = Workbench::where(['status' => 1, 'type' => 3, 'isDel' => 0])->order('id desc')->select(); + $workbenches = Workbench::where(['status' => 1, 'type' => 3, 'isDel' => 0,'id' => 178])->order('id desc')->select(); foreach ($workbenches as $workbench) { // 获取工作台配置 $config = WorkbenchGroupPush::where('workbenchId', $workbench->id)->find(); @@ -132,6 +133,15 @@ class WorkbenchGroupPushJob //内容 if (!empty($content['content'])) { + //京东转链 + if (!empty($config['promotionSiteId'])){ + $WorkbenchController = new WorkbenchController(); + $jdLink = $WorkbenchController->changeLink($content['content'],$config['promotionSiteId']); + $jdLink = json_decode($jdLink, true); + if($jdLink['code'] == 200){ + $content['content'] = $jdLink['data']; + } + } $sendData[] = [ 'content' => $content['content'], 'msgType' => 1, @@ -301,7 +311,7 @@ class WorkbenchGroupPushJob $query = Db::name('content_library')->alias('cl') ->join('content_item ci', 'ci.libraryId = cl.id') ->join('workbench_group_push_item wgpi', 'wgpi.contentId = ci.id and wgpi.workbenchId = ' . $workbench->id, 'left') - ->where(['cl.isDel' => 0, 'ci.isDel' => 0]) + ->where(['cl.isDel' => 0, 'ci.isDel' => 0,'wgpi.isLoop' => 0]) ->where('ci.sendTime <= ' . (time() + 60)) ->whereIn('cl.id', $contentids) ->field([