| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- declare(strict_types=1);
- namespace app\miniapi\auth;
- use app\miniapi\exception\ApiException;
- /** Explicit fixture identities, never verified phone numbers or WeChat accounts. */
- final class TestPhoneIdentityProvider implements IdentityProvider
- {
- public const APP_ID = 'local-test-phone';
- public const PHONES = [
- 'enterprise_admin' => '13012345678',
- 'driver' => '13012345679',
- 'agent' => '13012345680',
- ];
- public function __construct(private readonly string $phone)
- {
- }
- public static function enabled(): bool
- {
- return config('mini_api.test_phone_login', false) === true;
- }
- public function exchange(string $code): array
- {
- if (!self::enabled()) {
- throw new ApiException(50301, '测试手机号登录未开启', 503);
- }
- if (!in_array($this->phone, self::PHONES, true) || !hash_equals('66666', $code)) {
- throw new ApiException(40102, '测试手机号或验证码错误', 401);
- }
- return ['appid' => self::APP_ID, 'openid' => $this->phone];
- }
- }
|