如何在我的服务器上解码 v2 App Store 服务器通知?

问题描述 投票:0回答:1

如何在 NodeJS 服务器上使用

@apple/app-store-server-library
SignedDataVerifier
来验证 v2 通知?

ios node.js flutter app-store
1个回答
0
投票
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;
}


© www.soinside.com 2019 - 2024. All rights reserved.