1, 'source'=>'TEST_MULTI', 'rules'=>[ ['position'=>'tl', 'margin_x'=>'2%', 'margin_y'=>'2%', 'width'=>'15%', 'height'=>'8%', 'mode'=>1], // 左上 ['position'=>'tr', 'margin_x'=>'2%', 'margin_y'=>'2%', 'width'=>'15%', 'height'=>'8%', 'mode'=>1], // 右上 ['position'=>'bl', 'margin_x'=>'2%', 'margin_y'=>'15%', 'width'=>'10%', 'height'=>'5%', 'mode'=>1] // 左下 ]]; $debug_log[] = "⚠️ 多遮罩测试模式"; } else { $ch = curl_init(); $api_query = API_WATERMARK . "?id=" . $id . "&url=" . urlencode($check_url_for_api); if($is_debug) $debug_log[] = "API: ".$api_query; curl_setopt_array($ch, [CURLOPT_URL=>$api_query, CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>3, CURLOPT_SSL_VERIFYPEER=>false, CURLOPT_SSL_VERIFYHOST=>false]); $response = curl_exec($ch); curl_close($ch); $res_data = json_decode($response, true); } // 3. 解析多条规则 if ($res_data && isset($res_data['code']) && $res_data['code'] == 1) { if ($is_debug) $debug_log[] = "Source: " . ($res_data['source'] ?? 'Unknown'); // 兼容单条和多条 if (isset($res_data['rules']) && is_array($res_data['rules'])) { $rules = $res_data['rules']; if ($is_debug) $debug_log[] = "检测到多条规则: " . count($rules) . "个"; } elseif (isset($res_data['rule']) && is_array($res_data['rule'])) { $rules[] = $res_data['rule']; if ($is_debug) $debug_log[] = "检测到单条规则"; } // 4. 循环生成 CSS 和 HTML foreach ($rules as $idx => $r) { $pos_style = ""; $mx = $r['margin_x']; if(strpos($mx, '%')===false && strpos($mx, 'px')===false) $mx .= '%'; $my = $r['margin_y']; if(strpos($my, '%')===false && strpos($my, 'px')===false) $my .= '%'; switch ($r['position']) { case 'tl': $pos_style = "top: $my; left: $mx;"; break; case 'tr': $pos_style = "top: $my; right: $mx;"; break; case 'bl': $pos_style = "bottom: $my; left: $mx;"; break; case 'br': $pos_style = "bottom: $my; right: $mx;"; break; default: $pos_style = "top: 2%; right: 2%;"; } $bg_style = ""; $debug_border = ($is_debug || $is_test) ? "border: 2px solid red !important; background: rgba(255,0,0,0.3) !important;" : ""; if (isset($r['mode']) && $r['mode'] == 1) { $bg_style = "backdrop-filter: blur(15px); -webkit-backdrop-filter: blur(15px); background: rgba(255,255,255,0.01);"; } else { $img = $r['cover_img'] ?? ''; $bg_style = "background-image: url('$img'); background-size: 100% 100%; background-repeat: no-repeat;"; } $mask_id = "smart-mask-" . $idx; $mask_css .= " #{$mask_id} { position: absolute !important; {$pos_style} width: {$r['width']}; height: {$r['height']}; z-index: 1 !important; /* 位于视频上,控制栏下 */ pointer-events: none !important; border-radius: 4px; overflow: hidden; {$bg_style} {$debug_border} -webkit-mask-image: radial-gradient(white, black); display: none; visibility: visible !important; }"; // 加上统一类名 .smart-mask-layer $mask_html .= '
'; } } } ?>