如何从play billing api获取数据

问题描述 投票:0回答:1

我已经在后端实现了播放计费 API,我成功获取了 startTime 但 lineItems->expiryTime 无法获取,不显示任何内容

require_once('autoload.php');
         //purchases_products
        $client = new Google_Client();
        $client->setAuthConfig( 'credentials.json');
        $client->addScope('https://www.googleapis.com/auth/androidpublisher');

        $service = new Google_Service_AndroidPublisher($client);
        $purchase = $service->purchases_subscriptionsv2->get(PACKAGE_NAME, $token);
        
        echo $purchase->startTime;
        //echo $purchase->lineItems;  
        
        echo json_encode($purchase['lineItems']);
          

  // don't show anything with this
        echo $purchase->lineItems->expiryTime;
        
       
php google-play google-api-php-client android-billing
1个回答
0
投票

我用它来获取 $purchase->getExpiryTimeMillis(); 请注意我使用旧版本(2.10.1)的 google-api-php-client

    $packageName = 'your package name'; 
    $productId = 'your product id';
    $token = 'purchase token';

    $client = new \Google_Client();
    $path = 'googleApi/service.json';
    
   
    $client->setAuthConfig($path);
    $client->addScope('https://www.googleapis.com/auth/androidpublisher');
    $service = new \Google_Service_AndroidPublisher($client);

    $purchase = $service->purchases_subscriptions->get($packageName, $productId, $token);

    $autoRenewing = $purchase->getAutoRenewing(); 
    $acknowledgementState = $purchase->getAcknowledgementState();
    $expiryTimeMillis = $purchase->getExpiryTimeMillis();

    echo('$expiryTimeMillis: '. $expiryTimeMillis. ' | $autoRenewing:'. $autoRenewing. ' | $acknowledgementState: '. $acknowledgementState);
    dd($purchase);
© www.soinside.com 2019 - 2024. All rights reserved.