PHPackages                             weijiajia/tencent-url-detection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. weijiajia/tencent-url-detection

ActiveLibrary[Security](/categories/security)

weijiajia/tencent-url-detection
===============================

A PHP library to detect URL safety using Tencent URL security API, with support for multiple captcha solving services.

05PHP

Since May 22Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/jackchang1025/tencent-url-detection)[ Packagist](https://packagist.org/packages/weijiajia/tencent-url-detection)[ RSS](/packages/weijiajia-tencent-url-detection/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Tencent URL Detection for PHP
=============================

[](#tencent-url-detection-for-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/367c10257f1d459ccecfb199fc3230f63576b0eed20d7ae659f7587a526bc9b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7765696a69616a69612f74656e63656e742d75726c2d646574656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/weijiajia/tencent-url-detection)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![PHP Version Require](https://camo.githubusercontent.com/3a9516ac91260d9c369d4e5431c6226243da4ddbce51afe891d2c56aa70a6cf7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7765696a69616a69612f74656e63656e742d75726c2d646574656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/weijiajia/tencent-url-detection)

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
--------

[](#features)

- Easy integration with Tencent's URL safety check.
- Multiple drivers available:
    - `CgiUrlsecQq`: Direct check via `cgi.urlsec.qq.com` (may require captcha solving).
    - `Rrbay`: Uses the `rrbay.com` service for URL checking.
    - `TwoCaptcha`: Integrates with `2captcha.com` to solve Tencent's captchas before checking.
- Built on [SaloonPHP](https://docs.saloon.dev/) for robust HTTP requests.
- PSR-4 autoloading and PSR-12 coding standards (enforced by PHP CS Fixer).
- Comprehensive unit and feature tests using [PestPHP](https://pestphp.com/).

Requirements
------------

[](#requirements)

- PHP ^8.1
- Composer

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require weijiajia/tencent-url-detection
```

Laravel Integration (Optional)
------------------------------

[](#laravel-integration-optional)

This package includes a Service Provider for easy integration with the Laravel framework.

1. **Service Provider Auto-Discovery:**The `Weijiajia\TencentUrlDetection\TencentUrlDetectionServiceProvider` will be automatically discovered and registered by Laravel.
2. **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.php` file in your application. You should fill in your API keys and preferred settings in this file and, for security, add it to your `.gitignore` if it contains sensitive credentials.
3. **Usage in Laravel:**You can resolve the `DriversManager` or 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.php` when instantiated via the `DriversManager`.

Standalone Usage (Non-Laravel)
------------------------------

[](#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

[](#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`: Returns `true` if the URL is considered safe, `false` otherwise.
- `isWeChatRiskWarning(): bool`: Returns `true` if Tencent flags it as a risk (opposite of `isSafe()`).
- `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
-------

[](#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
------------

[](#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
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a pull request or create an issue for any bugs or feature requests.

1. Fork the repository.
2. Create your feature branch (`

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/636557533fde1107bb301eca908de1c17c9ea7073d5c9c0fbad725ccd0800bde?d=identicon)[jackchang1025](/maintainers/jackchang1025)

---

Top Contributors

[![422066139](https://avatars.githubusercontent.com/u/1780162?v=4)](https://github.com/422066139 "422066139 (6 commits)")

### Embed Badge

![Health badge](/badges/weijiajia-tencent-url-detection/health.svg)

```
[![Health](https://phpackages.com/badges/weijiajia-tencent-url-detection/health.svg)](https://phpackages.com/packages/weijiajia-tencent-url-detection)
```

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[roave/security-advisories

Prevents installation of composer packages with known security vulnerabilities: no API, simply require it

2.9k97.3M6.4k](/packages/roave-security-advisories)[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k16.7M113](/packages/mews-purifier)[robrichards/xmlseclibs

A PHP library for XML Security

41278.1M118](/packages/robrichards-xmlseclibs)[bjeavons/zxcvbn-php

Realistic password strength estimation PHP library based on Zxcvbn JS

86917.5M63](/packages/bjeavons-zxcvbn-php)[enlightn/security-checker

A PHP dependency vulnerabilities scanner based on the Security Advisories Database.

33732.2M110](/packages/enlightn-security-checker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
