Firebase Firestore + 云功能服务器端验证收据(应用内购买),最终结果:状态 21002 这意味着:收据属性中的数据格式错误或丢失。
步骤1)我使用swift将应用内购买收据存储到Firestore中,Firestore数据库自然将其存储为blob
step2) 一旦收据进入 firestore 就会触发云功能。Firebase 函数向苹果 iTunes 商店发送收据,但最终结果是:状态 21002。
我猜在将收据从 base64EncodedData 转换为 Firestore blob 的过程中,不知何故格式错误,然后在云函数上检索它。如何获得正确的收据格式,以便我可以将其发送到 Apple iTunes 商店进行收据验证?
第 1 步快速代码:
func sendReceiptToFirestore() {
guard let appStoreReceiptURL = Bundle.main.appStoreReceiptURL,
FileManager.default.fileExists(atPath: appStoreReceiptURL.path) else {return}
do {
let rawReceiptData = try Data(contentsOf: appStoreReceiptURL)
let receiptData = rawReceiptData.base64EncodedData()
//Standard way to store receiptData to firestore, i did that but not posting full code here for cleanliness
} catch {}
}
Run Code Online (Sandbox Code Playgroud)
step 2 云函数代码:
const request = require("request-promise"); …Run Code Online (Sandbox Code Playgroud) in-app-purchase firebase swift google-cloud-functions google-cloud-firestore