我一直在过去的日子里想测试我的第一个应用程序内purchse iPhone应用程序。不幸的是,我找不到倾诉的iTunes服务器,以验证transactionReceipt的方式。

由于这是我第一次尝试这种技术我选择了从iPhone,而不是使用服务器支持直接验证收据。但试图发送与使用来自谷歌代码JSON API onbject创建的JSON POST请求后,iTunes的总是返回一个响应怪(而不是“状态= 0”的字符串我等)。

下面是我使用来验证接收到的代码:

- (void)recordTransaction:(SKPaymentTransaction *)transaction {
    NSString *receiptStr = [[NSString alloc] initWithData:transaction.transactionReceipt encoding:NSUTF8StringEncoding];
    NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"algo mas",@"receipt-data",nil];

    NSString *jsonString = [jsonDictionary JSONRepresentation];
    NSLog(@"string to send: %@",jsonString);

    NSLog(@"JSON Created");
    urlData = [[NSMutableData data] retain];

    //NSURL *sandboxStoreURL = [[NSURL alloc] initWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"]];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
    NSLog(@"will create connection");
    [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

也许我忘在请求的报头的东西,但我认为这个问题是在我用它来创建JSON对象的方法。

下面是JSON对象看起来像之前我把它添加到HTTPBody:

    string to send: {"receipt-data":"{\n\t\"signature\" = \"AUYMbhY

       ...........

D0gIjEuMCI7Cn0=\";\n\t\"pod\" = \"100\";\n\t\"signing-status\" = \"0\";\n}"}

我已经得到了响应:

  

完全响应{       例外=“java.lang.IllegalArgumentException异常:试图读取加引号的字符串属性列表解析失败没有允许的字符被发现在行号:1,柱:0.”       状态= 21002;   }

非常感谢您的指导。

有帮助吗?

解决方案

我刚刚固定的后挣扎的2天。你必须插入JSON对象之前编码的Base64收据。像(红宝石):

dataForVerification = {"receipt-data" => Base64.encode64(receipt)}.to_json

Base64是不是在官方的文档中任何地方提到的(至少对于SDK 3.0)中,只有一对夫妇的博客。

例如,此处的人传递之前编码该收据以Base64它的PHP服务器,但不会对其进行解码回PHP,从而发送Base64编码字符串到iTunes。

其他提示

回复: “21002:java.lang.IllegalArgumentException异常:propertyListFromString解析的对象,但仍然在字符串中更多的文本:”

我通过编码之前缠绕在{}中的收据数据固定在我的代码类似的问题。

将所得的收据如下:

{
    "signature" = "A[...]OSzQ==";
    "purchase-info" = "ew[...]fQ==";
    "pod" = "100";
    "signing-status" = "0";
}

下面是我使用的代码:

receipt = "{%s}" % receipt    // This step was not specified - trial and error
encoded = base64.b64encode(receipt)
fullpost = '{ "receipt-data" : "%s" }' % encoded
req = urllib2.Request(url, fullpost)
response = urllib2.urlopen(req)

苹果的响应:

{"receipt":{"item_id":"371235", "original_transaction_id":"1012307", "bvrs":"1.0", "product_id":"com.foo.cup", "purchase_date":"2010-05-25 21:05:36 Etc/GMT", "quantity":"1", "bid":"com.foo.messenger", "original_purchase_date":"2010-05-25 21:05:36 Etc/GMT", "transaction_id":"11237"}, "status":0}

祝你好运!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top