-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Automatically sovle captcha * feat(README): Add example --------- Co-authored-by: ging-dev <[email protected]>
- Loading branch information
1 parent
cbffdff
commit 1db2cb8
Showing
17 changed files
with
212 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## IPay Unoffical Client | ||
|
||
```php | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use IPay\IPayClient; | ||
|
||
require __DIR__.'/vendor/autoload.php'; | ||
|
||
$ipay = IPayClient::create(); | ||
|
||
try { | ||
$session = $ipay->guest()->login([ | ||
'userName' => 'yourUsername', | ||
'accessCode' => 'yourPassword' | ||
]); | ||
|
||
$accountNumber = $session->customer()->accountNumber; | ||
|
||
foreach ($session->historyTransactions([ | ||
'accountNumber' => $accountNumber, | ||
'startDate' => new \DateTimeImmutable('-5 days'), | ||
]) as $transaction) { | ||
echo $transaction->remark.PHP_EOL; | ||
} | ||
} catch (Throwable $e) { | ||
echo $e->getMessage(); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace IPay\Captcha; | ||
|
||
use Symfony\Component\DomCrawler\Crawler; | ||
|
||
final class CaptchaSolver | ||
{ | ||
private const LENGTH_TO_NUMBER_MAPPING = [ | ||
66 => 0, | ||
49 => 1, | ||
53 => 2, | ||
70 => 3, | ||
76 => 4, | ||
58 => 5, | ||
64 => 6, | ||
50 => 7, | ||
75 => 8, | ||
69 => 9, | ||
]; | ||
|
||
public static function solve(string $svg): string | ||
{ | ||
/** @var string[] */ | ||
$svgPathCommands = (new Crawler($svg)) | ||
->filterXPath('//path[@fill!="none"]') | ||
->each(function (Crawler $node): string { | ||
return (string) $node->attr('d'); | ||
}); | ||
|
||
sort($svgPathCommands, SORT_NATURAL); | ||
|
||
$result = ''; | ||
foreach ($svgPathCommands as $svgPathCommand) { | ||
/** @var string */ | ||
$symbolicPath = preg_replace('/[^A-Z]/', '', $svgPathCommand); | ||
$result .= static::LENGTH_TO_NUMBER_MAPPING[ | ||
strlen($symbolicPath) | ||
]; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
use IPay\Captcha\CaptchaSolver; | ||
|
||
test('captcha solver', function (string $filename, string $result) { | ||
$svg = file_get_contents($filename); | ||
expect(CaptchaSolver::solve($svg))->toBe($result); | ||
})->with([ | ||
'captcha 1' => [__DIR__.'/Fixture/1.svg', '540701'], | ||
'captcha 2' => [__DIR__.'/Fixture/2.svg', '826778'], | ||
'captcha 3' => [__DIR__.'/Fixture/3.svg', '835697'], | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
// nothing |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.