我正在尝试将receipt
发送到我的Node.js server
。目前,它会打印出Firebase中的receipt-data
,表明它是从我从POST
发送来的iOS App
请求中获得的。但是,我无法在我的代码中正确传递要在const receipt = request.body;
中进行验证的代码。我该如何以正确的方式传递它?谢谢。
exports.receiptValidation = functions.https.onRequest((request, response) => {
const receipt = request.body;
console.log(receipt);
iap.config({
applePassword: 'MySharedAppleKey',
test: true
});
iap.setup((error) => {
if (error) {
console.log('Failed to validate receipt', error);
}
});
iap.validate(receipt).then((pResponse) => {
//Check if receipt is valid
if (iap.isValidated(pResponse)) {
console.log('The receipt is valid', pResponse);
response.send(pResponse);
}
return pResponse;
})
.catch((error) => {
console.log(`Sorry couldn't validate receipt`, error);
response.send(error);
return error
});
});
这是我在Firebase中的输出。我正在使用firebase function
答案 0 :(得分:1)
我通过更改Swift
和Server code
中的收据数据字符串来解决了该问题
迅速
let receiptData = receipt!.base64EncodedString()
let requestReceiptDict = ["receipt": receiptData]
Node.js
const receipt = request.body.receipt;
console.log(receipt);