如何让云功能的火力地堡的HTTP请求?
答
回答是从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.');
}
});
可能的复制[如何使Node.js的外部HTTP请求( http://stackoverflow.com/questions/7967037/how-to-make-external-http-requests-with-node-js) –
不是重复的,实际上是一个很好的问题。 @Rashid Khan,你解决了这个问题吗?我也需要它。 –
是的,我正在使用这个库https://github.com/request/request - 我已经发布上面的解决方案。 –