causal/dgc

根据eHealth网络定义的解码数字绿色证书的库

1.4 2021-09-08 07:52 UTC

This package is auto-updated.

Last update: 2024-09-08 14:26:00 UTC


README

DGC是一个PHP库,用于解码数字绿色证书。简而言之,它解码COVID-19证书。

安装

使用composer进行安装。

$ composer require causal/dgc

用法

$decoder = new \Causal\DGC\Decoder();

// The string as embedded in the QR code of the certificate (e.g., you can use https://qrafter.com/)
$input = 'HC1:NCFOXNYTSFDHJI89.O%26V$L.BUTRDUV...';

// Extract issuer, issuing date, expiring date, type of vaccine, manufacturer, etc.
$data = $decoder->decodeFromQR($input);
{
  1: "DE",
  4: 1643356073,
  6: 1622316073,
  -260: {
    1: {
      v: [
        {
          ci: "URN:UVCI:01DE/IZ12345A/5CWLU12RNOB9RXSEOP6FG8#W",
          co: "DE",
          dn: 2,
          dt: "2021-05-29",
          is: "Robert Koch-Institut",
          ma: "ORG-100031184",
          mp: "EU/1/20/1507",
          sd: 2,
          tg: "840539006",
          vp: "1119349007"
        }
      ],
      dob: "1964-08-12",
      nam: {
        fn: "Mustermann",
        gn: "Erika",
        fnt: "MUSTERMANN",
        gnt: "ERIKA"
      },
      ver: "1.0.0"
    }
  }
}

您可以将数据格式化,使其更易于阅读

// Basically this returns the exact same data you read in the official Swiss app "Covid Cert"
$humanReadableData = $decoder->prettify($data);
{
  issuer: "DE",
  issuingDate: "2021-05-29T21:21:13+02:00",
  expiringDate: "2022-01-28T08:47:53+01:00",
  certificate: {
    type: "vaccination",
    person: {
      familyName: "Mustermann",
      givenName: "Erika",
      familyNameTransliterated: "MUSTERMANN",
      givenNameTransliterated: "ERIKA",
      dateOfBirth: "1964-08-12"
    },
    info: {
      singleDoses: 2,
      diseaseOrAgentTargeted: "COVID-19",
      vaccineType: "SARS-CoV2 mRNA vaccine",
      product: "COVID-19 Vaccine Moderna",
      manufacturer: "Moderna Biotech Spain S.L.",
      date: "2021-05-29",
      country: "DE",
      issuer: "Robert Koch-Institut",
      id: "URN:UVCI:01DE/IZ12345A/5CWLU12RNOB9RXSEOP6FG8#W"
    }
  }
}

证书类型

支持以下类型的证书

  • 疫苗接种证书
  • 检测证书
  • 康复证书

免责声明

  • 目前没有对数字签名进行检查(目前尚不清楚各种发行者的公钥是否对任何人可用)。
  • 可读性转换基于2021/08/30的欧洲数据映射。
  • 本库提供“现状”,使用风险自负!

参考

许可证

MIT许可证(MIT)。请参阅许可证文件获取更多信息。