App Store 服务器节点.js 库
用于 App Store 服务器 API, (中文(简体) ), App Store 服务器通知, (中文(简体) ), 保留通讯API,以及 高级商务 API。也可以在 挥发, (中文(简体) ), 蟒,以及 爪哇语。 。 。 .
目录
安装
所需资源
- 节点16+
国家预防机制/也门
# With NPM
npm install @apple/app-store-server-library --save
# With Yarn
yarn add @apple/app-store-server-library
文档
从 App Store 连接获取内购密钥
要使用 App Store 服务器 API 或创建促销要约签名,需要从 App Store Connect 下载签名密钥. 要获得这个密钥,你必须拥有管理员的角色. 转到用户和访问 > 集成 > 内部购买。 您可以在这里创建和管理密钥, 并找到您的发行者 ID 。 使用密钥时,也需要密钥ID和发证人ID.
获取苹果根证书
下载并存储在 $ 1 的 Apple Root 证书部分中找到的根证书 苹果公用钥匙 网站。 将这些证书作为数组提供给一个已签名的Data验证器,以便验证所签名的数据来自苹果公司.
使用量
API 使用量
import { AppStoreServerAPIClient, Environment, SendTestNotificationResponse } from "@apple/app-store-server-library"
const issuerId = "99b16628-15e4-4668-972b-eeff55eeff55"
const keyId = "ABCDEFGHIJ"
const bundleId = "com.example"
const filePath = "/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8"
const encodedKey = readFile(filePath) // Specific implementation may vary
const environment = Environment.SANDBOX
const client = new AppStoreServerAPIClient(encodedKey, keyId, issuerId, bundleId, environment)
try {
const response: SendTestNotificationResponse = await client.requestTestNotification()
console.log(response)
} catch (e) {
console.error(e)
}
核查使用情况
import { SignedDataVerifier } from "@apple/app-store-server-library"
const bundleId = "com.example"
const appleRootCAs: Buffer[] = loadRootCAs() // Specific implementation may vary
const enableOnlineChecks = true
const environment = Environment.SANDBOX
const appAppleId = undefined // appAppleId is required when the environment is Production
const verifier = new SignedDataVerifier(appleRootCAs, enableOnlineChecks, environment, bundleId, appAppleId)
const notificationPayload = "ey..."
const verifiedNotification = await verifier.verifyAndDecodeNotification(notificationPayload)
console.log(verifiedNotification)
收款使用情况
import { AppStoreServerAPIClient, Environment, GetTransactionHistoryVersion, ReceiptUtility, Order, ProductType, HistoryResponse, TransactionHistoryRequest } from "@apple/app-store-server-library"
const issuerId = "99b16628-15e4-4668-972b-eeff55eeff55"
const keyId = "ABCDEFGHIJ"
const bundleId = "com.example"
const filePath = "/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8"
const encodedKey = readFile(filePath) // Specific implementation may vary
const environment = Environment.SANDBOX
const client =
new AppStoreServerAPIClient(encodedKey, keyId, issuerId, bundleId, environment)
const appReceipt = "MI..."
const receiptUtil = new ReceiptUtility()
const transactionId = receiptUtil.extractTransactionIdFromAppReceipt(appReceipt)
if (transactionId != null) {
const transactionHistoryRequest: TransactionHistoryRequest = {
sort: Order.ASCENDING,
revoked: false,
productTypes: [ProductType.AUTO_RENEWABLE]
}
let response: HistoryResponse | null = null
let transactions: string[] = []
do {
const revisionToken = response !== null && response.revision !== null ? response.revision : null
response = await client.getTransactionHistory(transactionId, revisionToken, transactionHistoryRequest, GetTransactionHistoryVersion.V2)
if (response.signedTransactions) {
transactions = transactions.concat(response.signedTransactions)
}
} while (response.hasMore)
console.log(transactions)
}
促进提供签署
import { PromotionalOfferSignatureCreator } from "@apple/app-store-server-library"
const keyId = "ABCDEFGHIJ"
const bundleId = "com.example"
const filePath = "/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8"
const encodedKey = readFile(filePath) // Specific implementation may vary
const productId = "<product_id>"
const subscriptionOfferId = "<subscription_offer_id>"
const appAccountToken = "<app_account_token>"
const nonce = "<nonce>"
const timestamp = Date.now()
const signatureCreator = new PromotionalOfferSignatureCreator(encodedKey, keyId, bundleId)
const signature = signatureCreator.createSignature(productId, subscriptionOfferId, appAccountToken, nonce, timestamp)
console.log(signature)
支助
只有最新的主要版本的图书馆才会收到更新,包括安全更新. 因此,建议更新新的主要版本.