mfiyalka / telegram-passport
Telegram Passport 库
v1.0.0
2018-08-02 14:53 UTC
This package is not auto-updated.
Last update: 2024-09-21 18:49:48 UTC
README
https://core.telegram.org/passport
安装
composer require mfiyalka/telegram-passport "*"
... "require": { "mfiyalka/telegram-passport": "*" } ...
生成私有密钥,并将其放置在 config/telegram 目录中
openssl genrsa 2048 > private.key
现在生成公共密钥,并将其也放置在 config/telegram 目录中,命名为 public.key
openssl rsa -in private.key -pubout
使用 @BotFather 的 /setpublickey 命令将此公共密钥与您的机器人关联。
将配置文件 /vendor/mfiyalka/telegram-passport/config/telegram_passport.php 复制到 /config 目录
示例
{
"passport_data": {
"data": [
{
"type": "personal_details",
"data": "..."
},
{
"type": "passport",
"data": "...",
"front_side": {
"file_id": "...",
"file_size": 1690656,
"file_date": 1532965670
}
},
{
"type": "driver_license",
"data": "",
"front_side": {
"file_id": "...",
"file_date": 1533211580
},
"reverse_side": {
"file_id": "...",
"file_date": 1533211580
}
},
{
"type": "address",
"data": "..."
},
{
"type": "utility_bill",
"files": [
{
"file_id": "...",
"file_date": 1532965834
},
{
"file_id": "...",
"file_date": 1533213517
}
]
},
{
"type": "rental_agreement",
"files": [
{
"file_id": "...",
"file_date": 1533213500
}
]
},
{
"type": "phone_number",
"phone_number": "..."
},
{
"type": "email",
"email": "..."
}
],
"credentials": {
"data": "...",
"hash": "...",
"secret": "..."
}
}
}
<?php use Mfiyalka\TelegramPassport\TelegramPassport; $passportData = new TelegramPassport($passportData); // Identity // // Personal Details $personalDetails = $passportData->getPersonalDetails(); $firstName = $personalDetails->firstName ?? null; $lastName = $personalDetails->lastName ?? null; $birthDate = $personalDetails->birthDate ?? null; $gender = $personalDetails->gender ?? null; $countryCode = $personalDetails->countryCode ?? null; $residenceCountryCode = $personalDetails->residenceCountryCode ?? null; // Passport $passport = $passportData->getPassport(); $passportDocumentNo = $passport->idDocumentData()->documentNo ?? null; $passportExpiryDate = $passport->idDocumentData()->expiryDate ?? null; $passportFrontSide = null; if ($passport->frontSide) { $toURL = __DIR__ . '/../../../public/img/'; $passportFrontSide = $passport->getFrontSide($toURL); } $passportSelfie = null; if ($passport->selfie) { $toURL = __DIR__ . '/../../../public/img/'; $passportSelfie = $passport->getSelfie($toURL); } // Drive License $driveLicense = $passportData->getDriveLicense(); $driveLicenseDocumentNo = $driveLicense->idDocumentData()->documentNo ?? null; $driveLicenseExpiryDate = $driveLicense->idDocumentData()->expiryDate ?? null; $driveLicenseFrontSide = null; if ($driveLicense->frontSide) { $toURL = __DIR__ . '/../../../public/img/'; $driveLicenseFrontSide = $driveLicense->getFrontSide($toURL); } $driveLicenseReverseSide = null; if ($driveLicense->reverseSide) { $toURL = __DIR__ . '/../../../public/img/'; $driveLicenseReverseSide = $driveLicense->getReverseSide($toURL); } $driveLicenseSelfie = null; if ($driveLicense->selfie) { $toURL = __DIR__ . '/../../../public/img/'; $driveLicenseSelfie = $driveLicense->getSelfie($toURL); } // Identity Card $identityCard = $passportData->getIdentityCard(); $identityCardDocumentNo = $identityCard->idDocumentData()->documentNo ?? null; $identityCardExpiryDate = $identityCard->idDocumentData()->expiryDate ?? null; $identityCardFrontSide = null; if ($identityCard->frontSide) { $toURL = __DIR__ . '/../../../public/img/'; $identityCardFrontSide = $identityCard->getFrontSide($toURL); } $identityCardReverseSide = null; if ($identityCard->reverseSide) { $toURL = __DIR__ . '/../../../public/img/'; $identityCardReverseSide = $identityCard->getReverseSide($toURL); } $identityCardSelfie = null; if ($identityCard->selfie) { $toURL = __DIR__ . '/../../../public/img/'; $identityCardSelfie = $identityCard->getSelfie($toURL); } // Internal Passport $internalPassportCard = $passportData->getInternalPassport(); $internalPassportDocumentNo = $internalPassportCard->idDocumentData()->documentNo ?? null; $internalPassportExpiryDate = $internalPassportCard->idDocumentData()->expiryDate ?? null; $internalPassportFrontSide = null; if ($internalPassportCard->frontSide) { $toURL = __DIR__ . '/../../../public/img/'; $internalPassportFrontSide = $internalPassportCard->getFrontSide($toURL); } $internalPassportSelfie = null; if ($internalPassportCard->selfie) { $toURL = __DIR__ . '/../../../public/img/'; $internalPassportSelfie = $internalPassportCard->getSelfie($toURL); } // Address // // Residential Address $residentialAddress = $passportData->getAddress(); $streetLine1 = $residentialAddress->streetLine1 ?? null; $streetLine2 = $residentialAddress->streetLine2 ?? null; $city = $residentialAddress->city ?? null; $state = $residentialAddress->state ?? null; $addresCountryCode = $residentialAddress->countryCode ?? null; $postCode = $residentialAddress->postCode ?? null; // Utility Bill $utilityBill = $passportData->getUtilityBill(); $utilityBillFiles = null; if (!is_null($utilityBill->files)) { $files = $utilityBill->files; $toURL = __DIR__ . '/../../../public/img/'; $utilityBillFiles = []; foreach ($files as $key => $item) { $utilityBillFiles[] = $utilityBill->getFile($key, $toURL); } } // Contact // $phoneNumber = $passportData->getPhoneNumber()->phoneNumber ?? null; $email = $passportData->getEmail()->email ?? null;