igengx
This commit is contained in:
@@ -14,8 +14,11 @@ namespace app\common\service\esign {
|
||||
public static array $identity = ['status' => 'INIT'];
|
||||
public static int $starts = 0;
|
||||
public static int $creates = 0;
|
||||
public static string $newAccountId = 'bound-account';
|
||||
public static string $requestedName = '';
|
||||
public static ?string $mobile = null;
|
||||
public static bool $expired = false;
|
||||
public static ?\Closure $checkCertificate = null;
|
||||
public static ?\Closure $duringStart = null;
|
||||
public static ?\Closure $duringRecipientLookup = null;
|
||||
public static ?string $account = null;
|
||||
@@ -29,6 +32,7 @@ namespace app\common\service\esign {
|
||||
{
|
||||
++self::$starts;
|
||||
self::$account = $accountId;
|
||||
self::$requestedName = $name;
|
||||
if (self::$duringStart) {
|
||||
(self::$duringStart)();
|
||||
}
|
||||
@@ -71,7 +75,7 @@ namespace app\common\service\esign {
|
||||
throw new \RuntimeException('Identity proof mismatch');
|
||||
}
|
||||
++self::$creates;
|
||||
return 'bound-account';
|
||||
return self::$newAccountId;
|
||||
}
|
||||
|
||||
public function signingAccount(string $accountId): array
|
||||
@@ -82,6 +86,9 @@ namespace app\common\service\esign {
|
||||
|
||||
public function certificateValidity(string $accountId): array
|
||||
{
|
||||
if (self::$checkCertificate) {
|
||||
return (self::$checkCertificate)($accountId);
|
||||
}
|
||||
return ['startDate' => '2024-01-01 08:00:00',
|
||||
'endDate' => self::$expired ? '2024-02-01 08:00:00' : '2099-01-01 08:00:00'];
|
||||
}
|
||||
@@ -107,6 +114,7 @@ namespace {
|
||||
use app\common\service\esign\DoctorEsignAuthorizationRequired;
|
||||
use app\common\service\esign\DoctorEsignIdentityService as Enrollment;
|
||||
use app\common\service\esign\EsignClient as Provider;
|
||||
use app\common\service\esign\EsignProviderException;
|
||||
use think\facade\Db;
|
||||
use think\Container;
|
||||
|
||||
@@ -128,7 +136,8 @@ namespace {
|
||||
Db::execute($sql);
|
||||
Db::execute($sql);
|
||||
}
|
||||
Db::execute('CREATE TABLE zyt_admin (id INTEGER PRIMARY KEY,name TEXT,disable INTEGER DEFAULT 0,delete_time INTEGER)');
|
||||
Db::execute('CREATE TABLE zyt_config (id INTEGER PRIMARY KEY,type TEXT,name TEXT,value TEXT,create_time INTEGER,update_time INTEGER)');
|
||||
Db::execute('CREATE TABLE zyt_admin (id INTEGER PRIMARY KEY,name TEXT,disable INTEGER DEFAULT 0,delete_time INTEGER,root INTEGER DEFAULT 0)');
|
||||
Db::execute('CREATE TABLE zyt_admin_role (admin_id INTEGER,role_id INTEGER)');
|
||||
Db::execute('CREATE TABLE zyt_doctor_esign_account (doctor_id INTEGER,environment TEXT,app_id TEXT,account_id TEXT,
|
||||
doctor_name TEXT,create_time INTEGER,UNIQUE(doctor_id,environment,app_id))');
|
||||
@@ -145,7 +154,7 @@ namespace {
|
||||
$throws = static function (callable $operation, string $expected, string $message) use ($assert): void {
|
||||
try {
|
||||
$operation();
|
||||
} catch (DomainException $error) {
|
||||
} catch (Throwable $error) {
|
||||
$assert(is_a($error, $expected), $message);
|
||||
return;
|
||||
}
|
||||
@@ -155,7 +164,8 @@ namespace {
|
||||
$phone = '13800000000';
|
||||
$assert(Enrollment::status(1)['enabled'] === false, 'SMS enrollment defaults off');
|
||||
$config->set(['doctor_sms_enabled' => true], 'esign');
|
||||
$assert(Enrollment::status(1)['status'] === 'unbound', 'doctor starts unbound');
|
||||
$unbound = Enrollment::status(1);
|
||||
$assert($unbound['status'] === 'unbound' && !isset($unbound['certificate_state']), 'doctor starts unbound');
|
||||
$throws(static fn () => Enrollment::status(3), DomainException::class, 'non-physician denied');
|
||||
$throws(static fn () => Enrollment::willingnessRecipient(1, Provider::NAME, ''), DoctorEsignIdentityRequired::class, 'setup-required reason distinguishes an unbound doctor');
|
||||
|
||||
@@ -180,14 +190,46 @@ namespace {
|
||||
$assert($pending['status'] === 'binding_required' && $pending['identity_details_required'] && !isset($pending['auth_url'])
|
||||
&& Provider::$creates === 0, 'successful polling exposes only safe metadata and accepts masked identity as supplemental');
|
||||
$assert(Enrollment::complete(1, 'bad-input')['identity_details_required'] && Provider::$creates === 0, 'invalid supplemental number never reaches SDK');
|
||||
$assert(Enrollment::complete(1, Provider::DOCUMENT)['status'] === 'needs_mobile' && Provider::$creates === 1,
|
||||
$withoutMobile = Enrollment::complete(1, Provider::DOCUMENT);
|
||||
$assert($withoutMobile['status'] === 'needs_mobile' && $withoutMobile['certificate_state'] === 'valid' && Provider::$creates === 1,
|
||||
'successful provider proof binds without signing, but an absent provider authorization is not ready');
|
||||
$assert(Db::name('doctor_esign_identity')->count() === 0 && !str_contains(json_encode(Db::name('doctor_esign_account')->find()), Provider::DOCUMENT),
|
||||
'completed enrollment clears hosted URL and does not persist identity number');
|
||||
|
||||
$throws(static fn () => Enrollment::willingnessRecipient(1, Provider::NAME, 'bound-account'), DoctorEsignIdentityRequired::class, 'willingness requires a current authorized mobile');
|
||||
|
||||
$boundAccount = Db::name('doctor_esign_account')->where('doctor_id', 1)->find();
|
||||
Provider::$checkCertificate = static function (string $accountId) use ($assert): array {
|
||||
$assert($accountId === 'bound-account', 'certificate query uses the current signing account');
|
||||
return ['startDate' => '2098-01-01 08:00:00', 'endDate' => '2099-01-01 08:00:00'];
|
||||
};
|
||||
$futureCertificate = Enrollment::status(1);
|
||||
$assert($futureCertificate['status'] === 'renewal_required' && $futureCertificate['certificate_state'] === 'renewal_required',
|
||||
'certificate validity must have already started');
|
||||
Provider::$checkCertificate = static fn () => ['startDate' => '2024-01-01 08:00:00', 'endDate' => '2024-01-01 08:00:00'];
|
||||
$assert(Enrollment::status(1)['certificate_state'] === 'renewal_required', 'an empty validity period cannot authorize signing');
|
||||
Provider::$checkCertificate = static fn () => ['startDate' => '2024-02-30 08:00:00', 'endDate' => '2099-01-01 08:00:00'];
|
||||
$badCertificate = Enrollment::status(1);
|
||||
$assert($badCertificate['status'] === 'renewal_required' && $badCertificate['certificate_state'] === 'unconfirmed'
|
||||
&& $badCertificate['cert_expires_at'] === 0, 'unparseable dates cannot establish certificate validity');
|
||||
$throws(static fn () => Enrollment::start(1, $phone), DomainException::class, 'malformed dates cannot begin renewal');
|
||||
Provider::$checkCertificate = static fn () => throw new EsignProviderException('certificateValidity', 'TIMEOUT');
|
||||
$timeout = Enrollment::status(1);
|
||||
$assert($timeout['certificate_state'] === 'unconfirmed' && $timeout['cert_expires_at'] === 0 && !isset($timeout['auth_url'])
|
||||
&& !str_contains(json_encode($timeout), 'TIMEOUT'), 'a transient query failure reports uncertainty without provider data');
|
||||
$throws(static fn () => Enrollment::start(1, $phone), EsignProviderException::class, 'a transient failure preserves the retry path');
|
||||
Provider::$checkCertificate = static fn () => throw new EsignProviderException('certificateValidity', 'PROVIDER_123');
|
||||
$providerRejection = Enrollment::status(1);
|
||||
$assert($providerRejection['certificate_state'] === 'unconfirmed' && $providerRejection['cert_expires_at'] === 0
|
||||
&& !str_contains(json_encode($providerRejection), 'PROVIDER_123') && Provider::$starts === 1
|
||||
&& Db::name('doctor_esign_account')->where('doctor_id', 1)->find() === $boundAccount
|
||||
&& Db::name('doctor_esign_identity')->count() === 0, 'recheck does not initiate or mutate enrollment on provider rejection');
|
||||
Provider::$checkCertificate = null;
|
||||
$assert(Enrollment::status(1)['certificate_state'] === 'valid', 'a later recheck can confirm the existing certificate');
|
||||
Provider::$expired = true;
|
||||
$assert(Enrollment::status(1)['status'] === 'renewal_required', 'expired provider certificate requires renewal');
|
||||
$expired = Enrollment::status(1);
|
||||
$assert($expired['status'] === 'renewal_required' && $expired['certificate_state'] === 'renewal_required',
|
||||
'expired provider certificate requires renewal');
|
||||
Provider::$identity = ['status' => 'INIT'];
|
||||
$assert(Enrollment::start(1, $phone)['status'] === 'authenticating' && Provider::$account === 'bound-account', 'renewal reuses canonical account');
|
||||
Provider::$identity = ['status' => 'SUCCESS', 'indivInfo' => null];
|
||||
@@ -195,7 +237,8 @@ namespace {
|
||||
Provider::$expired = false;
|
||||
$assert(Enrollment::status(1)['identity_details_required'] === false, 'a bound account needs no supplemental input');
|
||||
$ready = Enrollment::complete(1);
|
||||
$assert($ready['status'] === 'ready' && $ready['cert_expires_at'] === strtotime('2099-01-01T00:00:00Z') && Provider::$creates === 1,
|
||||
$assert($ready['status'] === 'ready' && $ready['certificate_state'] === 'valid'
|
||||
&& $ready['cert_expires_at'] === strtotime('2099-01-01T00:00:00Z') && Provider::$creates === 1,
|
||||
'same account becomes ready with certificate date in configured SDK timezone');
|
||||
$assert(!str_contains(json_encode($ready), $phone) && !str_contains(json_encode($ready), Provider::DOCUMENT), 'status never returns provider identity');
|
||||
$recipient = Enrollment::willingnessRecipient(1, Provider::NAME, 'bound-account');
|
||||
@@ -207,6 +250,15 @@ namespace {
|
||||
Provider::$mobile = null;
|
||||
Db::name('doctor_esign_account')->where('doctor_id', 1)->update(['account_id' => 'bound-account']);
|
||||
|
||||
Provider::$identity = ['status' => 'INIT'];
|
||||
Provider::$checkCertificate = static fn () => throw new EsignProviderException('certificateValidity', 'PROVIDER_123');
|
||||
$assert(Enrollment::start(1, $phone)['status'] === 'authenticating' && Provider::$account === 'bound-account',
|
||||
'explicit renewal on provider rejection reuses the canonical account');
|
||||
Provider::$checkCertificate = null;
|
||||
Provider::$identity = ['status' => 'SUCCESS', 'indivInfo' => null];
|
||||
$assert(Enrollment::complete(1)['certificate_state'] === 'valid' && Provider::$creates === 1,
|
||||
'successful same-account recheck does not create another account');
|
||||
|
||||
$assert(!Enrollment::quickEnabled(), 'quick-sign is disabled by default');
|
||||
$config->set(['doctor_sms_enabled' => false, 'doctor_quicksign_enabled' => true], 'esign');
|
||||
$quickReady = Enrollment::status(1);
|
||||
@@ -240,9 +292,9 @@ namespace {
|
||||
'provider face verification alone does not activate grant');
|
||||
$quickGranted = Enrollment::complete(1);
|
||||
$assert($quickGranted['status'] === 'ready' && !$quickGranted['quicksign_authorizing']
|
||||
&& $quickGranted['quicksign_expires_at'] === $now + 86400 && $quickGranted['quicksign_remaining_times'] === 2
|
||||
&& $quickGranted['quicksign_expires_at'] === $now + 3 * 86400 && $quickGranted['quicksign_remaining_times'] === 2
|
||||
&& !str_contains(json_encode($quickGranted), 'quick-proof') && !str_contains(json_encode($quickGranted), Provider::DOCUMENT),
|
||||
'confirmed provider proof is capped to 24 hours and remains server-only');
|
||||
'confirmed provider proof follows provider expiry and remains server-only');
|
||||
$quickRow = Db::name('doctor_esign_quicksign')->where('doctor_id', 1)->find();
|
||||
$assert($quickRow['flow_id'] === 'quick-proof-1' && $quickRow['auth_url'] === null
|
||||
&& Db::name('doctor_esign_identity')->count() === 0 && Provider::$creates === 1, 'grant clears its hosted link and keeps enrollment untouched');
|
||||
@@ -271,7 +323,7 @@ namespace {
|
||||
Provider::$willingnessValid = false;
|
||||
$spent = Enrollment::status(1);
|
||||
$assert($spent['quicksign_expires_at'] === 0 && $spent['quicksign_remaining_times'] === 0
|
||||
&& $spent['quicksign_unavailable_reason'] === 'exhausted' && $spent['status'] === 'ready',
|
||||
&& $spent['quicksign_unavailable_reason'] === 'exhausted' && $spent['status'] === 'ready' && $spent['certificate_state'] === 'valid',
|
||||
'provider exhaustion leaves certificate enrollment valid and reports the spent grant');
|
||||
$throws(static fn () => Enrollment::quickAuthorization(1, Provider::NAME, 'bound-account'), DoctorEsignAuthorizationRequired::class,
|
||||
'provider cancellation/exhaustion blocks dispatch');
|
||||
@@ -291,5 +343,33 @@ namespace {
|
||||
$assert(Enrollment::start(1, '')['quicksign_authorizing'] && Provider::$quickStarts === 2, 'expired grant permits a new standalone grant');
|
||||
Provider::$identity = ['status' => 'SUCCESS', 'indivInfo' => null];
|
||||
$assert(Enrollment::complete(1)['quicksign_expires_at'] === $now + 120, 'provider validity is preserved when shorter than the local bound');
|
||||
|
||||
$config->set(['review_enabled' => true], 'esign');
|
||||
Db::name('admin')->insert(['id' => 4, 'name' => 'admin', 'root' => 1]);
|
||||
Provider::$identity = ['status' => 'INIT'];
|
||||
Provider::$newAccountId = 'reviewer-account';
|
||||
$startsBeforeReview = Provider::$starts;
|
||||
$assert(Enrollment::status(4)['can_edit_signer_name'] === true, 'an unbound reviewer can supply a separate legal name');
|
||||
$throws(static fn () => Enrollment::start(2, $phone, Provider::NAME), DomainException::class,
|
||||
'the reviewer-only input does not override a physician roster name');
|
||||
$throws(static fn () => Enrollment::start(4, $phone, '<姓名>'), DomainException::class,
|
||||
'invalid names are rejected before contacting eSign');
|
||||
$oldReview = Enrollment::start(4, $phone);
|
||||
$newReview = Enrollment::start(4, $phone, Provider::NAME);
|
||||
$assert($newReview['auth_url'] !== $oldReview['auth_url'] && Provider::$requestedName === Provider::NAME
|
||||
&& Enrollment::status(4)['can_edit_signer_name'] && Provider::$starts === $startsBeforeReview + 2,
|
||||
'correcting an unfinished reviewer name requests a new provider URL');
|
||||
$assert(Enrollment::start(4, $phone, Provider::NAME) === $newReview && Provider::$starts === $startsBeforeReview + 2,
|
||||
'resubmitting the same name and number restores the pending flow');
|
||||
Provider::$identity = ['status' => 'SUCCESS', 'indivInfo' => ['name' => Provider::NAME,
|
||||
'certType' => 'INDIVIDUAL_CH_IDCARD', 'certNo' => Provider::DOCUMENT]];
|
||||
$assert(Enrollment::start(4, $phone, '错误姓名')['status'] === 'binding_required' && Provider::$starts === $startsBeforeReview + 2,
|
||||
'an already verified identity cannot be replaced on retry');
|
||||
$assert(Enrollment::complete(4)['status'] === 'ready'
|
||||
&& Db::name('doctor_esign_account')->where('doctor_id', 4)->value('doctor_name') === Provider::NAME
|
||||
&& Db::name('admin')->where('id', 4)->value('name') === 'admin',
|
||||
'verified legal name is saved only to the reviewer signing account');
|
||||
$throws(static fn () => Enrollment::start(4, $phone, '不同姓名'), DomainException::class,
|
||||
'a verified signing account cannot be renamed through enrollment');
|
||||
echo "Doctor eSign enrollment: $checks checks passed (SQLite and provider doubles)\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user