app store server library java
Release 3.2.0
App Store 서버 API 및 App Store 서버 알림을 위한 Java 서버 라이브러리입니다. Swift, Python 및 Node.js에서도 사용할 수 있습니다.
implementation ' com.apple.itunes.storekit:app-store-server-library:3.2.0 '
< dependency >
< groupId >com.apple.itunes.storekit groupId >
< artifactId >app-store-server-library artifactId >
< version >3.2.0 version >
dependency >
JavaDocs
WWDC 비디오
App Store Server API를 사용하거나 프로모션 제안 서명을 생성하려면 App Store Connect에서 다운로드한 서명 키가 필요합니다. 이 키를 얻으려면 관리자 역할이 있어야 합니다. 사용자 및 액세스 > 통합 > 인앱 구매로 이동합니다. 여기에서 키를 생성 및 관리할 수 있을 뿐만 아니라 발급자 ID도 찾을 수 있습니다. 키를 사용할 때는 키 ID와 발급자 ID도 필요합니다.
Apple PKI 사이트의 Apple 루트 인증서 섹션에 있는 루트 인증서를 다운로드하여 저장하세요. 서명된 데이터가 Apple에서 온 것인지 확인할 수 있도록 이러한 인증서를 SignedDataVerifier에 배열로 제공합니다.
import com . apple . itunes . storekit . client . APIException ;
import com . apple . itunes . storekit . client . AppStoreServerAPIClient ;
import com . apple . itunes . storekit . model . Environment ;
import com . apple . itunes . storekit . model . SendTestNotificationResponse ;
import java . io . IOException ;
import java . nio . file . Files ;
import java . nio . file . Path ;
public class APIExample {
public static void main ( String [] args ) throws Exception {
String issuerId = "99b16628-15e4-4668-972b-eeff55eeff55" ;
String keyId = "ABCDEFGHIJ" ;
String bundleId = "com.example" ;
Path filePath = Path . of ( "/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8" );
String encodedKey = Files . readString ( filePath );
Environment environment = Environment . SANDBOX ;
AppStoreServerAPIClient client =
new AppStoreServerAPIClient ( encodedKey , keyId , issuerId , bundleId , environment );
try {
SendTestNotificationResponse response = client . requestTestNotification ();
System . out . println ( response );
} catch ( APIException | IOException e ) {
e . printStackTrace ();
}
}
}
import com . apple . itunes . storekit . model . Environment ;
import com . apple . itunes . storekit . model . ResponseBodyV2DecodedPayload ;
import com . apple . itunes . storekit . verification . SignedDataVerifier ;
import com . apple . itunes . storekit . verification . VerificationException ;
import java . io . FileInputStream ;
import java . io . InputStream ;
import java . util . Set ;
public class ExampleVerification {
public static void main ( String [] args ) {
String bundleId = "com.example" ;
Environment environment = Environment . SANDBOX ;
Set < InputStream > rootCAs = Set . of (
new FileInputStream ( "/path/to/rootCA1" ),
new FileInputStream ( "/path/to/rootCA2" )
);
Long appAppleId = null ; // appAppleId must be provided for the Production environment
SignedDataVerifier signedPayloadVerifier = new SignedDataVerifier ( rootCAs , bundleId , appAppleId , environment , true );
String notificationPayload = "ey..." ;
try {
ResponseBodyV2DecodedPayload payload = signedPayloadVerifier . verifyAndDecodeNotification ( notificationPayload );
System . out . println ( payload );
} catch ( VerificationException e ) {
e . printStackTrace ();
}
}
}
import com . apple . itunes . storekit . client . AppStoreServerAPIClient ;
import com . apple . itunes . storekit . client . GetTransactionHistoryVersion ;
import com . apple . itunes . storekit . migration . ReceiptUtility ;
import com . apple . itunes . storekit . model . Environment ;
import com . apple . itunes . storekit . model . HistoryResponse ;
import com . apple . itunes . storekit . model . TransactionHistoryRequest ;
import java . nio . file . Files ;
import java . nio . file . Path ;
import java . util . LinkedList ;
import java . util . List ;
public class ExampleMigration {
public static void main ( String [] args ) throws Exception {
String issuerId = "99b16628-15e4-4668-972b-eeff55eeff55" ;
String keyId = "ABCDEFGHIJ" ;
String bundleId = "com.example" ;
Path filePath = Path . of ( "/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8" );
String encodedKey = Files . readString ( filePath );
Environment environment = Environment . SANDBOX ;
AppStoreServerAPIClient client =
new AppStoreServerAPIClient ( encodedKey , keyId , issuerId , bundleId , environment );
String appReceipt = "MI..." ;
ReceiptUtility receiptUtil = new ReceiptUtility ();
String transactionId = receiptUtil . extractTransactionIdFromAppReceipt ( appReceipt );
if ( transactionId != null ) {
TransactionHistoryRequest request = new TransactionHistoryRequest ()
. sort ( TransactionHistoryRequest . Order . ASCENDING )
. revoked ( false )
. productTypes ( List . of ( TransactionHistoryRequest . ProductType . AUTO_RENEWABLE ));
HistoryResponse response = null ;
List < String > transactions = new LinkedList <>();
do {
String revision = response != null ? response . getRevision () : null ;
response = client . getTransactionHistory ( transactionId , revision , request , GetTransactionHistoryVersion . V2 );
transactions . addAll ( response . getSignedTransactions ());
} while ( response . getHasMore ());
System . out . println ( transactions );
}
}
}
import com . apple . itunes . storekit . offers . PromotionalOfferSignatureCreator ;
import java . nio . file . Files ;
import java . nio . file . Path ;
import java . util . UUID ;
public class ExampleSignatureCreation {
public static void main ( String [] args ) throws Exception {
String keyId = "ABCDEFGHIJ" ;
String bundleId = "com.example" ;
Path filePath = Path . of ( "/path/to/key/SubscriptionKey_ABCDEFGHIJ.p8" );
String encodedKey = Files . readString ( filePath );
PromotionalOfferSignatureCreator signatureCreator = new PromotionalOfferSignatureCreator ( encodedKey , keyId , bundleId );
String productId = "" ;
String subscriptionOfferId = "" ;
String appAccountToken = "" ;
UUID nonce = UUID . randomUUID ();
long timestamp = System . currentTimeMillis ();
String encodedSignature = signatureCreator . createSignature ( productId , subscriptionOfferId , appAccountToken , nonce , timestamp );
System . out . println ( encodedSignature );
}
}
라이브러리의 최신 주요 버전만 보안 업데이트를 포함한 업데이트를 받게 됩니다. 따라서 새로운 메이저 버전으로 업데이트하는 것이 좋습니다.