如何在 NodeJS 服务器上使用
@apple/app-store-server-library
SignedDataVerifier
来验证 v2 通知?
async function subscriptionUpdate(signedPayload, testMode) {
const environment = testMode ? Environment.SANDBOX : Environment.PRODUCTION
const appAppleId = '0000000000'
const bundleId = "com.name.name"
const cas = [];
//probably cache these
cas.push(Buffer.from(await (await fetch("https://www.apple.com/certificateauthority/AppleRootCA-G3.cer")).arrayBuffer()))
cas.push(Buffer.from(await (await fetch("https://www.apple.com/certificateauthority/AppleRootCA-G2.cer")).arrayBuffer()))
const verifier = new SignedDataVerifier(cas, true, environment, bundleId, appAppleId)
const decodedNotification = await verifier.verifyAndDecodeNotification(signedPayload)
decodedNotification.data.signedRenewalInfo = await verifier.verifyAndDecodeRenewalInfo(decodedNotification.data.signedRenewalInfo);
decodedNotification.data.signedTransactionInfo = await verifier.verifyAndDecodeRenewalInfo(decodedNotification.data.signedTransactionInfo);
const decoded = decodedNotification;
if (decoded.notificationType == "EXPIRED") {
//user does not have the subscription
}
console.log(decoded);
return decoded;
}