12

我正在测试应用内购买自动更新订阅,但苹果的沙箱服务器总是返回 status=21004

 #define SHARED_SECRET @"INSERT HERE YOUR ITUNESCONNECT SHARED SECRECT KEY FOR AUTORENEWABLE SUBCRIPTIONS RECEIPT VALIDATION"

-(void)checkReceipt {
// verifies receipt with Apple
NSError *jsonError = nil;
NSString *receiptBase64 = [NSString base64StringFromData:receiptData length:[receiptData length]];
NSLog(@"Receipt Base64: %@",receiptBase64);

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:[NSDictionary dictionaryWithObjectsAndKeys:
                                                            receiptBase64,@"receipt-data",
                                                            SHARED_SECRET,@"password",
                                                            nil]
                                                   options:NSJSONWritingPrettyPrinted
                                                     error:&jsonError
                    ];
NSLog(@"%@",jsonData);
NSError * error=nil;
NSDictionary * parsedData = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error];
NSLog(@"%@",parsedData);
NSLog(@"JSON: %@",[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]);
// URL for sandbox receipt validation; replace "sandbox" with "buy" in production or you will receive
// error codes 21006 or 21007
NSURL *requestURL = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];

NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:requestURL];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:jsonData];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if(conn) {
    receivedData = [[NSMutableData alloc] init];
} else {
    completionBlock(NO,@"Cannot create connection");
}
}

有人可以帮我获得正确的收据验证吗?

4

2 回答 2

23

INSERT HERE YOUR ITUNESCONNECT SHARED SECRECT KEY FOR AUTORENEWABLE SUBCRIPTIONS RECEIPT VALIDATION您必须使用从 iTunes Connect 获得的密钥替换顶部的此文本。(显然,不要在 Stack Overflow 上发布完整的秘密)。

秘密通常是一个 32 位的字母数字字符串,看起来像这样39fkjc38jd02mg72k9cn29dfkm39fk00(这个是假的)。

在(新的)iTunes Connect 中,转到“我的应用” >(然后单击您的应用)> “应用内购买” > “查看或生成共享密钥”

于 2013-03-06T09:28:54.547 回答
1

去ituenes connet 然后你的应用然后去ManageInApp购买然后这里看到左下角有一个选项视图或者生成一个sharedsecret 这里你可以生成一个shared secret或者你可以查看之前的shared secret

于 2013-03-06T13:39:01.157 回答