weijiajia/tencent-url-detection
Composer 安装命令:
composer require weijiajia/tencent-url-detection
包简介
A PHP library to detect URL safety using Tencent URL security API, with support for multiple captcha solving services.
README 文档
README
A PHP library to detect URL safety using Tencent's URL security API. It provides a simple interface to check if a URL is considered risky by Tencent, often used for WeChat and QQ link previews. This library supports multiple drivers, including direct API calls and integration with captcha solving services like 2Captcha.
Features
- Easy integration with Tencent's URL safety check.
- Multiple drivers available:
CgiUrlsecQq: Direct check viacgi.urlsec.qq.com(may require captcha solving).Rrbay: Uses therrbay.comservice for URL checking.TwoCaptcha: Integrates with2captcha.comto solve Tencent's captchas before checking.
- Built on SaloonPHP for robust HTTP requests.
- PSR-4 autoloading and PSR-12 coding standards (enforced by PHP CS Fixer).
- Comprehensive unit and feature tests using PestPHP.
Requirements
- PHP ^8.1
- Composer
Installation
You can install the package via Composer:
composer require weijiajia/tencent-url-detection
Laravel Integration (Optional)
This package includes a Service Provider for easy integration with the Laravel framework.
-
Service Provider Auto-Discovery: The
Weijiajia\TencentUrlDetection\TencentUrlDetectionServiceProviderwill be automatically discovered and registered by Laravel. -
Publish Configuration (Recommended): To customize the default driver and driver-specific settings (like API keys), publish the configuration file:
php artisan vendor:publish --provider="Weijiajia\TencentUrlDetection\TencentUrlDetectionServiceProvider" --tag="config"
This will create a
config/tencent-url-detection.phpfile in your application. You should fill in your API keys and preferred settings in this file and, for security, add it to your.gitignoreif it contains sensitive credentials. -
Usage in Laravel: You can resolve the
DriversManageror a specific driver from the service container, or use the Facade (if you choose to create one).use Illuminate\Http\Request; use Weijiajia\TencentUrlDetection\DriversManager; use Weijiajia\TencentUrlDetection\Contracts\Driver; // Example in a Controller using Dependency Injection for the Manager class UrlCheckController extends Controller { protected $urlDetectionManager; public function __construct(DriversManager $urlDetectionManager) { $this->urlDetectionManager = $urlDetectionManager; } public function check(Request $request) { $urlToCkeck = $request->input('url', 'https://example.com'); // Get the default driver as configured in config/tencent-url-detection.php $driver = $this->urlDetectionManager->driver(); // Or specify a driver: // $driver = $this->urlDetectionManager->driver('two_captcha'); $response = $driver->check($urlToCkeck); if ($response->isWeChatRiskWarning()) { return response()->json([ 'url' => $urlToCkeck, 'is_risky' => true, 'title' => $response->getWordingTitle(), 'message' => $response->getWording() ]); } else { return response()->json([ 'url' => $urlToCkeck, 'is_risky' => false, 'message' => 'URL seems safe.' ]); } } } // Alternatively, resolving a specific driver directly (less common for default usage) // $twoCaptchaDriver = app(\Weijiajia\TencentUrlDetection\Drivers\TwoCaptcha::class);
Accessing Configuration: The drivers will automatically use the configuration published to
config/tencent-url-detection.phpwhen instantiated via theDriversManager.
Standalone Usage (Non-Laravel)
First, you need to choose and instantiate a driver. The response object will tell you if the URL is considered safe and provide any warning messages from Tencent.
use Weijiajia\TencentUrlDetection\Drivers\CgiUrlsecQq; use Weijiajia\TencentUrlDetection\Drivers\Rrbay; use Weijiajia\TencentUrlDetection\Drivers\TwoCaptcha as TwoCaptchaDriver; // Alias to avoid conflict use TwoCaptcha\TwoCaptcha; // The 2Captcha solver service $urlToCkeck = 'https://example.com'; // Example 1: Using CgiUrlsecQq (may require captcha if used frequently) $cgiDriver = new CgiUrlsecQq(); $response = $cgiDriver->check($urlToCkeck); if ($response->isWeChatRiskWarning()) { echo "URL is risky: " . $response->getWordingTitle() . " - " . $response->getWording(); } else { echo "URL seems safe."; } // Example 2: Using Rrbay // Replace 'YOUR_RRBAY_KEY' with your actual Rrbay API key $rrbayKey = 'YOUR_RRBAY_KEY'; $rrbayDriver = new Rrbay($rrbayKey); $responseRrbay = $rrbayDriver->check($urlToCkeck); if ($responseRrbay->isWeChatRiskWarning()) { echo "Rrbay: URL is risky."; } else { echo "Rrbay: URL seems safe."; } // Example 3: Using TwoCaptcha driver // Replace 'YOUR_2CAPTCHA_API_KEY' with your actual 2Captcha API key $twoCaptchaApiKey = 'YOUR_2CAPTCHA_API_KEY'; $tencentCaptchaAppId = '2046626881'; // Default Tencent captcha appid, can be overridden $captchaSolver = new TwoCaptcha($twoCaptchaApiKey); $twoCaptchaDriver = new TwoCaptchaDriver($captchaSolver, $tencentCaptchaAppId); $responseTwoCaptcha = $twoCaptchaDriver->check($urlToCkeck); if ($responseTwoCaptcha->isWeChatRiskWarning()) { echo "2Captcha: URL is risky: " . $responseTwoCaptcha->getWordingTitle() . " - " . $responseTwoCaptcha->getWording(); } else { echo "2Captcha: URL seems safe."; } // Accessing the original Saloon response if needed $saloonResponse = $response->getOriginalResponse(); // $rawBody = (string) $saloonResponse->getBody(); // $jsonData = $saloonResponse->json();
Response Object
The check() method returns a Weijiajia\TencentUrlDetection\Response object with the following methods:
getUrl(): string: Returns the URL that was checked.isSafe(): bool: Returnstrueif the URL is considered safe,falseotherwise.isWeChatRiskWarning(): bool: Returnstrueif Tencent flags it as a risk (opposite ofisSafe()).getWordingTitle(): ?string: Returns the title of the warning message from Tencent, if any.getWording(): ?string: Returns the detailed warning message from Tencent, if any.getOriginalResponse(): \Saloon\Http\Response: Returns the original Saloon response object for advanced use cases.
Testing
The package uses PestPHP for testing. To run the tests:
# Run all tests composer test # Run tests with coverage report (requires Xdebug or PCOV) composer test-coverage
Code Styling
This project uses PHP CS Fixer to enforce PSR-12 coding standards.
# Check for coding style violations composer cs-check # Automatically fix coding style violations composer cs-fix
Contributing
Contributions are welcome! Please feel free to submit a pull request or create an issue for any bugs or feature requests.
- Fork the repository.
- Create your feature branch (`
weijiajia/tencent-url-detection 适用场景与选型建议
weijiajia/tencent-url-detection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「url」 「captcha」 「detection」 「wechat」 「qq」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 weijiajia/tencent-url-detection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 weijiajia/tencent-url-detection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 weijiajia/tencent-url-detection 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
Provide a way to secure accesses to all routes of an symfony application.
Easy URL rewrites in your Laravel application
Two Captcha
It's a barebone security class written on PHP
A Laravel helper to detect if the current route/path is active.
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-22