Download the PHP package lemoba/mobile-monetization without Composer

On this page you can find all versions of the php package lemoba/mobile-monetization. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mobile-monetization

Mobile Monetization for Laravel

Laravel 扩展包,用于移动端短剧/内容应用常见的后端验证能力:

本包只做「可信验证、签名校验、接口封装、结果归一化、推送发送」,不创建数据表,不写数据库,不给用户加金币,不开通 VIP,不解锁视频。订单幂等、金币流水、会员权益、短剧解锁、推送 token 保存等业务逻辑全部由调用方完成。

安装

通过 Composer 安装:

发布配置:

环境变量

配置文件会按职责发布到主项目:

路由

本包不注册任何默认路由,由调用方在主项目中自行定义路由和控制器。示例:

缓存

JWKS、公钥集合、Google Play OAuth token、App Store Server API bearer token、FCM OAuth token 都会走 Laravel Cache,并默认使用 Redis:

调用方可以改 store 使用任意 Laravel cache store,但生产环境建议 Redis。

登录验证

Apple:

Google:

返回字段包含:

调用方应该用 provider + provider_user_id 去绑定或创建自己的用户。

provider_user_id 来自 Apple / Google ID token 的 sub 字段。本包会强制校验 sub,如果 token 中没有 sub 会直接抛出异常,不会返回空的 provider_user_id

支付验证

iOS App Store:

iOS App Store 订阅优惠签名:

applePromotionalOfferSignature() 参数:

客户端按 Apple StoreKit API 使用返回字段即可:

如配置了 APPLE_PROMOTIONAL_OFFER_KEY_ID / APPLE_PROMOTIONAL_OFFER_PRIVATE_KEY_PATH,会优先使用订阅优惠专用密钥;否则回退到 APPLE_KEY_ID / APPLE_PRIVATE_KEY_PATH

新版 StoreKit 2 promotional offer compact JWS:

applePromotionalOfferJws() 参数:

Android Google Play 一次性消耗商品:

一次性消耗商品适合金币、钻石、体力、道具包等可以反复购买的商品。服务端必须先请求 Google Play Developer API 验证 purchaseToken,验单成功后还要调用 Google 的 consume 接口;否则 Google Play 侧该购买 token 未被消费,同一个商品可能无法再次购买。

如果客户端把业务订单号放进 Google Billing 的 obfuscatedExternalProfileId,服务端可以先只用 purchaseToken 解析订单号,再查询自己的订单表判断这笔订单是订阅还是一次性消耗商品:

parseGoogleOrderNo() 返回:

推荐使用 verifyAndConsumeGoogleProduct() 一次完成“验单 + 消费”:

如果客户端没有单独上传 product_id,也可以只传 purchaseToken。服务端会调用 Google Play purchases.productsv2 查询购买信息,并从返回的 productLineItem[0].productId 补出商品 ID:

verifyAndConsumeGoogleProduct() 的行为:

如果业务需要把“验单、入库、发货、消费”拆成自己的事务流程,也可以手动调用:

一次性商品注意事项:

Android Google Play VIP 周/月/年订阅:

订阅适合 VIP 周卡、月卡、年卡等周期性权益。订阅不是消耗品,不需要也不能调用 consumeGoogleProduct()。服务端要做的是验证 purchaseToken,读取 Google 返回的订阅状态和到期时间,然后更新自己系统里的会员权益。

订阅返回的 VerifiedPurchase 里,常用字段包括:

订阅注意事项:

Android Google Play 订阅优惠:

Google Play 订阅优惠和 Apple promotional offer 不一样。Apple 需要服务端生成签名;Google Play 订阅优惠不需要服务端签名,服务端也拿不到一个需要签名后返回给客户端的优惠参数。

Google Play 订阅优惠流程:

  1. 客户端通过 Play Billing 查询 ProductDetails
  2. 客户端从 ProductDetails.SubscriptionOfferDetails 中选择一个优惠。
  3. 客户端使用该优惠的 offerToken 发起购买。
  4. 购买成功后,客户端把 Google 返回的 purchaseToken 发给服务端。
  5. 服务端调用 verifyGoogleSubscriptionOffer() 验证该购买确实来自期望的 basePlanId / offerId

服务端示例:

verifyGoogleSubscriptionOffer() 返回:

如果传入了 expectedBasePlanIdexpectedOfferId,服务端会与 Google 返回的 offerDetails 对比;不一致会抛出异常,不应该给用户发放该优惠权益。

统一返回对象:

关键字段:

建议调用方业务处理:

LevelPlay 激励广告

在 LevelPlay 后台配置 S2S Rewarded Video Callback URL:

本包不提供默认 HTTP 控制器,也不注册默认路由。调用方需要在主项目中自行创建回调入口,调用本包完成验签,并保存 event_id 做唯一幂等。

业务控制器示例:

本地测试如果不方便生成 LevelPlay 签名,可以传入第二个参数 true 开启 dev 模式,跳过 LEVELPLAY_SECRETsignature 校验:

verifyRewardCallback() 返回:

Firebase Cloud Messaging 推送

由于 Android 和 iOS 不在同一个 Firebase 后台,本包在 config/mobile-push.php 中分别配置两套 service account:

发送到单个设备 token:

发送到 Android:

发送到 topic:

data 会统一转成字符串值,符合 FCM HTTP v1 对 data payload 的要求。FCM OAuth token 会按平台和 service account 缓存在 Redis 中。

数据库说明

本包没有迁移文件,也不会调用 DB、Model 或 Schema。推荐调用方自行维护这些业务表或存储:


All versions of mobile-monetization with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
firebase/php-jwt Version ^7.0
illuminate/contracts Version ^9.0|^10.0|^11.0|^12.0
illuminate/http Version ^9.0|^10.0|^11.0|^12.0
illuminate/routing Version ^9.0|^10.0|^11.0|^12.0
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lemoba/mobile-monetization contains the following files

Loading the files please wait ...