使用Node.js验证iOS收据

编程入门 行业动态 更新时间:2024-10-10 04:26:33
本文介绍了使用Node.js验证iOS收据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

经过几天的努力试图让某些东西上班并且没有在哪里工作之后,我想知道是否有人在Node.js上使用了iOS Receipt Validation。我已经尝试了这里找到的节点模块iap_verifier,但我无法让它正常工作。我收到的苹果服务器回复的唯一回复是21002,数据格式不正确。

After struggling a few days trying to get something to work and getting no where, I was wondering if someone has gotten iOS Receipt Validation working on Node.js. I have tried the node module iap_verifier found here but I could not get it to work properly for me. the only response I received back form Apples servers is 21002, data was malformed.

对我来说有一件事是对我提供的苹果服务器的客户端验证请求直接来自Apple提供的教程这里,代码如下所示。

One thing that has worked for me was a client side validation request to apples servers that I got directly from the tutorials provided by Apple here, with the code shown below.

// The transaction looks ok, so start the verify process. // Encode the receiptData for the itms receipt verification POST request. NSString *jsonObjectString = [self encodeBase64:(uint8_t *)transaction.transactionReceipt.bytes length:transaction.transactionReceipt.length]; // Create the POST request payload. NSString *payload = [NSString stringWithFormat:@"{\"receipt-data\" : \"%@\", \"password\" : \"%@\"}", jsonObjectString, ITC_CONTENT_PROVIDER_SHARED_SECRET]; NSData *payloadData = [payload dataUsingEncoding:NSUTF8StringEncoding]; // Use ITMS_SANDBOX_VERIFY_RECEIPT_URL while testing against the sandbox. NSString *serverURL = ITMS_SANDBOX_VERIFY_RECEIPT_URL; // Create the POST request to the server. NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:serverURL]]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:payloadData]; NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self]; [conn start];

我有一堆不同的代码,我一直用来向节点发送各种各样的东西服务器。我所有不同的尝试都失败了。我甚至尝试将我在上面的客户端验证示例中构建的payloadData汇集到我的服务器,并使用以下代码将其发送到Apples服务器:

I have a bunch of different code I have been using to send a wide array of things to my node server. and all of my different attempts have failed. I have even tried just funneling the "payloadData" I constructed in the client side validation example above to my server and sending that to Apples servers with the following code:

function verifyReceipt(receiptData, responder) { var options = { host: 'sandbox.itunes.apple', port: 443, path: '/verifyReceipt', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': Buffer.byteLength(receiptData) } }; var req = https.request(options, function(res) { res.setEncoding('utf8'); res.on('data', function (chunk) { console.log("body: " + chunk); }); }); req.write(receiptData); req.end(); }

函数传递的是payloadData。从Apple收到的回复总是21002.我基本上还是一个节点新手,所以我无法弄清楚到底出了什么问题。我认为当我将数据从ObjC发送到我的节点服务器时可能会发生一些数据损坏,所以也许我没有正确传输。

Where the function is passed the payloadData. The response received from Apple is always 21002. I'm still basically a node novice,so I can't figure out what exactly is going wrong. I think there might be some data corruption happening when I am sending the data from ObjC to my Node server, so perhaps I am not transmitting right.

如果有人能指出我正确的方向,或提供一些例子说明他们如何让收据验证在他们的节点中工作,那将是一个很大的帮助。如果有人对iap_verifier模块有任何经验,并且确切地知道它需要什么数据,那将是很棒的。我将提供我需要的任何代码示例,因为我已经在这个过程中争取了几天。

If anyone can point me in the right direction, or provide some example of how they got receipt validation to work in node for them, it would be a great help. It would be great if anyone has had any experience with the iap_verifier module, and exactly what data it requires. I'll provide any code example I need to, as I have been fighting this process for a few days now.

谢谢!

推荐答案

你是否正确编写了receiptData?根据Apple规范,它应具有格式

Do you have composed correctly receiptData? Accordlying with Apple specification it should have the format

{"receipt-data": "your base64 receipt"}

使用receipt-data对象修改包含base64收据字符串的代码验证应该有效

Modifying your code wrapping the base64 receipt string with receipt-data object the validation should works

function (receiptData_base64, production, cb) { var url = production ? 'buy.itunes.apple' : 'sandbox.itunes.apple' var receiptEnvelope = { "receipt-data": receiptData_base64 }; var receiptEnvelopeStr = JSON.stringify(receiptEnvelope); var options = { host: url, port: 443, path: '/verifyReceipt', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': Buffer.byteLength(receiptEnvelopeStr) } }; var req = https.request(options, function(res) { res.setEncoding('utf8'); res.on('data', function (chunk) { console.log("body: " + chunk); cb(true, chunk); }); res.on('error', function (error) { console.log("error: " + error); cb(false, error); }); }); req.write(receiptEnvelopeStr); req.end(); }

更多推荐

使用Node.js验证iOS收据

本文发布于:2023-11-26 09:08:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633497.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:收据   Node   js   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!