# SubscriptionInfo 类引用

> 引用 `SubscriptionInfo` 类方法来检索订阅商品信息和状态。

Unity IAP 通过 `SubscriptionInfo` 类提供详细的订阅产品信息。

## SubscriptionInfo 类方法##subscriptioninfo-class-methods

`SubscriptionInfo` 类是商品订阅相关信息的容器。

> **Note:**
>
> 方法 `IsSubscribed()`、`IsExpired()`、`IsCancelled()`、`IsAutoRenewing()` 和 `GetRemainingTime()` 在调用时使用当前日期进行计算。这意味着，如果缓存 `SubscriptionInfo` 对象，这些值将随时间推移而动态更新。

`SubscriptionInfo` 类中提供了以下方法：

| 方法                                               | 描述                                                                                                                                                                                                                                     |
| :----------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `public string GetProductId()`                   | 返回商品的商店 ID。                                                                                                                                                                                                                            |
| `public DateTime GetPurchaseDate()`              | 返回商品的购买日期。 对于 Apple，购买日期是购买或续订订阅的日期。对于 Google，购买日期是最初购买订阅的日期。                                                                                                                                                                          |
| `public Result IsSubscribed()`                   | 指示商品当前是否已订阅。 Apple App Store 中不可续订的商品会返回 `Result.Unsupported` 值。Apple App Store 中的可自动续订商品和 Google Play Store 中的订阅商品返回`Result.True`或`Result.False`值。                                                                                    |
| `public Result IsExpired()`                      | 指示订阅是否已过期。 \* Apple App Store 中不可续订的商品返回`Result.Unsupported`值。 \* Apple App Store 中的可自动续订商品和 Google Play Store 中的订阅商品返回`Result.True`或`Result.False`值。                                                                                  |
| `public Result IsCancelled()`                    | 指示订阅是否已取消。 取消的订阅意味着商品当前已订阅，但不会在下一个计费日期续订。 对于 Apple，这由取消日期决定。 对于 Google，这取决于自动续订状态。 Apple App Store 中不可续订的商品会返回 `Result.Unsupported` 值。                                                                                                 |
| `public Result IsFreeTrial()`                    | 指示商品是否处于免费试用状态。 Apple App Store 中不可续订的商品会返回 `Result.Unsupported` 值。Apple App Store 中的可自动续订商品和 Google Play Store 中的订阅商品返回`Result.True`或`Result.False`值。                                                                                 |
| `public Result IsAutoRenewing()`                 | 指示订阅是否可以自动续订。 对于 Apple，这是根据商品类型、取消状态和到期状态计算的。对于 Google，这将返回存储的自动续订标志。 Apple App Store 中不可续订的商品会返回 `Result.Unsupported` 值。                                                                                                              |
| `public TimeSpan GetRemainingTime()`             | 返回 TimeSpan，指示到下一个计费日期的剩余时间。Apple App Store 中不可续订的商品返回`TimeSpan.Zero`。                                                                                                                                                                 |
| `public Result IsIntroductoryPricePeriod()`      | 指示订阅是否处于介绍性价格期。 Apple App Store 中不可续订的商品会返回 `Result.Unsupported` 值。 Apple App Store 中的可自动续订商品和 Google Play Store 中的订阅商品返回`Result.True`或`Result.False`值。                                                                                |
| `public TimeSpan GetIntroductoryPricePeriod()`   | 返回一个`TimeSpan`，指示介绍性价格期的剩余时间。 没有介绍性价格期的订阅商品返回`TimeSpan.Zero`。如果应用程序不支持 iOS 11.2+、macOS 10.13.2+ 或 tvOS 11.2+ 版本，Apple App Store 中的商品将返回 `TimeSpan.Zero`。                                                                               |
| `public long GetIntroductoryPricePeriodCycles()` | 返回介绍性价格周期的数量。 如果应用程序不支持 iOS 11.2+、macOS 10.13.2+ 或 tvOS 11.2+ 版本，Apple App Store 中的商品将返回 0。                                                                                                                                            |
| `public string GetIntroductoryPrice()`           | 返回介绍性价格字符串。 没有介绍性价格的商品返回`"not available"`值。Apple App Store 商品具有介绍性价格时，会返回格式化为 `“0.99USD”` 的值。Google Play 商品具有介绍性价格，返回一个格式化为 `“$0.99”` 的值。如果应用程序不支持 iOS 11.2+、macOS 10.13.2+ 或 tvOS 11.2+ 版本，Apple App Store 中的商品将返回 `“not available”`。 |
| `public DateTime GetExpireDate()`                | 返回商品下一次自动续订或到期的日期（对于已取消的自动续订订阅）。                                                                                                                                                                                                       |
| `public DateTime GetCancelDate()`                | 返回取消订阅的日期。 Apple App Store返回收据中的取消日期。 Google Play 应用商店不支持 - 返回 `DateTime.MinValue`。使用 IsCancelled() 可检查 Google Play 上的取消状态。                                                                                                            |
| `public TimeSpan GetFreeTrialPeriod()`           | 返回免费试用期的持续时间。 Google Play 应用商店从商品详细信息中返回配置的免费试用期限。 Apple App Store不支持 - 返回 `TimeSpan.Zero`。可使用 `IsFreeTrial()` 检查免费试用状态。                                                                                                               |
| `public TimeSpan GetSubscriptionPeriod()`        | 返回订阅计费期的持续时间。 Google Play 应用商店返回商品详细信息中的订阅期限。  Apple App Store不支持 - 返回 `TimeSpan.Zero`。                                                                                                                                                |
| `public string GetFreeTrialPeriodString()`       | 以 ISO8601 持续时间字符串的形式返回免费试用期（例如，“P1W”一周）。 但是，此方法仅返回 Google Play 应用商店的有用数据。 对于 Apple App Store，这将返回 `null`。                                                                                                                              |
| `public string GetSkuDetails()`                  | 从 Google Play API 返回原始 JSON SkuDetails。对于 Apple App Store，这将返回 `null`。                                                                                                                                                                 |
| `public string GetSubscriptionInfoJsonString()`  | 返回包含订阅数据的 JSON 字符串，包括 `productId`、`is_free_trial`、`is_introductory_price_period` 和 `remaining_time_in_seconds`。 在内部用于订阅 Google Play 应用商店的更新。                                                                                           |
