京东联盟 转链
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user