小编Jac*_*her的帖子

如何在 Cloud Functions for Firebase 中实现 json 对象?

我想通过使用 Firebase 云功能将原始收据发送到应用商店服务器进行验证并获取经过验证的收据来验证应用程序购买收据中的苹果。

var jsonObject = {
            'receipt-data': receiptData,
            password: functions.config().apple.iappassword
        };
        var jsonData = JSON.stringify(jsonObject);
        var firebaseRef = '/' + fbRefHelper.getUserPaymentInfo(currentUser);

        let url = "https://sandbox.itunes.apple.com/verifyReceipt";//or production  
        request.post({
            headers: { 'content-type': 'application/x-www-form-urlencoded' },
            url: url,
            body: jsonData
        }, function (error, response, body) {
            if (error) {

            } else {
                var jsonResponse = JSON.parse(body);
                if (jsonResponse.status === 0) {
                    console.log('Recipt Valid!');

                } else {

                    console.log('Recipt Invalid!.');

                }
                if (jsonResponse.status === 0 && jsonResponse.environment !== 'Sandbox') {
                    console.log('Response is in Production!');
                } …
Run Code Online (Sandbox Code Playgroud)

javascript node.js firebase google-cloud-functions

6
推荐指数
1
解决办法
3128
查看次数