PHP code example of weijiajia / decrypt-verification-code

1. Go to this page and download the library: Download weijiajia/decrypt-verification-code library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

weijiajia / decrypt-verification-code example snippets


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();
}

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

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'
);

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();
}