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(簽名)只有庫的最新主要版本才會收到更新,包括安全更新。因此,建議更新到新的主要版本。