chfur/appgallery-iap

PHP AppGallery In-App Purchase 实现

v1.2.0 2022-06-15 17:24 UTC

This package is auto-updated.

Last update: 2024-09-10 17:33:20 UTC


README

关于

AppGallery IAP 是一个用于处理 AppGallery 购买验证和服务器通知的 PHP 库。此包通过允许您使用现成的数据对象来简化开发。该包还包含带有和不带有 PSS 填充的 SHA256WithRSA 签名验证。

安装

使用 composer

composer require chfur/appgallery-iap

使用方法

AppGallery IAP 验证订单和订阅服务的实现可以在 验证包 中找到。Laravel 框架的实现可以在 Laravel In-App purchase 包 中找到。

关于关键订阅事件的的通知

您可以使用以下方式使用服务器通知处理 "关于关键订阅事件":

use CHfur\AppGallery\ServerNotifications\ServerNotification;
use CHfur\AppGallery\ServerNotifications\SubscriptionNotification;
use Huawei\IAP\Response\SubscriptionResponse;

/** 
 * @var array $data AppGallery ServerNotification request
 * @see https://developer.huawei.com/consumer/en/doc/development/HMSCore-References/api-notifications-about-subscription-events-0000001050706084 
*/
$data = [];

$publicKey = 'Your AppGallery notification public key';

/** @var ServerNotification $serverNotification */
$serverNotification = ServerNotification::parse($data, $publicKey);

if($serverNotification->isSubscriptionNotification()){
    /** @var SubscriptionNotification $subscriptionNotification */
    $subscriptionNotification = $serverNotification->getSubscriptionNotification();
    
    $productId = $subscriptionNotification->getProductId();
    $environment = $subscriptionNotification->getEnvironment();

    /** @var SubscriptionResponse $subscriptionResponse */
    $subscriptionResponse = $subscriptionNotification->getSubscriptionResponse();
    
    $notificationTypeName = $subscriptionNotification->getNotificationTypeName();
    
    switch ($notificationTypeName){
        case 'RENEWAL':
            //implement your logic
            break;
    }
}

关于待处理购买的 关键事件的通知

您还可以使用以下方式使用服务器通知处理 "关于待处理购买的 关键事件":

use CHfur\AppGallery\ServerNotifications\PendingPurchaseNotification;
use CHfur\AppGallery\ServerNotifications\ServerNotification;

/** 
 * @var array $data AppGallery ServerNotification request
 * @see https://developer.huawei.com/consumer/en/doc/development/HMSCore-References/api-notifications-about-pending-payment-events-0000001230063777 
*/
$data = [];

$publicKey = 'Your AppGallery notification public key';

/** @var ServerNotification $serverNotification */
$serverNotification = ServerNotification::parse($data, $publicKey);

if($serverNotification->isPendingPurchaseNotification()){
    /** @var PendingPurchaseNotification $pendingPurchaseNotification */
    $pendingPurchaseNotification = $serverNotification->getPendingPurchaseNotification();
    
    $productId = $pendingPurchaseNotification->getProductId();
    $purchaseToken = $pendingPurchaseNotification->getPurchaseToken();
    $isSuccessPayment = $pendingPurchaseNotification->getNotificationType();
    
    //implement your logic
}

许可证

AppGallery IAP 是一个开源软件,根据 MIT 许可证 授权。

待办事项

  • 实现无第三方包的验证