定制 laulamanapps/google-wallet 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laulamanapps/google-wallet

Composer 安装命令:

composer require laulamanapps/google-wallet

包简介

Generate Google Wallet passes from PHP

README 文档

README

Generate Google Wallet passes from PHP. The Google counterpart of laulamanapps/apple-passbook.

Passes are distributed via "Add to Google Wallet" links: an RS256-signed JWT whose payload embeds the pass classes and objects (a so-called "fat JWT"). Because the classes and objects travel inside the JWT, no Google Wallet REST API call is needed — the only dependency is ext-openssl for signing.

Installation

composer require laulamanapps/google-wallet

Or use one of the framework integrations, which wire the service account and save-URL factory from configuration:

Service account setup

  1. Sign up for a Google Wallet issuer account in the Google Pay & Wallet Console and note your issuer id.
  2. Create a Google Cloud service account with the Wallet Object Issuer role and download its JSON key file.
  3. Link the service account to your issuer account in the console.

Quickstart

use LauLamanApps\GoogleWallet\Object\Barcode;
use LauLamanApps\GoogleWallet\Object\BarcodeType;
use LauLamanApps\GoogleWallet\Object\GenericClass;
use LauLamanApps\GoogleWallet\Object\GenericObject;
use LauLamanApps\GoogleWallet\Object\Image;
use LauLamanApps\GoogleWallet\Object\TextModule;
use LauLamanApps\GoogleWallet\PassPayload;
use LauLamanApps\GoogleWallet\SaveUrlFactory;
use LauLamanApps\GoogleWallet\ServiceAccount;

$serviceAccount = ServiceAccount::fromJsonFile('/path/to/service-account.json');

// Ids are '<issuerId>.<identifier>'
$object = new GenericObject('3388000000012345678.member-0001', '3388000000012345678.membership');
$object->setCardTitle('ACME Membership');
$object->setHeader('John Doe');
$object->setSubheader('Gold member');
$object->setHexBackgroundColor('#4285f4');
$object->setLogo(Image::fromUri('https://example.com/logo.png', 'ACME logo'));
$object->setBarcode(new Barcode(BarcodeType::QrCode, 'member-0001'));
$object->addTextModule(new TextModule('Member since', '2020'));

$payload = new PassPayload();
$payload->addGenericClass(new GenericClass('3388000000012345678.membership'));
$payload->addGenericObject($object);

$factory = new SaveUrlFactory($serviceAccount, ['https://example.com']);
$saveUrl = $factory->create($payload);
// https://pay.google.com/gp/v/save/eyJhbGciOiJSUzI1NiIs...

Render the url as an Add to Google Wallet button and you are done.

Pass types

Next to GenericClass/GenericObject the same pattern is available for:

  • EventTicketClass / EventTicketObject
  • OfferClass / OfferObject
  • LoyaltyClass / LoyaltyObject
  • TransitClass / TransitObject

Add them to the PassPayload with the matching add*Class()/add*Object() methods.

Signing a JWT yourself

SaveUrlFactory covers the common case. If you need the raw JWT, use JwtSigner directly:

use LauLamanApps\GoogleWallet\JwtSigner;

$signer = new JwtSigner($serviceAccount);
$jwt = $signer->sign([
    'iss' => $serviceAccount->getClientEmail(),
    'aud' => 'google',
    'typ' => 'savetowallet',
    'iat' => time(),
    'origins' => ['https://example.com'],
    'payload' => $payload->toArray(),
]);

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 5
  • 推荐数: 3

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固