我尝试使用此处的 Node.js进行 IAP 收据验证,但它总是在服务器日志上返回错误:“收据数据属性中的数据格式错误。”
\n\n有人可以帮助我正确地将 Base64 字符串发送到 Node.js 并将其解码为相同的 Base64 字符串以进行收据验证吗?我对 javascript 的经验为零,并且已经尝试让这个简单的代码工作两天了,但没有成功。
\n\n这是我的 Swift 代码:
\n\nlet receiptData = try Data(contentsOf: appStoreReceiptURL, options: .alwaysMapped) \nlet receiptString = receiptData.base64EncodedString(options: [])\n\n\nvar request = URLRequest(url: URL(string: "https://us-central1-calendizer-6a849.cloudfunctions.net/receiptValidation")!)\nrequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")\n request.httpMethod = "POST"\n\n// attach receipt data to a request\nrequest.httpBody = receiptString.data(using: .utf8)\n\nprint("httpBody: \\(request.httpBody?.base64EncodedString())")\n\nLogs.log("\xe2\x9c\x89\xef\xb8\x8f Receipt Validation -> sending request ...")\nlet task = URLSession.shared.dataTask(with: request) { data, response, error in\n...\n}\nRun Code Online (Sandbox Code Playgroud)\n\n这是我的 Node.js 代码(Firebase Cloud Functions):
\n\nconst functions = require(\'firebase-functions\');\nvar …Run Code Online (Sandbox Code Playgroud)