weijiajia/decrypt-verification-code 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

weijiajia/decrypt-verification-code

最新稳定版本:0.0.2

Composer 安装命令:

composer require weijiajia/decrypt-verification-code

包简介

A PHP package for decoding CAPTCHA verification codes using the jfbym.com cloud service API

README 文档

README

A PHP package for decoding CAPTCHA verification codes using the jfbym.com cloud service API.

Description

This package provides a simple interface for decrypting various types of verification code images by leveraging the jfbym.com API. It uses the Saloon HTTP client library for making API requests and handling responses.

Installation

You can install the package via composer:

composer require weijiajia/decrypt-verification-code

Requirements

  • PHP 8.0 or higher
  • Saloon HTTP client
  • A valid API token from jfbym.com

Usage

Basic Usage

use Weijiajia\DecryptVerificationCode\CloudCode\CloudCodeConnector;

// Create a new connector instance
$connector = new CloudCodeConnector();

try {
    // Decode a verification code
    $response = $connector->decryptCloudCode(
        token: 'your-api-token',
        type: 'captcha-type-code', // Specific type code for the CAPTCHA format
        image: 'base64-encoded-image-data' // Base64 encoded image data
    );
    
    // Get the decoded verification code
    $code = $response->getCode();
    echo "Decoded CAPTCHA: " . $code;
    
} catch (DecryptCloudCodeException $e) {
    // Handle API-specific errors
    echo "API Error: " . $e->getMessage() . " (Code: " . $e->getCode() . ")";
} catch (\Exception $e) {
    // Handle other exceptions
    echo "Error: " . $e->getMessage();
}

Response Structure

The API response is mapped to a CloudCodeResponse object with the following structure:

CloudCodeResponse {
    public string $msg,
    public int $code,
    public Data $data {
        public int $code,
        public string $data, // The decoded verification code
        public float $time,
        public string $unique_code
    }
}

With Logging

The connector supports logging functionality via the HasLogger trait:

use Psr\Log\LoggerInterface;
use Weijiajia\DecryptVerificationCode\CloudCode\CloudCodeConnector;

// Create a PSR-3 compatible logger
$logger = /* your PSR-3 logger */;

// Create a connector with logging
$connector = new CloudCodeConnector();
$connector->setLogger($logger);

// Now API requests and responses will be logged
$response = $connector->decryptCloudCode(
    token: 'your-api-token',
    type: 'captcha-type-code',
    image: 'base64-encoded-image-data'
);

Error Handling

The package throws a DecryptCloudCodeException when the API returns an error. The exception includes the error message and code from the API response.

try {
    $response = $connector->decryptCloudCode(/* ... */);
} catch (DecryptCloudCodeException $e) {
    // API returned an error
    echo "API Error: " . $e->getMessage() . " (Code: " . $e->getCode() . ")";
} catch (JsonException $e) {
    // JSON parsing error
    echo "JSON Error: " . $e->getMessage();
} catch (RequestException $e) {
    // Request failed
    echo "Request Error: " . $e->getMessage();
} catch (FatalRequestException $e) {
    // Fatal request error
    echo "Fatal Request Error: " . $e->getMessage();
}

API Reference

CloudCodeConnector

decryptCloudCode(string $token, string $type, string $image): CloudCodeResponseInterface

Sends a request to the jfbym.com API to decode a verification code image.

Parameters:

  • $token - Your API authentication token
  • $type - The type code that specifies the CAPTCHA format
  • $image - Base64 encoded image data

Returns:

  • A CloudCodeResponseInterface object containing the decoded verification code

License

This package is open-sourced software licensed under the MIT license.

Credits

  • [Author Name]
  • [All Contributors]

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-08