feat: 实现TCP Server
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace app\net\parsers;
|
||||
|
||||
use app\net\parsers\PacketParserInterface;
|
||||
|
||||
/**
|
||||
* 有线读卡器报文解析器(长度20)
|
||||
*/
|
||||
class WiredReaderParser implements PacketParserInterface
|
||||
{
|
||||
public function supports(string $hexString): bool
|
||||
{
|
||||
return strlen($hexString) === 20;
|
||||
}
|
||||
|
||||
public function parse(string $hexString): array
|
||||
{
|
||||
$pattern = '/(09[a-fA-F0-9]{8})([a-fA-F0-9]{10})/';
|
||||
if (preg_match($pattern, $hexString, $matches)) {
|
||||
return [
|
||||
'hexType' => 1,
|
||||
'isMatched' => true,
|
||||
'reader' => $matches[1],
|
||||
'card' => $matches[2],
|
||||
];
|
||||
}
|
||||
return ['isMatched' => false];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user