AppStoreReceiptValidation

Swift 5.1 github-actions codecov

这个包实现了用于通过 App Store API 验证收据的功能。

特性

用法

swift-app-store-receipt-validation, async-http-clientswift-nio 作为依赖项添加到你的项目。为此,打开你的 Package.swift 文件,并将这些添加到你的依赖项中。

  dependencies: [
    .package(url: "https://github.com/swift-server/async-http-client", .upToNextMajor(from: "1.1.0")),
    .package(url: "https://github.com/apple/swift-nio", .upToNextMajor(from: "2.14.0")),
    .package(url: "https://github.com/slashmo/swift-app-store-receipt-validation", .upToNextMajor(from: "0.1.0")),
  ]

然后,将 AsyncHTTPClient, SwiftNIOAppStoreReceiptValidation 作为目标依赖项添加。

  targets: [
    .target(name: "Hello", dependencies: [
      .product(name: "NIO", package: "swift-nio"),
      .product(name: "AsyncHTTPClient", package: "async-http-client"),
      .product(name: "AppStoreReceiptValidation", package: "swift-app-store-receipt-validation"),
    ]
  ]

要在你的代码中验证 AppStore 收据,你需要首先创建一个 HTTPClient

let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
defer { try? httpClient.syncShutdown() }

let appStoreClient = AppStore.Client(httpClient: httpClient, secret: "abc123")

let base64EncodedReceipt: String = ...
let receipt = try appStoreClient.validateReceipt(base64EncodedReceipt).wait()