如何让云功能的火力地堡的HTTP请求?

问题描述:

我试图让使用云功能的火力地堡到苹果收据验证服务器的呼叫。任何想法如何进行HTTP调用?如何让云功能的火力地堡的HTTP请求?

+2

可能的复制[如何使Node.js的外部HTTP请求( http://*.com/questions/7967037/how-to-make-external-http-requests-with-node-js) –

+1

不是重复的,实际上是一个很好的问题。 @Rashid Khan,你解决了这个问题吗?我也需要它。 –

+0

是的,我正在使用这个库https://github.com/request/request - 我已经发布上​​面的解决方案。 –

回答是从OP的编辑问题复制


OP解决了这个使用https://github.com/request/request

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!'); 
    } 
    console.log('Done.'); 
    } 
});