app store server library node
1.4.0
App Store Server API和App Store Server通知的Node.js服务器库。也有Swift,Python和Java提供。
安装
文档
用法
支持
节点16+
#with NPMNPM install @apple/app-store-server-library-save-save#with yarnyarn add @apple/app-store-server-library
文档
WWDC视频
要使用App Store Server API或创建促销优惠签名,需要从App Store Connect下载的签名密钥。要获得此键,您必须具有管理员角色。转到用户并访问> Integrations>“应用程序内购买”。在这里,您可以创建和管理密钥,并找到您的发行人ID。使用密钥时,您还需要密钥ID和发行器ID。
下载并存储在Apple PKI网站的Apple Root证书部分中找到的根证书。将这些证书作为符号段的数组提供给签名的Dataverifier,以允许验证签名的数据来自Apple。
导入{appStoreserVerapicLient,环境,sendtestNotificationResponse},来自“@Apple/App-Store-Store-Server-library” const issuerid =“ 99B16628-15E4-46668-972B-EEEFF5555555555555555555555555” filepath =“/path/key/subscriptionkey_abcdefghij.p8""const encodedkey = readfile = readfile(filepath)//特定的实现可能会varyconst emoverition = Environment.sandboxconst client = new AppStoresererVerapicLient(Encodedkey(Encodedkey)(Encodedkey)响应:sendTestNotificationResponse =等待client.requesttestnotification()console.log(wenspy)} catch(e){console.error(e)}import {signeddataverifier}来自“@apple/app-store-store-server-library” const bundleid =“ com.example” const applerootcas:buffer [] = loadrootcas() = undefined // appAppleId is required when the environment is Productionconst verifier = new SignedDataVerifier(appleRootCAs, enableOnlineChecks, environment, bundleId, appAppleId)const notificationPayload = "ey..."const verifiedNotification = await verifier.verifyAndDecodeNotification(notificationPayload)console.log(验证的通知)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 =” , issuerId, bundleId, environment)const appReceipt = "MI..."const receiptUtil = new ReceiptUtility()const transactionId = receiptUtil.extractTransactionIdFromAppReceipt(appReceipt)if (transactionId != null) {const transactionHistoryRequest: TransactionHistoryRequest = {sort: Order.上升,撤销:false,producttypes:[productType.auto_renewable]}}让响应:history ressponse | null = nulllet Transactions:String [] = [] do {const revisionToken = wendesp!== null && response.revision!== null? response.revision : nullresponse = await client.getTransactionHistory(transactionId, revisionToken, transactionHistoryRequest, GetTransactionHistoryVersion.V2)if (response.signedTransactions) {transactions = transactions.concat(response.signedTransactions)}} while (response.hasMore)console.log(交易)}}import {proverionaloffersignatureCreator}来自“@apple/app-store-store-server-library” const keyId =“ abcdefghij” const bundled =“ com.example” const filepath =“/path/path/path/key/subscriptionkey_abcdekekey_abcdefghij.abcdefghij.p8 conconst enccodedkey = read read read read read read read read read read read read read read read read read (filepath)//特定实现可能会varyconst productid =“ <product_id>” const subscriptionofferid =“ <sisscription_offer_id>” const applicationusername =“ <application_username>” const noncon nonce =“ const noncon>” =新的proverionaloffersignatureCreator(codedkey,keyid,bundleid)const签名= signatureCreator.CreateSignature(productid,sisscriptionofferid,applicationUsername,applicationUsername,nonce,timestamp)console.log(签名)只有库的最新主要版本才会收到更新,包括安全更新。因此,建议更新到新的主要版本。